From patchwork Wed Mar 17 23:59:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26438 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E3DEC44AD54 for ; Thu, 18 Mar 2021 02:01:29 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C4B96688158; Thu, 18 Mar 2021 02:01:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CBFE688137 for ; Thu, 18 Mar 2021 02:01:23 +0200 (EET) Received: by mail-ed1-f49.google.com with SMTP id x21so4418673eds.4 for ; Wed, 17 Mar 2021 17:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=5jHuW7WJAoyoFuczTPoSOIa31nnZYoUa7bjcq6YASgM=; b=gQFKXqXLMxV8KCCctLrqzbJnZi/shzKFv8AEJF5wFMVnfcNEz9IoKUXEAD5QqfYF7K bLxyKd2JPeDMW9V0AJ1Es5o0Vmv0ZwchqyIWS7AjIRXtJP5esy6shaq6Qd4KmHKULE32 whmVo2QfXkXRD2j4lSQdDxMiYR3gmeiQwJrmMtbPxFxhTQD1Uu/7/19MdapBC7kotb4K MKaX7jgtjZT3tFu+37pXCgVuil5YJy7bExgid9fk1DrNeVM6H6wYv1qFZVQrkYZmCQb6 hkqF74oO36kW4uwniX5n74KqGD3A1sWCM3RhWcykYi4k8r6k5/OjMWwtYQL7QbK8UCEZ Fm7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=5jHuW7WJAoyoFuczTPoSOIa31nnZYoUa7bjcq6YASgM=; b=l9c3z0OzZQKGFk35xP3aQoWzKbyyeNFU15/gakzk/kVkM+nPmblyexr40DSYh3ZGCY OzZb41W0957tuHUMZfaXi0plgs89bK0VokfLE3cAr1NKXew4ElQ5q/qLo4qhsIFlBiw1 giwDfl2bxfXmJYnxU4Uqgc8XdOmVTY4xLYD+Eh2zBqvVN4PrJMHwKTTp80LLX2JMgMxP psxVsd17odGtpHcnw+SBQHzNO0HyMrfZsL64UHAerf6qYWnW0CRW07Ub+ljZw0PA1DMt R107aQxCNCc/HdU3UUYuE1D1f2InayvwXfXcWeSh2yAQIeYBm+dRObsAlb95ocGlFrRv 9eyA== X-Gm-Message-State: AOAM533jsjSKXGfKinO+mDUszkQjvNePWlnfpfwZjs4OteeDoLUj7pwB qXFOfpyUcTlJKNErXZYPay+vaKHWTMGX9A== X-Google-Smtp-Source: ABdhPJwzOLImpfE2pe10NwmzmN3VUg0VxOTS3ZanhUJXYo9Pl8HZ7XLdobz3SZqEesJoGJHk/VoR7w== X-Received: by 2002:a05:6402:30a2:: with SMTP id df2mr284648edb.29.1616025682603; Wed, 17 Mar 2021 17:01:22 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08960.dynamic.kabel-deutschland.de. [188.192.137.96]) by smtp.gmail.com with ESMTPSA id u24sm326881ejn.5.2021.03.17.17.01.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 17:01:22 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Mar 2021 00:59:59 +0100 Message-Id: <20210317235958.1308987-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210317235958.1308987-1-andreas.rheinhardt@gmail.com> References: <20210317235958.1308987-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] Fix printf specifiers for variables that will be switched to size_t X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Andreas Rheinhardt --- There is btw an instance in ffprobe where a variable will have to be switched to size_t when doing the bump. Hopefully it won't be forgotten. libavcodec/decode.c | 5 +++++ libavcodec/mpeg12enc.c | 5 +++++ libavcodec/mscc.c | 5 +++++ libavfilter/af_ashowinfo.c | 5 +++++ libavfilter/vf_showinfo.c | 15 +++++++++++++++ libavformat/dump.c | 5 +++++ libavformat/framecrcenc.c | 7 ++++++- libavformat/hashenc.c | 9 +++++++-- libavformat/matroskaenc.c | 3 ++- libavformat/webvttdec.c | 2 +- libavformat/webvttenc.c | 18 ++++++++++++++---- 11 files changed, 70 insertions(+), 9 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index efa8a9ac8d..74e0d0679e 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -2061,7 +2061,12 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) memcpy(dst, pal, AVPALETTE_SIZE); return 1; } else if (pal) { +#if FF_API_BUFFER_SIZE_T av_log(logctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); +#else + av_log(logctx, AV_LOG_ERROR, + "Palette size %"SIZE_SPECIFIER" is wrong\n", size); +#endif } return 0; } diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c index a05c2db6cb..1bc733aff0 100644 --- a/libavcodec/mpeg12enc.c +++ b/libavcodec/mpeg12enc.c @@ -574,8 +574,13 @@ void ff_mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) put_bits(&s->pb, 8, 0xff); // marker_bits } else { av_log(s->avctx, AV_LOG_WARNING, +#if FF_API_BUFFER_SIZE_T "Warning Closed Caption size (%d) can not exceed 93 bytes " "and must be a multiple of 3\n", side_data->size); +#else + "Closed Caption size (%"SIZE_SPECIFIER") can not exceed " + "93 bytes and must be a multiple of 3\n", side_data->size); +#endif } } } diff --git a/libavcodec/mscc.c b/libavcodec/mscc.c index fe02649623..4cec26f5b2 100644 --- a/libavcodec/mscc.c +++ b/libavcodec/mscc.c @@ -160,7 +160,12 @@ static int decode_frame(AVCodecContext *avctx, for (j = 0; j < 256; j++) s->pal[j] = 0xFF000000 | AV_RL32(pal + j * 4); } else if (pal) { +#if FF_API_BUFFER_SIZE_T av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); +#else + av_log(avctx, AV_LOG_ERROR, + "Palette size %"SIZE_SPECIFIER" is wrong\n", size); +#endif } memcpy(frame->data[1], s->pal, AVPALETTE_SIZE); } diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c index 9046e8d84a..0e84bd8d65 100644 --- a/libavfilter/af_ashowinfo.c +++ b/libavfilter/af_ashowinfo.c @@ -170,7 +170,12 @@ static void dump_audio_service_type(AVFilterContext *ctx, AVFrameSideData *sd) static void dump_unknown(AVFilterContext *ctx, AVFrameSideData *sd) { +#if FF_API_BUFFER_SIZE_T av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size %d bytes", sd->type, sd->size); +#else + av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size " + "%"SIZE_SPECIFIER" bytes", sd->type, sd->size); +#endif } static int filter_frame(AVFilterLink *inlink, AVFrame *buf) diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 6208892005..bfcd5ebf72 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -314,7 +314,12 @@ static void dump_sei_unregistered_metadata(AVFilterContext *ctx, const AVFrameSi int i; if (sd->size < uuid_size) { +#if FF_API_BUFFER_SIZE_T av_log(ctx, AV_LOG_ERROR, "invalid data(%d < UUID(%d-bytes))\n", sd->size, uuid_size); +#else + av_log(ctx, AV_LOG_ERROR, "invalid data(%"SIZE_SPECIFIER" < " + "UUID(%d-bytes))\n", sd->size, uuid_size); +#endif return; } @@ -472,7 +477,12 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) av_log(ctx, AV_LOG_INFO, "pan/scan"); break; case AV_FRAME_DATA_A53_CC: +#if FF_API_BUFFER_SIZE_T av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%d bytes)", sd->size); +#else + av_log(ctx, AV_LOG_INFO, "A/53 closed captions (%"SIZE_SPECIFIER" bytes)", + sd->size); +#endif break; case AV_FRAME_DATA_SPHERICAL: dump_spherical(ctx, frame, sd); @@ -516,8 +526,13 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) dump_sei_unregistered_metadata(ctx, sd); break; default: +#if FF_API_BUFFER_SIZE_T av_log(ctx, AV_LOG_WARNING, "unknown side data type %d (%d bytes)\n", sd->type, sd->size); +#else + av_log(ctx, AV_LOG_WARNING, "unknown side data type %d " + "(%"SIZE_SPECIFIER" bytes)\n", sd->type, sd->size); +#endif break; } diff --git a/libavformat/dump.c b/libavformat/dump.c index 62ef5e9852..364cca9415 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -495,8 +495,13 @@ static void dump_sidedata(void *ctx, const AVStream *st, const char *indent) dump_s12m_timecode(ctx, st, sd); break; default: +#if FF_API_BUFFER_SIZE_T av_log(ctx, AV_LOG_INFO, "unknown side data type %d (%d bytes)", sd->type, sd->size); +#else + av_log(ctx, AV_LOG_INFO, "unknown side data type %d " + "(%"SIZE_SPECIFIER" bytes)", sd->type, sd->size); +#endif break; } diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c index 1fbe4aa4ee..dd7f3d227d 100644 --- a/libavformat/framecrcenc.c +++ b/libavformat/framecrcenc.c @@ -88,7 +88,7 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) case AV_PKT_DATA_SPHERICAL: case AV_PKT_DATA_CONTENT_LIGHT_LEVEL: case AV_PKT_DATA_S12M_TIMECODE: - for (int j = 0; j < sd->size / 4; j++) { + for (size_t j = 0; j < sd->size / 4; j++) { uint8_t buf[4]; AV_WL32(buf, AV_RB32(sd->data + 4 * j)); side_data_crc = av_adler32_update(side_data_crc, buf, 4); @@ -119,7 +119,12 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt) default: side_data_crc = av_adler32_update(0, data, sd->size); } +#if FF_API_BUFFER_SIZE_T av_strlcatf(buf, sizeof(buf), ", %8d, 0x%08"PRIx32, pkt->side_data[i].size, side_data_crc); +#else + av_strlcatf(buf, sizeof(buf), ", %8"SIZE_SPECIFIER", 0x%08"PRIx32, + pkt->side_data[i].size, side_data_crc); +#endif } } av_strlcatf(buf, sizeof(buf), "\n"); diff --git a/libavformat/hashenc.c b/libavformat/hashenc.c index 1e9faf372a..1be3bfdd61 100644 --- a/libavformat/hashenc.c +++ b/libavformat/hashenc.c @@ -298,18 +298,23 @@ static int framehash_write_packet(struct AVFormatContext *s, AVPacket *pkt) avio_write(s->pb, buf, strlen(buf)); if (c->format_version > 1 && pkt->side_data_elems) { - int i, j; + int i; avio_printf(s->pb, ", S=%d", pkt->side_data_elems); for (i = 0; i < pkt->side_data_elems; i++) { av_hash_init(c->hashes[0]); if (HAVE_BIGENDIAN && pkt->side_data[i].type == AV_PKT_DATA_PALETTE) { - for (j = 0; j < pkt->side_data[i].size; j += sizeof(uint32_t)) { + for (size_t j = 0; j < pkt->side_data[i].size; j += sizeof(uint32_t)) { uint32_t data = AV_RL32(pkt->side_data[i].data + j); av_hash_update(c->hashes[0], (uint8_t *)&data, sizeof(uint32_t)); } } else av_hash_update(c->hashes[0], pkt->side_data[i].data, pkt->side_data[i].size); +#if FF_API_BUFFER_SIZE_T snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1), ", %8d, ", pkt->side_data[i].size); +#else + snprintf(buf, sizeof(buf) - (AV_HASH_MAX_SIZE * 2 + 1), + ", %8"SIZE_SPECIFIER", ", pkt->side_data[i].size); +#endif len = strlen(buf); av_hash_final_hex(c->hashes[0], buf + len, sizeof(buf) - len); avio_write(s->pb, buf, strlen(buf)); diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 4931988efd..73cbfca90e 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2170,7 +2170,8 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, const AVPac put_ebml_num(pb, track->track_num, track->track_num_size); avio_wb16(pb, ts - mkv->cluster_pts); avio_w8(pb, flags); - avio_printf(pb, "%.*s\n%.*s\n%.*s", id_size, id, settings_size, settings, pkt->size, pkt->data); + avio_printf(pb, "%.*s\n%.*s\n%.*s", (int)id_size, id, (int)settings_size, + settings, pkt->size, pkt->data); put_ebml_uint(pb, MATROSKA_ID_BLOCKDURATION, pkt->duration); end_ebml_master(pb, blockgroup); diff --git a/libavformat/webvttdec.c b/libavformat/webvttdec.c index 8d2fdfed37..cf060bd011 100644 --- a/libavformat/webvttdec.c +++ b/libavformat/webvttdec.c @@ -78,7 +78,7 @@ static int webvtt_read_header(AVFormatContext *s) int64_t pos; AVPacket *sub; const char *p, *identifier, *settings; - int identifier_len, settings_len; + size_t identifier_len, settings_len; int64_t ts_start, ts_end; ff_subtitles_read_chunk(s->pb, &cue); diff --git a/libavformat/webvttenc.c b/libavformat/webvttenc.c index 552bc38b65..342cba6dd8 100644 --- a/libavformat/webvttenc.c +++ b/libavformat/webvttenc.c @@ -72,8 +72,13 @@ static int webvtt_write_packet(AVFormatContext *ctx, AVPacket *pkt) id = av_packet_get_side_data(pkt, AV_PKT_DATA_WEBVTT_IDENTIFIER, &id_size); - if (id && id_size > 0) - avio_printf(pb, "%.*s\n", id_size, id); + if (id && id_size > 0) { +#if !FF_API_BUFFER_SIZE_T + if (id_size > INT_MAX) + return AVERROR(ERANGE); +#endif + avio_printf(pb, "%.*s\n", (int)id_size, id); + } webvtt_write_time(pb, pkt->pts); avio_printf(pb, " --> "); @@ -82,8 +87,13 @@ static int webvtt_write_packet(AVFormatContext *ctx, AVPacket *pkt) settings = av_packet_get_side_data(pkt, AV_PKT_DATA_WEBVTT_SETTINGS, &settings_size); - if (settings && settings_size > 0) - avio_printf(pb, " %.*s", settings_size, settings); + if (settings && settings_size > 0) { +#if !FF_API_BUFFER_SIZE_T + if (id_size > INT_MAX) + return AVERROR(ERANGE); +#endif + avio_printf(pb, " %.*s", (int)settings_size, settings); + } avio_printf(pb, "\n");