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] avcodec/zmbv: handle corrupted packet
       [not found] <20231008131702.53228-1-quinkblack@foxmail.com>
@ 2023-10-08 13:17 ` Zhao Zhili
  0 siblings, 0 replies; only message in thread
From: Zhao Zhili @ 2023-10-08 13:17 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Zhao Zhili

From: Zhao Zhili <zhilizhao@tencent.com>

Mark the frame as corrupt when AV_CODEC_FLAG_OUTPUT_CORRUPT is set,
drop the frame otherwise.
---
 libavcodec/zmbv.c        | 26 ++++++++++++++++++++------
 tests/ref/fate/zmbv-8bit |  1 -
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/libavcodec/zmbv.c b/libavcodec/zmbv.c
index d309a8612b..c7408f7af8 100644
--- a/libavcodec/zmbv.c
+++ b/libavcodec/zmbv.c
@@ -148,9 +148,11 @@ static int zmbv_decode_xor_8(ZmbvContext *c)
         output += c->width * c->bh;
         prev += c->width * c->bh;
     }
-    if (src - c->decomp_buf != c->decomp_len)
+    if (src - c->decomp_buf != c->decomp_len) {
         av_log(c->avctx, AV_LOG_ERROR, "Used %"PTRDIFF_SPECIFIER" of %i bytes\n",
                src-c->decomp_buf, c->decomp_len);
+        return AVERROR_INVALIDDATA;
+    }
     return 0;
 }
 
@@ -224,9 +226,11 @@ static int zmbv_decode_xor_16(ZmbvContext *c)
         output += c->width * c->bh;
         prev += c->width * c->bh;
     }
-    if (src - c->decomp_buf != c->decomp_len)
+    if (src - c->decomp_buf != c->decomp_len) {
         av_log(c->avctx, AV_LOG_ERROR, "Used %"PTRDIFF_SPECIFIER" of %i bytes\n",
                src-c->decomp_buf, c->decomp_len);
+        return AVERROR_INVALIDDATA;
+    }
     return 0;
 }
 
@@ -309,9 +313,11 @@ static int zmbv_decode_xor_24(ZmbvContext *c)
         output += stride * c->bh;
         prev += stride * c->bh;
     }
-    if (src - c->decomp_buf != c->decomp_len)
+    if (src - c->decomp_buf != c->decomp_len) {
         av_log(c->avctx, AV_LOG_ERROR, "Used %"PTRDIFF_SPECIFIER" of %i bytes\n",
                src-c->decomp_buf, c->decomp_len);
+        return AVERROR_INVALIDDATA;
+    }
     return 0;
 }
 #endif //ZMBV_ENABLE_24BPP
@@ -386,9 +392,11 @@ static int zmbv_decode_xor_32(ZmbvContext *c)
         output += c->width * c->bh;
         prev   += c->width * c->bh;
     }
-    if (src - c->decomp_buf != c->decomp_len)
+    if (src - c->decomp_buf != c->decomp_len) {
         av_log(c->avctx, AV_LOG_ERROR, "Used %"PTRDIFF_SPECIFIER" of %i bytes\n",
                src-c->decomp_buf, c->decomp_len);
+        return AVERROR_INVALIDDATA;
+    }
     return 0;
 }
 
@@ -567,8 +575,14 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         frame->pict_type = AV_PICTURE_TYPE_P;
         if (c->decomp_len < 2LL * ((c->width + c->bw - 1) / c->bw) * ((c->height + c->bh - 1) / c->bh))
             return AVERROR_INVALIDDATA;
-        if (c->decomp_len)
-            c->decode_xor(c);
+        if (c->decomp_len) {
+            if (c->decode_xor(c) < 0) {
+                if (avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT)
+                    frame->flags |= AV_FRAME_FLAG_CORRUPT;
+                else
+                    return buf_size;
+            }
+        }
     }
 
     /* update frames */
diff --git a/tests/ref/fate/zmbv-8bit b/tests/ref/fate/zmbv-8bit
index 7c2fab691f..9a7c96cb32 100644
--- a/tests/ref/fate/zmbv-8bit
+++ b/tests/ref/fate/zmbv-8bit
@@ -278,4 +278,3 @@
 0,        272,        272,        1,   192000, 0xd08e49d1
 0,        273,        273,        1,   192000, 0xd08e49d1
 0,        274,        274,        1,   192000, 0xd08e49d1
-0,        275,        275,        1,   192000, 0x1f34135f
-- 
2.42.0

_______________________________________________
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:[~2023-10-08 13:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20231008131702.53228-1-quinkblack@foxmail.com>
2023-10-08 13:17 ` [FFmpeg-devel] [PATCH] avcodec/zmbv: handle corrupted packet Zhao Zhili

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