Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] Two exif Fixes (PR #20326)
@ 2025-08-24 13:16 Leo Izen via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: Leo Izen via ffmpeg-devel @ 2025-08-24 13:16 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Leo Izen

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 <leo.izen@gmail.com>
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 <leo.izen@gmail.com>
---
 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 <leo.izen@gmail.com>
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 <leo.izen@gmail.com>
---
 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".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-08-24 13:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-24 13:16 [FFmpeg-devel] [PATCH] Two exif Fixes (PR #20326) Leo Izen via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git