[FFmpeg-devel] [PATCH] avcodec/exr detect invalid line offset table and recreate table

Dzung Hoang dthoang at yahoo.com
Fri Mar 17 18:19:21 EET 2017


Since there are no comments since March 14, I assume this patch is good to go. I tried to commit the patch and push it to the mirror on github.com, but was denied access.
Can a developer please apply and commit this patch?
Thanks,- Dzung Hoang


      From: Dzung Hoang <dthoang-at-yahoo.com at ffmpeg.org>
 To: FFmpeg Development Discussions and Patches <ffmpeg-devel at ffmpeg.org> 
 Sent: Tuesday, March 14, 2017 1:36 PM
 Subject: [FFmpeg-devel] [PATCH] avcodec/exr detect invalid line offset table and recreate table
   
The EXR decoder cannot handle the image files included in NVidia's HDR SDK. After debugging, I found that the line offset table in the image files contained 0's. Other EXR decoders, including the official OpenEXR decoder, can detect and reconstruct missing line offset tables, so I added some code to do so.

I filed a trac ticket for this issue here:

https://trac.ffmpeg.org/ticket/6220.

The image files are here:

http://samples.ffmpeg.org/ffmpeg-bugs/trac/ticket6220/

Dzung Hoang
Signed-off-by: Dzung Hoang <dthoang at yahoo.com>

---
 libavcodec/exr.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index 034920f..dec21af 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -1726,6 +1726,25 @@ static int decode_frame(AVCodecContext *avctx, void *data,
    if (bytestream2_get_bytes_left(&s->gb) < nb_blocks * 8)
        return AVERROR_INVALIDDATA;

+    // check line offset table and recreate if first entry is 0
+    if (bytestream2_peek_le64(&s->gb) == 0)
+    {
+        uint64_t *table = (uint64_t *)s->gb.buffer;
+        uint8_t *head = avpkt->data;
+        uint8_t *marker = head + bytestream2_tell(&s->gb) + nb_blocks * 8;
+
+        av_log(s->avctx, AV_LOG_INFO, "Recreating invalid offset table.\n");
+
+        // recreate the line offset table using the length field for each line
+        // decode_block() will check for out-of-bounds offsets, so do not bother
+        // to check here
+        for (y = 0; y < nb_blocks; y++)
+        {
+            table[y] = marker - head;
+            marker += ((uint32_t *)marker)[1] + 8;
+        }
+    }
+
    // save pointer we are going to use in decode_block
    s->buf      = avpkt->data;
    s->buf_size = avpkt->size;
--
2.1.4
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


   


More information about the ffmpeg-devel mailing list