The branch, master has been updated
       via  ef9fe0fe0bba7ecff3ed07fd53146296c1831a8f (commit)
       via  2398fddf6ed5d9ba81a4fa6b7afb895ca6cee144 (commit)
      from  2298d4d0725a9b1f9f1b50a7ef15e24047ef0600 (commit)


- Log -----------------------------------------------------------------
commit ef9fe0fe0bba7ecff3ed07fd53146296c1831a8f
Author:     Leo Izen <[email protected]>
AuthorDate: Sun Aug 24 09:12:49 2025 -0400
Commit:     Leo Izen <[email protected]>
CommitDate: Sun Aug 24 20:20:10 2025 +0000

    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 <[email protected]>

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++) {

commit 2398fddf6ed5d9ba81a4fa6b7afb895ca6cee144
Author:     Leo Izen <[email protected]>
AuthorDate: Sun Aug 24 08:54:16 2025 -0400
Commit:     Leo Izen <[email protected]>
CommitDate: Sun Aug 24 20:20:10 2025 +0000

    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 <[email protected]>

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);
     }
 

-----------------------------------------------------------------------

Summary of changes:
 libavcodec/exif.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)


hooks/post-receive
-- 

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to