From patchwork Wed Mar 17 23:59:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26434 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 8E03E44A940 for ; Thu, 18 Mar 2021 02:00:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 75663688152; Thu, 18 Mar 2021 02:00:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37B4F687ED6 for ; Thu, 18 Mar 2021 02:00:09 +0200 (EET) Received: by mail-ej1-f45.google.com with SMTP id u5so1106047ejn.8 for ; Wed, 17 Mar 2021 17:00:09 -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:reply-to:mime-version :content-transfer-encoding; bh=gj7+D+52LKQod0/xroB/AIM8dVjC1MkNQu2GZb+ooP8=; b=sIH7/DZIHGPDMTDOxilTdUgi3Gmg26MtbhgIHDFEpuGe8uXa6zXWa0i21j/ImPj42M h03pMlZdEpRrneccWN2z8KPGRG5m1Uf6WjRopO7XHBEaqe0+Pjt48FmDsYqFKIy0FKVW 9j1k94LBb07wOt839qY4LZuoybJ7jMDZGkDYG0wvD0kuAbEKiSJE7VbwaKI/jZYdN3gB SjS6KvHe6iBuxOyIxq2vb21HrjwHW47rcqj8r1Db2OIxkYT3gQSimGbopWMyLcY4ayNd 8/QOeQa74gQweMMahzeUKVqXYvL2aVLJc95BOI+TiF3RQloxVEhfKP9WV2a+L7fYizeG fuCQ== 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:reply-to :mime-version:content-transfer-encoding; bh=gj7+D+52LKQod0/xroB/AIM8dVjC1MkNQu2GZb+ooP8=; b=jVHqWQob5RqPDFDDQ7d0PNo5PaXECQCUuJgJS/naQlfaO/5KbgSOqIYTjBLWC4VhY3 txppVGMuQ2LTrGulQtJy2EHxBplIV7mbl3N1zOVu97pt/T9s06g4Lk1R5ZUsb+VEqZca wiu9kmH/b6AfIq2wRQMUYH8JAVAuWR0/t5XWCgpmGbBviYFlGHO2CxmA9uhGTQ4A/FPo BxUCwTkz2dCuMd7ZJD+NGzU1+LfII9dg73qir7Snp4w1B/lW9NmaFKzxrGr1upM0epQC lRwvqeit9Xl+vZ68lbHEgeyHVK/J1PlhINWGj7qgGrFCYB9Dem2KC5yp08isJCxpBOV1 cisQ== X-Gm-Message-State: AOAM531NrRQ9I2R3Noxtty+VzbaeRCuwbeAWGPfS5sbUnA+fOq92y7tE pbyEcoEBD4mIB+Ukq+pdTbaSKLrB5pO2sg== X-Google-Smtp-Source: ABdhPJzQVsGrQg+4V9k6GpzxusApQEF0UH8hL6Sj8n/3H7cKuDbIl50egmO24BcvOZU3qXL4v9Efjg== X-Received: by 2002:a17:906:b20b:: with SMTP id p11mr38814677ejz.0.1616025606934; Wed, 17 Mar 2021 17:00:06 -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.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 17:00:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Mar 2021 00:59:54 +0100 Message-Id: <20210317235958.1308987-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] avcodec/avpacket: Improve overflow checks when packing dictionary 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" Also avoid reallocations. Signed-off-by: Andreas Rheinhardt --- libavcodec/avpacket.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 6840688b15..8f0850fb00 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -509,37 +509,37 @@ int av_packet_split_side_data(AVPacket *pkt){ uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size) { - AVDictionaryEntry *t = NULL; uint8_t *data = NULL; *size = 0; if (!dict) return NULL; - while ((t = av_dict_get(dict, "", t, AV_DICT_IGNORE_SUFFIX))) { - const size_t keylen = strlen(t->key); - const size_t valuelen = strlen(t->value); - const size_t new_size = *size + keylen + 1 + valuelen + 1; - uint8_t *const new_data = av_realloc(data, new_size); + for (int pass = 0; pass < 2; pass++) { + const AVDictionaryEntry *t = NULL; + size_t total_length = 0; - if (!new_data) - goto fail; - data = new_data; - if (new_size > INT_MAX) - goto fail; - - memcpy(data + *size, t->key, keylen + 1); - memcpy(data + *size + keylen + 1, t->value, valuelen + 1); + while ((t = av_dict_get(dict, "", t, AV_DICT_IGNORE_SUFFIX))) { + for (int i = 0; i < 2; i++) { + const char *str = i ? t->value : t->key; + const size_t len = strlen(str) + 1; - *size = new_size; + if (pass) + memcpy(data + total_length, str, len); + else if (len > INT_MAX - total_length) + return NULL; + total_length += len; + } + } + if (pass) + break; + data = av_malloc(total_length); + if (!data) + return NULL; + *size = total_length; } return data; - -fail: - av_freep(&data); - *size = 0; - return NULL; } int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict) From patchwork Wed Mar 17 23:59:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26435 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 8DC4344A940 for ; Thu, 18 Mar 2021 02:00:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6700E689A15; Thu, 18 Mar 2021 02:00:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7760C689A01 for ; Thu, 18 Mar 2021 02:00:25 +0200 (EET) Received: by mail-ej1-f50.google.com with SMTP id b9so1106939ejc.11 for ; Wed, 17 Mar 2021 17:00:25 -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=Zz/Ux4tH594wqVXRHssQUqIpIIcJe7l1HMuRKwUEOuY=; b=QWS6Vf/VxH2kfuV1Onpyco3FWzaw9e82NJTwdJfgyotgjnm1x4H+u46T4B0WYhMwni gL4YaCNm2oabvzwqb5qFzM8+WJ5QT4ZgM1IyFYnc4C5vdXa9Sq5zA52NRvgawQuHE48N UGUQmOSHNWxFyZO/Gu0ULelJs+kMfSaFjUdo+ycym3Sg5tF2sUhBghLyOifk6HLDkasD FPKLdVZjjUUaunGruEFcmzF/hwfIyU8Mkhp2Q2LPvbXQmJcuh1W8wJiAF2wukOhxRyeT OnvUi5qSo2pikTf6bbYfKjxNBll5QdIE/F8moqLndh7Elep723clXZ/SmUIpMEQebKmK 4NvA== 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=Zz/Ux4tH594wqVXRHssQUqIpIIcJe7l1HMuRKwUEOuY=; b=oQG0Oglj7CMzPAkAtoI4CksCU8PfsRG376JDhKHvvRNwNd7c2tt9+0EXSW3+JBUcRc iu+xSRoPiwfLWd4/BgzkVpkCA4zIP+lBDrwr23oQ7M+TaztZURWocauBiKsJ/1sJOmlk QRLayI1pednsK4C1c9HEUmcvrqXSR3IGww0N7zzcKf6ihPmcRgkOxf+lUoEkU40KqebH 4Kv3macp7XWSD4YlY3gXJ7mmNlfu/P6QGCZ23bqqOK+puFUuO1dI3VwHI3dMFrht3sGM VnMGrChEWJIDDoLJ/29lHxR6ZYhfKpzvDVpAvaXadmx6JT7XIdx9SFCyYjee4cWyAwDF SBlg== X-Gm-Message-State: AOAM5307W2Nj7msMxWThDe/zb8d5R42/iNrwmSxgbhTnDvXu90521aMZ O/K/vzFr+yVi67We71WqjIbK5Fx5UvKH3w== X-Google-Smtp-Source: ABdhPJwobgDMds/0ztZjIvG8eA83iUC78HasTNveVbOflt5Rq4vqaoAdAU9TzThpM+FmRqmbGZGSlA== X-Received: by 2002:a17:906:d8d3:: with SMTP id re19mr38390091ejb.440.1616025623705; Wed, 17 Mar 2021 17:00:23 -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.00.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 17:00:23 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Mar 2021 00:59:55 +0100 Message-Id: <20210317235958.1308987-2-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 2/5] avcodec/packet: Also change av_packet_pack/unpack_dictionary 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" These are auxiliary side-data functions, so they should have been switched to size_t in d79e0fe65c51491f9bf8a470bbe36fb09f3e1280, but this has been forgotten. Signed-off-by: Andreas Rheinhardt --- libavcodec/avpacket.c | 13 +++++++++++++ libavcodec/packet.h | 10 +++++++++- libavdevice/decklink_dec.cpp | 2 +- libavdevice/lavfi.c | 2 +- libavformat/concatdec.c | 2 +- libavformat/img2dec.c | 3 ++- libavformat/oggdec.h | 2 +- 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index 8f0850fb00..b5bac5c5f2 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -507,7 +507,11 @@ int av_packet_split_side_data(AVPacket *pkt){ } #endif +#if FF_API_BUFFER_SIZE_T uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size) +#else +uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size) +#endif { uint8_t *data = NULL; *size = 0; @@ -526,7 +530,11 @@ uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size) if (pass) memcpy(data + total_length, str, len); +#if FF_API_BUFFER_SIZE_T else if (len > INT_MAX - total_length) +#else + else if (len > SIZE_MAX - total_length) +#endif return NULL; total_length += len; } @@ -542,7 +550,12 @@ uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size) return data; } +#if FF_API_BUFFER_SIZE_T int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict) +#else +int av_packet_unpack_dictionary(const uint8_t *data, size_t size, + AVDictionary **dict) +#endif { const uint8_t *end; int ret; diff --git a/libavcodec/packet.h b/libavcodec/packet.h index da4377e09f..ca18ae631f 100644 --- a/libavcodec/packet.h +++ b/libavcodec/packet.h @@ -647,7 +647,11 @@ const char *av_packet_side_data_name(enum AVPacketSideDataType type); * @param size pointer to store the size of the returned data * @return pointer to data if successful, NULL otherwise */ +#if FF_API_BUFFER_SIZE_T uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size); +#else +uint8_t *av_packet_pack_dictionary(AVDictionary *dict, size_t *size); +#endif /** * Unpack a dictionary from side_data. * @@ -656,8 +660,12 @@ uint8_t *av_packet_pack_dictionary(AVDictionary *dict, int *size); * @param dict the metadata storage dictionary * @return 0 on success, < 0 on failure */ +#if FF_API_BUFFER_SIZE_T int av_packet_unpack_dictionary(const uint8_t *data, int size, AVDictionary **dict); - +#else +int av_packet_unpack_dictionary(const uint8_t *data, size_t size, + AVDictionary **dict); +#endif /** * Convenience function to free all the side data stored. diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 40c3dae968..79d96cd620 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -922,7 +922,6 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( const char *tc = av_timecode_make_string(&tcr, tcstr, 0); if (tc) { AVDictionary* metadata_dict = NULL; - int metadata_len; uint8_t* packed_metadata; if (av_cmp_q(ctx->video_st->r_frame_rate, av_make_q(60, 1)) < 1) { @@ -937,6 +936,7 @@ HRESULT decklink_input_callback::VideoInputFrameArrived( } if (av_dict_set(&metadata_dict, "timecode", tc, 0) >= 0) { + buffer_size_t metadata_len; packed_metadata = av_packet_pack_dictionary(metadata_dict, &metadata_len); av_dict_free(&metadata_dict); if (packed_metadata) { diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index 94ad03268a..fdadff3f7f 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -446,7 +446,7 @@ static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) frame_metadata = frame->metadata; if (frame_metadata) { - int size; + buffer_size_t size; uint8_t *metadata = av_packet_pack_dictionary(frame_metadata, &size); if (!metadata) { diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index 6d5b9914f9..32d4a99010 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -626,7 +626,7 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &st->time_base), av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &st->time_base)); if (cat->cur_file->metadata) { - int metadata_len; + buffer_size_t metadata_len; char* packed_metadata = av_packet_pack_dictionary(cat->cur_file->metadata, &metadata_len); if (!packed_metadata) return AVERROR(ENOMEM); diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c index 6c78dada8c..be7149bb2f 100644 --- a/libavformat/img2dec.c +++ b/libavformat/img2dec.c @@ -381,9 +381,10 @@ int ff_img_read_header(AVFormatContext *s1) * as a dictionary, so it can be used by filters like 'drawtext'. */ static int add_filename_as_pkt_side_data(char *filename, AVPacket *pkt) { - int metadata_len, ret; AVDictionary *d = NULL; char *packed_metadata = NULL; + buffer_size_t metadata_len; + int ret; av_dict_set(&d, "lavf.image2dec.source_path", filename, 0); av_dict_set(&d, "lavf.image2dec.source_basename", av_basename(filename), 0); diff --git a/libavformat/oggdec.h b/libavformat/oggdec.h index 629a1d6262..bf982bfe1c 100644 --- a/libavformat/oggdec.h +++ b/libavformat/oggdec.h @@ -87,7 +87,7 @@ struct ogg_stream { int start_trimming; ///< set the number of packets to drop from the start int end_trimming; ///< set the number of packets to drop from the end uint8_t *new_metadata; - unsigned int new_metadata_size; + buffer_size_t new_metadata_size; void *private; }; From patchwork Wed Mar 17 23:59:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26436 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 16EE144A940 for ; Thu, 18 Mar 2021 02:00:36 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C4862689BEC; Thu, 18 Mar 2021 02:00:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4D5D5689A81 for ; Thu, 18 Mar 2021 02:00:29 +0200 (EET) Received: by mail-ej1-f44.google.com with SMTP id r12so1112730ejr.5 for ; Wed, 17 Mar 2021 17:00:29 -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=v5a0MnV33Nixj7EpljDq+dKd3G0mntJdc09xaPiOrEM=; b=mRHIQD51oHK51mBUxPeujs9Oo/JJVnFyQB4kedv2B34YYJfTwZGTLOwQk4ozF1sjtt W2eLkiP4+fcYqc0pyyYw2QPCOVFZ6j1sZgcBTndssLRNBnCV0Q4KNSoHipny1lOZeQE5 /er9hLFv5md+62Zqsu3LICgbh5FinXLPhDbDU0Dl/k3BW8MNxmYiCiCp0EdCo79ylJeS mwo6mhCXmEZXOelPjZdxMvivmopYcqHKtTUGDbCW7lJ9V/yqZ5z+c5nIWNroKUyjwuNR 39Pg3BZd0I64uaOOdDtMArYAw3h9vcZTrs8eqlYlcmFIexvmk4opWsyO7TqgAfdwRYcu 7IUA== 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=v5a0MnV33Nixj7EpljDq+dKd3G0mntJdc09xaPiOrEM=; b=P1bP6o1iILRo14NDgGJE0H6FUs6ejQoLBqc4C4fZRKDWay41Mom35agHlDBgcsv0UM 14u6dvK+gS3tYRSdux2/N8AisZdaHQbpdR6LJrMpjyjmYDeZHh84Aqu0u1WY0LVh9e0e 2jdeseWIp0MPpqUFbPlkZ+25n/MdoituJXugN1jLYqX6QnfJe5vH3zVIfqkC3+XnyVJ6 YqtOrAiusMrkhD9WwqY/h8IOsPUUvwEb1B+YQkvrhHi0iJV6z0jQRS/lZR7HFzgBWArW 6L96TB/5m880YGUPDcjL60ap0zmH3s3dRdlyivi0nbBHe/lSyyQ7AARtrzwztqvGNMWY Omyg== X-Gm-Message-State: AOAM53197fLfNg5IymrWcMSmSIljemFSf0KdBwNRslAqLFzfEk9QaD3p 8Tf0HyTBPTr8yfXxST5vKrcWT45cHHrAFA== X-Google-Smtp-Source: ABdhPJwfzyhnsLtCcLKnQ6+asUKG3NA3iXpf/cV2IJyOLeU1K2uRa1b692+nlQKu4Og7f0AHD4YH9Q== X-Received: by 2002:a17:907:7355:: with SMTP id dq21mr37297989ejc.159.1616025625846; Wed, 17 Mar 2021 17:00:25 -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.00.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 17:00:25 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Mar 2021 00:59:56 +0100 Message-Id: <20210317235958.1308987-3-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 3/5] avcodec: Factor updating palette out 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" Because the properties of frames returned from ff_get/reget_buffer are not reset at all, lots of returned frames had palette_has_changed wrongly set to 1. This has been changed, too. Signed-off-by: Andreas Rheinhardt --- libavcodec/8bps.c | 11 +---------- libavcodec/cinepak.c | 9 +-------- libavcodec/decode.c | 14 ++++++++++++++ libavcodec/gdv.c | 5 +---- libavcodec/idcinvideo.c | 9 +-------- libavcodec/imx.c | 5 +---- libavcodec/internal.h | 9 +++++++++ libavcodec/interplayvideo.c | 9 +-------- libavcodec/kmvc.c | 8 +------- libavcodec/msrle.c | 11 ++--------- libavcodec/msvideo1.c | 10 +--------- libavcodec/qpeg.c | 9 +-------- libavcodec/qtrle.c | 10 +--------- libavcodec/rawdec.c | 13 ++----------- libavcodec/rscc.c | 13 ++----------- libavcodec/smc.c | 9 +-------- libavcodec/tscc.c | 10 +--------- 17 files changed, 41 insertions(+), 123 deletions(-) diff --git a/libavcodec/8bps.c b/libavcodec/8bps.c index 53e939d35d..9d19e21342 100644 --- a/libavcodec/8bps.c +++ b/libavcodec/8bps.c @@ -122,16 +122,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, } if (avctx->bits_per_coded_sample <= 8) { - buffer_size_t size; - const uint8_t *pal = av_packet_get_side_data(avpkt, - AV_PKT_DATA_PALETTE, - &size); - if (pal && size == AVPALETTE_SIZE) { - frame->palette_has_changed = 1; - memcpy(c->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); - } + frame->palette_has_changed = ff_copy_palette(c->pal, avpkt, avctx); memcpy (frame->data[1], c->pal, AVPALETTE_SIZE); } diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c index d70cb4b694..61e2991d04 100644 --- a/libavcodec/cinepak.c +++ b/libavcodec/cinepak.c @@ -477,14 +477,7 @@ static int cinepak_decode_frame(AVCodecContext *avctx, return ret; if (s->palette_video) { - buffer_size_t size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size); - if (pal && size == AVPALETTE_SIZE) { - s->frame->palette_has_changed = 1; - memcpy(s->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); - } + s->frame->palette_has_changed = ff_copy_palette(s->pal, avpkt, avctx); } if ((ret = cinepak_decode(s)) < 0) { diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 5a00aeedae..efa8a9ac8d 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -2051,3 +2051,17 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; } + +int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) +{ + buffer_size_t size; + const void *pal = av_packet_get_side_data(src, AV_PKT_DATA_PALETTE, &size); + + if (pal && size == AVPALETTE_SIZE) { + memcpy(dst, pal, AVPALETTE_SIZE); + return 1; + } else if (pal) { + av_log(logctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); + } + return 0; +} diff --git a/libavcodec/gdv.c b/libavcodec/gdv.c index 860634c9ec..cda284a32a 100644 --- a/libavcodec/gdv.c +++ b/libavcodec/gdv.c @@ -462,8 +462,6 @@ static int gdv_decode_frame(AVCodecContext *avctx, void *data, PutByteContext *pb = &gdv->pb; AVFrame *frame = data; int ret, i; - buffer_size_t pal_size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size); int compression; unsigned flags; uint8_t *dst; @@ -479,8 +477,7 @@ static int gdv_decode_frame(AVCodecContext *avctx, void *data, if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - if (pal && pal_size == AVPALETTE_SIZE) - memcpy(gdv->pal, pal, AVPALETTE_SIZE); + ff_copy_palette(gdv->pal, avpkt, avctx); if (compression < 2 && bytestream2_get_bytes_left(gb) < 256*3) return AVERROR_INVALIDDATA; diff --git a/libavcodec/idcinvideo.c b/libavcodec/idcinvideo.c index 569191511f..02d5957bc7 100644 --- a/libavcodec/idcinvideo.c +++ b/libavcodec/idcinvideo.c @@ -214,8 +214,6 @@ static int idcin_decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; IdcinContext *s = avctx->priv_data; - buffer_size_t pal_size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size); AVFrame *frame = data; int ret; @@ -228,12 +226,7 @@ static int idcin_decode_frame(AVCodecContext *avctx, if (idcin_decode_vlcs(s, frame)) return AVERROR_INVALIDDATA; - if (pal && pal_size == AVPALETTE_SIZE) { - frame->palette_has_changed = 1; - memcpy(s->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size); - } + frame->palette_has_changed = ff_copy_palette(s->pal, avpkt, avctx); /* make the palette available on the way out */ memcpy(frame->data[1], s->pal, AVPALETTE_SIZE); diff --git a/libavcodec/imx.c b/libavcodec/imx.c index 0d6c99e5bf..59edd427cd 100644 --- a/libavcodec/imx.c +++ b/libavcodec/imx.c @@ -50,16 +50,13 @@ static int imx_decode_frame(AVCodecContext *avctx, void *data, { SimbiosisIMXContext *imx = avctx->priv_data; int ret, x, y; - buffer_size_t pal_size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size); AVFrame *frame = imx->frame; GetByteContext gb; if ((ret = ff_reget_buffer(avctx, frame, 0)) < 0) return ret; - if (pal && pal_size == AVPALETTE_SIZE) { - memcpy(imx->pal, pal, pal_size); + if (ff_copy_palette(imx->pal, avpkt, avctx)) { frame->palette_has_changed = 1; frame->key_frame = 1; } else { diff --git a/libavcodec/internal.h b/libavcodec/internal.h index b57b996816..0fb3107979 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -393,6 +393,15 @@ int ff_int_from_list_or_default(void *ctx, const char * val_name, int val, void ff_dvdsub_parse_palette(uint32_t *palette, const char *p); +/** + * Check whether the side-data of src contains a palette of + * size AVPALETTE_SIZE; if so, copy it to dst and return 1; + * else return 0. + * Also emit an error message upon encountering a palette + * with invalid size. + */ +int ff_copy_palette(void *dst, const AVPacket *src, void *logctx); + #if defined(_WIN32) && CONFIG_SHARED && !defined(BUILDING_avcodec) # define av_export_avcodec __declspec(dllimport) #else diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c index 4d16fdf619..b1e0145e30 100644 --- a/libavcodec/interplayvideo.c +++ b/libavcodec/interplayvideo.c @@ -1317,14 +1317,7 @@ static int ipvideo_decode_frame(AVCodecContext *avctx, return ret; if (!s->is_16bpp) { - buffer_size_t size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size); - if (pal && size == AVPALETTE_SIZE) { - frame->palette_has_changed = 1; - memcpy(s->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); - } + frame->palette_has_changed = ff_copy_palette(s->pal, avpkt, avctx); } switch (frame_format) { diff --git a/libavcodec/kmvc.c b/libavcodec/kmvc.c index 0d96139220..02caae346c 100644 --- a/libavcodec/kmvc.c +++ b/libavcodec/kmvc.c @@ -268,8 +268,6 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame, int i, ret; int header; int blocksize; - buffer_size_t pal_size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size); bytestream2_init(&ctx->g, avpkt->data, avpkt->size); @@ -304,12 +302,8 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame, } } - if (pal && pal_size == AVPALETTE_SIZE) { + if (ff_copy_palette(ctx->pal, avpkt, avctx)) frame->palette_has_changed = 1; - memcpy(ctx->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size); - } if (ctx->setpal) { ctx->setpal = 0; diff --git a/libavcodec/msrle.c b/libavcodec/msrle.c index feea2b60bb..7bfb29e58e 100644 --- a/libavcodec/msrle.c +++ b/libavcodec/msrle.c @@ -97,15 +97,8 @@ static int msrle_decode_frame(AVCodecContext *avctx, return ret; if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) { - buffer_size_t size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size); - - if (pal && size == AVPALETTE_SIZE) { - s->frame->palette_has_changed = 1; - memcpy(s->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); - } + s->frame->palette_has_changed = ff_copy_palette(s->pal, avpkt, avctx); + /* make the palette available */ memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE); } diff --git a/libavcodec/msvideo1.c b/libavcodec/msvideo1.c index b4b5ea4666..782e5cae00 100644 --- a/libavcodec/msvideo1.c +++ b/libavcodec/msvideo1.c @@ -314,15 +314,7 @@ static int msvideo1_decode_frame(AVCodecContext *avctx, return ret; if (s->mode_8bit) { - buffer_size_t size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size); - - if (pal && size == AVPALETTE_SIZE) { - memcpy(s->pal, pal, AVPALETTE_SIZE); - s->frame->palette_has_changed = 1; - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); - } + s->frame->palette_has_changed = ff_copy_palette(s->pal, avpkt, avctx); } if (s->mode_8bit) diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c index f4edc4b16f..ca8a0b01d6 100644 --- a/libavcodec/qpeg.c +++ b/libavcodec/qpeg.c @@ -274,8 +274,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame * const ref = a->ref; uint8_t* outdata; int delta, intra, ret; - buffer_size_t pal_size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size); if (avpkt->size < 0x86) { av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); @@ -300,12 +298,7 @@ static int decode_frame(AVCodecContext *avctx, } /* make the palette available on the way out */ - if (pal && pal_size == AVPALETTE_SIZE) { - p->palette_has_changed = 1; - memcpy(a->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size); - } + p->palette_has_changed = ff_copy_palette(a->pal, avpkt, avctx); memcpy(p->data[1], a->pal, AVPALETTE_SIZE); av_frame_unref(ref); diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c index e04fd31431..33da393bd1 100644 --- a/libavcodec/qtrle.c +++ b/libavcodec/qtrle.c @@ -540,15 +540,7 @@ static int qtrle_decode_frame(AVCodecContext *avctx, } if(has_palette) { - buffer_size_t size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size); - - if (pal && size == AVPALETTE_SIZE) { - s->frame->palette_has_changed = 1; - memcpy(s->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); - } + s->frame->palette_has_changed = ff_copy_palette(s->pal, avpkt, avctx); /* make the palette available on the way out */ memcpy(s->frame->data[1], s->pal, AVPALETTE_SIZE); diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c index c18c3dd3e1..1badb69180 100644 --- a/libavcodec/rawdec.c +++ b/libavcodec/rawdec.c @@ -367,16 +367,8 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, } if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { - buffer_size_t pal_size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, - &pal_size); int ret; - if (pal && pal_size != AVPALETTE_SIZE) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size); - pal = NULL; - } - if (!context->palette) context->palette = av_buffer_alloc(AVPALETTE_SIZE); if (!context->palette) { @@ -389,15 +381,14 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame, return ret; } - if (pal) { - memcpy(context->palette->data, pal, AVPALETTE_SIZE); + if (ff_copy_palette(context->palette->data, avpkt, avctx)) { frame->palette_has_changed = 1; } else if (context->is_nut_pal8) { int vid_size = avctx->width * avctx->height; int pal_size = avpkt->size - vid_size; if (avpkt->size > vid_size && pal_size <= AVPALETTE_SIZE) { - pal = avpkt->data + vid_size; + const uint8_t *pal = avpkt->data + vid_size; memcpy(context->palette->data, pal, pal_size); frame->palette_has_changed = 1; } diff --git a/libavcodec/rscc.c b/libavcodec/rscc.c index 79b02da441..372c35b603 100644 --- a/libavcodec/rscc.c +++ b/libavcodec/rscc.c @@ -346,17 +346,8 @@ static int rscc_decode_frame(AVCodecContext *avctx, void *data, /* Palette handling */ if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { - buffer_size_t size; - const uint8_t *palette = av_packet_get_side_data(avpkt, - AV_PKT_DATA_PALETTE, - &size); - if (palette && size == AVPALETTE_SIZE) { - frame->palette_has_changed = 1; - memcpy(ctx->palette, palette, AVPALETTE_SIZE); - } else if (palette) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); - } - memcpy (frame->data[1], ctx->palette, AVPALETTE_SIZE); + frame->palette_has_changed = ff_copy_palette(ctx->palette, avpkt, avctx); + memcpy(frame->data[1], ctx->palette, AVPALETTE_SIZE); } // We only return a picture when enough of it is undamaged, this avoids copying nearly broken frames around if (ctx->valid_pixels < ctx->inflated_size) diff --git a/libavcodec/smc.c b/libavcodec/smc.c index 33581bbf81..73ee6d6ebc 100644 --- a/libavcodec/smc.c +++ b/libavcodec/smc.c @@ -435,8 +435,6 @@ static int smc_decode_frame(AVCodecContext *avctx, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; SmcContext *s = avctx->priv_data; - buffer_size_t pal_size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &pal_size); int ret; int total_blocks = ((s->avctx->width + 3) / 4) * ((s->avctx->height + 3) / 4); @@ -448,12 +446,7 @@ static int smc_decode_frame(AVCodecContext *avctx, if ((ret = ff_reget_buffer(avctx, s->frame, 0)) < 0) return ret; - if (pal && pal_size == AVPALETTE_SIZE) { - s->frame->palette_has_changed = 1; - memcpy(s->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", pal_size); - } + s->frame->palette_has_changed = ff_copy_palette(s->pal, avpkt, avctx); smc_decode_stream(s); diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c index d33639f3a4..482c2966a0 100644 --- a/libavcodec/tscc.c +++ b/libavcodec/tscc.c @@ -72,15 +72,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, int palette_has_changed = 0; if (c->avctx->pix_fmt == AV_PIX_FMT_PAL8) { - buffer_size_t size; - const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size); - - if (pal && size == AVPALETTE_SIZE) { - palette_has_changed = 1; - memcpy(c->pal, pal, AVPALETTE_SIZE); - } else if (pal) { - av_log(avctx, AV_LOG_ERROR, "Palette size %d is wrong\n", size); - } + palette_has_changed = ff_copy_palette(c->pal, avpkt, avctx); } ret = inflateReset(&c->zstream); From patchwork Wed Mar 17 23:59:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26437 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 8667A44A940 for ; Thu, 18 Mar 2021 02:00:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 69EC6689C0A; Thu, 18 Mar 2021 02:00:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6F1086899EB for ; Thu, 18 Mar 2021 02:00:30 +0200 (EET) Received: by mail-ej1-f45.google.com with SMTP id l4so1105315ejc.10 for ; Wed, 17 Mar 2021 17:00:30 -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=DCwL+a8BTstxQXZ9jrL22oelxeMdiLos4a/lIsjT3Og=; b=rBqJ1kaecd6BQNLM7OZ64TzrKalrsmlw2qW58Iw2Zgjm3+twKDZ1icu7zBHt/8OVSg mKO+CoKRI/KlfJ09DvPAOI2AVelPvk+bgpwO8x1SOtw1sNeLENsiAOyj2teVghRAd9YU F6HAxpkq2saqLXiHVoejGRZmt3TGEchE6XwC3BC69dFTU23Pmej+R7lt9BaIIm3PzhkD eq9kNuzrisNpc89g+82DmMFSI8uM2XWxCKu4IsMIvWEtAZD4VYdJkKCOQmsAZLODPFMb G9nLzWtVuAgCtqmHmAEtyWcg1LKbPJ7XqJW7/vTtD2i1mOubiG+TlYBbsxzkzedntQKr DKNA== 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=DCwL+a8BTstxQXZ9jrL22oelxeMdiLos4a/lIsjT3Og=; b=mEzcnzpct2+q+ZKVs8EsHX1JqwqdPI+X3XvjVx9SbJWUf9fwndSjxJI4Qt8xaPK9ti ixyt1T8NhQeEl5IIKsz0BW+NPFQqER2qjSEN97ouhYXdYbnxU6uQpl077gjamlTlraFl 0N2GEdkUGE63NaRlU8Vlue7qUaUMnYeny802JSklZ5YzcVpr/I3LOfIC6fSmtkfSbyU0 2PRWEmGiaM3Dd2dkEZYwArbOk5P4jdsta3JDWA3EhdXqHv2NKffHCwpyPrl8sEwe8ETp ZRd6oLkQYugQ8DzhiG3wYTlunIVCJNwFvs42UVp/ZKgXzwQ0ON5Ith5d4UNpbrm8ZsUC Kr3g== X-Gm-Message-State: AOAM531nyM+aShHQcOSarStjyc9TNLszFi1MrPe303q9DsJIenceJTUu 4Vk01CforoyOiCChdYVxRlb1xliTZhi8jg== X-Google-Smtp-Source: ABdhPJx51dykscg7Q5rJNxCgzy/udDUDbAjV+eXPO7wJClHKG9gEuv+nkeBqmXAH6OSonrp1EK7EgQ== X-Received: by 2002:a17:906:2314:: with SMTP id l20mr38858468eja.178.1616025629747; Wed, 17 Mar 2021 17:00:29 -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.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 17:00:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Mar 2021 00:59:57 +0100 Message-Id: <20210317235958.1308987-4-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 4/5] avformat/matroskaenc: Check WebVTT subtitles for overflow 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" The destination here is an dynamic buffer which is restricted to INT_MAX, so check for that. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskaenc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 5d8d4cd646..4931988efd 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2133,7 +2133,7 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, const AVPac mkv_track *track = &mkv->tracks[pkt->stream_index]; ebml_master blockgroup; buffer_size_t id_size, settings_size; - int size; + int size = pkt->size + 2; const char *id, *settings; int64_t ts = track->write_dts ? pkt->dts : pkt->pts; const int flags = 0; @@ -2141,12 +2141,17 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, const AVPac id = av_packet_get_side_data(pkt, AV_PKT_DATA_WEBVTT_IDENTIFIER, &id_size); id = id ? id : ""; + if (id_size > INT_MAX - size) + return AVERROR(ERANGE); + size += id_size; settings = av_packet_get_side_data(pkt, AV_PKT_DATA_WEBVTT_SETTINGS, &settings_size); settings = settings ? settings : ""; + if (settings_size > INT_MAX - size) + return AVERROR(ERANGE); - size = id_size + 1 + settings_size + 1 + pkt->size; + size += settings_size; /* The following string is identical to the one in mkv_write_block so that * only one copy needs to exist in binaries. */ @@ -2170,7 +2175,7 @@ static int mkv_write_vtt_blocks(AVFormatContext *s, AVIOContext *pb, const AVPac put_ebml_uint(pb, MATROSKA_ID_BLOCKDURATION, pkt->duration); end_ebml_master(pb, blockgroup); - return pkt->duration; + return 0; } static int mkv_end_cluster(AVFormatContext *s) @@ -2341,7 +2346,9 @@ static int mkv_write_packet_internal(AVFormatContext *s, const AVPacket *pkt) } } else { if (par->codec_id == AV_CODEC_ID_WEBVTT) { - duration = mkv_write_vtt_blocks(s, pb, pkt); + ret = mkv_write_vtt_blocks(s, pb, pkt); + if (ret < 0) + return ret; } else { ebml_master blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, mkv_blockgroup_size(pkt->size, 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"); From patchwork Thu Mar 18 03:43:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 26443 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 1B65B448888 for ; Thu, 18 Mar 2021 05:44:37 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 01847689A8B; Thu, 18 Mar 2021 05:44:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA84E688152 for ; Thu, 18 Mar 2021 05:44:30 +0200 (EET) Received: by mail-ej1-f47.google.com with SMTP id r12so1680018ejr.5 for ; Wed, 17 Mar 2021 20:44:30 -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=SgfH4clm8dgKq4VXVjpLSnh+2Hu6Wnh7LY9rbWTe6hs=; b=C7iWYikBg+TlOPdC5gLp6MERRh9pS7XjT/OhsUtZgyVDE77i/YW9JU4ayASbvtOT43 nL60L1fb1FhLgK/kC9BvjB1XJMDo40RC1qyCQOExl+hwO/nyHvLnhkl3vF+umev/6XJU PCb6geDqwwACwLcIQ7b/d6JL5RBw5pjzH3RDOIjIrchvVVKm36MH6Tk9zI4bzgJVYAZ3 foG3LJpVNJ6eqKQaP2PEVM8MW0ejnHIerhuXNkx12UEDayPc/1ydSiNaed91Lzf7fe1e QG3RPckQA/gMBlXLH4kJjQ15RNjzxT/QbKLO6k9OKKn5OfAzGgbzNz/WSCjTq3qicCep WqYQ== 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=SgfH4clm8dgKq4VXVjpLSnh+2Hu6Wnh7LY9rbWTe6hs=; b=fv17jIfB4lWuaPcH+6xGssW6NnF3d3vxSnN3nyTlahwV42BST44YgyxK8yLqQkSJ+0 49lzIaaMDU6Jyt3cLgU4rUJTraDGhCQ/vWXgm/e1y/z5yu3PxG3zrqLcu2hDY0OAUYJN f//gewO8fPwEES1cncdXWmoA/Qm89EUjOL1QifoRweDvEauYw3Exu2eNUqX14TEsrE0W A0Yi0E/7+ZNxErd+zNFxzV8nzC53/UICIKmtfRSSSzEgCauyznOn36cW4Hk22O3UD0MM 8lVEw42wTGqqR4QSAHKm+dnKVcPXFX0FrdVvFYU+zCFlFfqzWbfG2zaE2qi7rEEYSfQi ZGhQ== X-Gm-Message-State: AOAM531GyNmo2kfP4WJGQVZNp+cadoSRAMTUg8RfFRAoRfjp5+zmXrfe ACyAmU0+EjNi3vT87t/8Xg55bScD8Ifnvg== X-Google-Smtp-Source: ABdhPJxrIdHjzezLCZrhyyevB8WkiEzrMWmQ6CyL3Rdp9o5s274rliXf9J3sL2LQzbBJzFCo8KUHzA== X-Received: by 2002:a17:907:7745:: with SMTP id kx5mr38330323ejc.3.1616039070034; Wed, 17 Mar 2021 20:44:30 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08960.dynamic.kabel-deutschland.de. [188.192.137.96]) by smtp.gmail.com with ESMTPSA id g11sm708875edw.37.2021.03.17.20.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 20:44:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 Mar 2021 04:43:14 +0100 Message-Id: <20210318034314.1531570-2-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 6/6] avutil/adler32: Switch av_adler32_update() to size_t on bump 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" av_adler32_update() is used by av_hash_update() which will be switched to size_t at the next bump. So it also has to be made to use size_t. This is also necessary for framecrcenc.c, because the size of side data will become a size_t, too. Signed-off-by: Andreas Rheinhardt --- doc/APIchanges | 5 +++++ libavutil/adler32.c | 4 ++++ libavutil/adler32.h | 16 ++++++++++++++-- libavutil/version.h | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 849d95a7ed..1782ae83fe 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,11 @@ libavutil: 2017-10-21 API changes, most recent first: +2021-03-18 - xxxxxxxxxx - lavu 56.69.100 - adler32.h + av_adler32_update() will be changed to use uint32_t + for the Adler-32 checksums and size_t for the length + if the input buffer at the next bump. + 2021-03-xx - xxxxxxxxxx - lavc 58.133.100 - codec.h Deprecated av_init_packet(). Once removed, sizeof(AVPacket) will no longer be a part of the public ABI. diff --git a/libavutil/adler32.c b/libavutil/adler32.c index c87d5e261c..5ed5ff55a3 100644 --- a/libavutil/adler32.c +++ b/libavutil/adler32.c @@ -41,8 +41,12 @@ #define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf); #define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf); +#if FF_API_CRYPTO_SIZE_T unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf, unsigned int len) +#else +AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len) +#endif { unsigned long s1 = adler & 0xffff; unsigned long s2 = adler >> 16; diff --git a/libavutil/adler32.h b/libavutil/adler32.h index a1f035b734..e7a8f83729 100644 --- a/libavutil/adler32.h +++ b/libavutil/adler32.h @@ -27,8 +27,10 @@ #ifndef AVUTIL_ADLER32_H #define AVUTIL_ADLER32_H +#include #include #include "attributes.h" +#include "version.h" /** * @defgroup lavu_adler32 Adler-32 @@ -38,6 +40,12 @@ * @{ */ +#if FF_API_CRYPTO_SIZE_T +typedef unsigned long AVAdler; +#else +typedef uint32_t AVAdler; +#endif + /** * Calculate the Adler32 checksum of a buffer. * @@ -50,8 +58,12 @@ * @param len size of input buffer * @return updated checksum */ -unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, - unsigned int len) av_pure; +AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, +#if FF_API_CRYPTO_SIZE_T + unsigned int len) av_pure; +#else + size_t len) av_pure; +#endif /** * @} diff --git a/libavutil/version.h b/libavutil/version.h index 9a290d57e7..f357f6165e 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 56 -#define LIBAVUTIL_VERSION_MINOR 68 +#define LIBAVUTIL_VERSION_MINOR 69 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \