From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 57DA64BB49 for ; Sun, 24 Aug 2025 13:16:15 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id B592768E6F7; Sun, 24 Aug 2025 16:16:09 +0300 (EEST) Received: from 0f4167fb2350 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id AB8AA68020B for ; Sun, 24 Aug 2025 16:16:08 +0300 (EEST) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] =?utf-8?q?=5BPATCH=5D_Two_exif_Fixes_=28PR_=23203?= =?utf-8?b?MjYp?= X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Leo Izen via ffmpeg-devel Reply-To: FFmpeg development discussions and patches Cc: Leo Izen Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Message-Id: <20250824131609.B592768E6F7@ffbox0-bg.ffmpeg.org> Date: Sun, 24 Aug 2025 16:16:09 +0300 (EEST) Archived-At: List-Archive: List-Post: PR #20326 opened by Leo Izen (Traneptora) URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20326 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20326.patch Fixes for two EXIF bugs, notably #20305 and #20291. >From c9e86ffd2ae9b3f296b761f3d7c2f10d69a46840 Mon Sep 17 00:00:00 2001 From: Leo Izen Date: Sun, 24 Aug 2025 08:54:16 -0400 Subject: [PATCH 1/2] avcodec/exif: avoid writing native-endian EXIF buffers Currently there's platform-dependent behavior where if no endianness is requested, it writes the buffers in native-endian. This breaks FATE tests on big-endian architecture. This commit changes the default to little-endian buffers upon writing. Fixes: #20291. Signed-off-by: Leo Izen --- libavcodec/exif.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/libavcodec/exif.c b/libavcodec/exif.c index 16635e1678..908a4a3d14 100644 --- a/libavcodec/exif.c +++ b/libavcodec/exif.c @@ -695,11 +695,7 @@ int av_exif_write(void *logctx, const AVExifMetadata *ifd, AVBufferRef **buffer, PutByteContext pb; int ret, off = 0; -#if AV_HAVE_BIGENDIAN - int le = 0; -#else int le = 1; -#endif if (*buffer) return AVERROR(EINVAL); @@ -736,12 +732,8 @@ int av_exif_write(void *logctx, const AVExifMetadata *ifd, AVBufferRef **buffer, if (header_mode != AV_EXIF_ASSUME_BE && header_mode != AV_EXIF_ASSUME_LE) { /* these constants are be32 in both cases */ - /* this is a #if instead of a ternary to suppress a deadcode warning */ -#if AV_HAVE_BIGENDIAN - bytestream2_put_be32(&pb, EXIF_MM_LONG); -#else + /* le == 1 always in this case */ bytestream2_put_be32(&pb, EXIF_II_LONG); -#endif tput32(&pb, le, 8); } -- 2.49.1 >From e754031691d320187ce3edebc2fce71a884735ee Mon Sep 17 00:00:00 2001 From: Leo Izen Date: Sun, 24 Aug 2025 09:12:49 -0400 Subject: [PATCH 2/2] avcodec/exif: avoid allocation failure on empty EXIF metadata An EXIF IFD with 0 entries is legal, but does not contain metadata. We should not attempt to allocate a struct with size zero in this case, as this causes an allocation failure. Instead, we just leave the struct empty. Fixes: #20305. Signed-off-by: Leo Izen --- libavcodec/exif.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libavcodec/exif.c b/libavcodec/exif.c index 908a4a3d14..f7effa6dbd 100644 --- a/libavcodec/exif.c +++ b/libavcodec/exif.c @@ -552,6 +552,10 @@ static int exif_parse_ifd_list(void *logctx, GetByteContext *gb, int le, ifd->count = entries; av_log(logctx, AV_LOG_DEBUG, "entry count for IFD: %u\n", ifd->count); + /* empty IFD is technically legal but equivalent to no metadata present */ + if (!ifd->count) + goto end; + if (av_size_mult(ifd->count, sizeof(*ifd->entries), &required_size) < 0) return AVERROR(ENOMEM); temp = av_fast_realloc(ifd->entries, &ifd->size, required_size); @@ -571,6 +575,7 @@ static int exif_parse_ifd_list(void *logctx, GetByteContext *gb, int le, return ret; } +end: /* * at the end of an IFD is an pointer to the next IFD * or zero if there are no more IFDs, which is usually the case @@ -1009,7 +1014,7 @@ static int exif_get_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int de { int offset = 1; - if (!ifd || ifd->entries && !ifd->count || ifd->count && !ifd->entries || !value) + if (!ifd || ifd->count && !ifd->entries || !value) return AVERROR(EINVAL); for (size_t i = 0; i < ifd->count; i++) { @@ -1043,7 +1048,7 @@ int av_exif_set_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, enum AVTif AVExifEntry *entry = NULL; AVExifEntry src = { 0 }; - if (!ifd || ifd->entries && !ifd->count || ifd->count && !ifd->entries + if (!ifd || ifd->count && !ifd->entries || ifd_lead && !ifd_offset || !ifd_lead && ifd_offset || !value || ifd->count == 0xFFFFu) return AVERROR(EINVAL); @@ -1089,7 +1094,7 @@ static int exif_remove_entry(void *logctx, AVExifMetadata *ifd, uint16_t id, int int32_t index = -1; int ret = 0; - if (!ifd || ifd->entries && !ifd->count || ifd->count && !ifd->entries) + if (!ifd || ifd->count && !ifd->entries) return AVERROR(EINVAL); for (size_t i = 0; i < ifd->count; i++) { -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".