[FFmpeg-devel] [PATCH]lavc/proresdec2: Fix slice_count for very high resolutions

Carl Eugen Hoyos cehoyos at ag.or.at
Sun Oct 25 13:37:15 CET 2015


Hi!

Attached patch intends to fix an issue reported by forum user Koracas:
For slice_count > 0x10000 FFmpeg fails to decode a frame, QT seems to 
ignore the value.

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c
index 932f85f..7d06a0b 100644
--- a/libavcodec/proresdec2.c
+++ b/libavcodec/proresdec2.c
@@ -153,6 +153,7 @@ static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, cons
     int log2_slice_mb_width, log2_slice_mb_height;
     int slice_mb_count, mb_x, mb_y;
     const uint8_t *data_ptr, *index_ptr;
+    const int mb_height_pow2[] = { 1, 2, 4, 8 };
 
     hdr_size = buf[0] >> 3;
     if (hdr_size < 8 || hdr_size > buf_size) {
@@ -181,6 +182,9 @@ static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, cons
         ctx->mb_height = (avctx->height + 15) >> 4;
 
     slice_count = AV_RB16(buf + 5);
+    // QT ignores the written value
+    slice_count = FFMAX(slice_count,
+                        ctx->mb_width * ctx->mb_height / mb_height_pow2[log2_slice_mb_width]);
 
     if (ctx->slice_count != slice_count || !ctx->slices) {
         av_freep(&ctx->slices);


More information about the ffmpeg-devel mailing list