[FFmpeg-devel] [PATCH] vqavideo: return error when vqa_decode_chunk fails.
Reimar Döffinger
Reimar.Doeffinger at gmx.de
Sun Jan 8 14:42:18 CET 2012
This fixes the decoder returning an uninitialized frame (though
framecrc shows it as being the same as the previous frame).
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
---
libavcodec/vqavideo.c | 24 ++++++++++++++++--------
tests/ref/fate/vqa-cc | 1 -
2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/libavcodec/vqavideo.c b/libavcodec/vqavideo.c
index ae99c6d..a53faec 100644
--- a/libavcodec/vqavideo.c
+++ b/libavcodec/vqavideo.c
@@ -294,7 +294,7 @@ static void decode_format80(const unsigned char *src, int src_size,
dest_index, dest_size);
}
-static void vqa_decode_chunk(VqaContext *s)
+static int vqa_decode_chunk(VqaContext *s)
{
unsigned int chunk_type;
unsigned int chunk_size;
@@ -381,7 +381,7 @@ static void vqa_decode_chunk(VqaContext *s)
/* a chunk should not have both chunk types */
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: found both CPL0 and CPLZ chunks\n");
- return;
+ return AVERROR_INVALIDDATA;
}
/* decompress the palette chunk */
@@ -399,7 +399,7 @@ static void vqa_decode_chunk(VqaContext *s)
if (chunk_size / 3 > 256) {
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: found a palette chunk with %d colors\n",
chunk_size / 3);
- return;
+ return AVERROR_INVALIDDATA;
}
cpl0_chunk += CHUNK_PREAMBLE_SIZE;
for (i = 0; i < chunk_size / 3; i++) {
@@ -417,7 +417,7 @@ static void vqa_decode_chunk(VqaContext *s)
/* a chunk should not have both chunk types */
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: found both CBF0 and CBFZ chunks\n");
- return;
+ return AVERROR_INVALIDDATA;
}
/* decompress the full codebook chunk */
@@ -437,7 +437,7 @@ static void vqa_decode_chunk(VqaContext *s)
if (chunk_size > MAX_CODEBOOK_SIZE) {
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: CBF0 chunk too large (0x%X bytes)\n",
chunk_size);
- return;
+ return AVERROR_INVALIDDATA;
}
cbf0_chunk += CHUNK_PREAMBLE_SIZE;
@@ -449,7 +449,7 @@ static void vqa_decode_chunk(VqaContext *s)
/* something is wrong if there is no VPTZ chunk */
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: no VPTZ chunk found\n");
- return;
+ return AVERROR_INVALIDDATA;
}
chunk_size = AV_RB32(&s->buf[vptz_chunk + 4]);
@@ -519,7 +519,11 @@ static void vqa_decode_chunk(VqaContext *s)
if ((cbp0_chunk != -1) && (cbpz_chunk != -1)) {
/* a chunk should not have both chunk types */
av_log(s->avctx, AV_LOG_ERROR, " VQA video: problem: found both CBP0 and CBPZ chunks\n");
- return;
+ /* this is a bit questionable since it really means the
+ * following frames will be broken, not the current one,
+ * might be better to just ignore it or even better
+ * only process CBPZ which should contain a full codebook */
+ return AVERROR_INVALIDDATA;
}
if (cbp0_chunk != -1) {
@@ -568,12 +572,14 @@ static void vqa_decode_chunk(VqaContext *s)
s->partial_countdown = s->partial_count;
}
}
+ return 0;
}
static int vqa_decode_frame(AVCodecContext *avctx,
void *data, int *data_size,
AVPacket *avpkt)
{
+ int ret;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
VqaContext *s = avctx->priv_data;
@@ -589,7 +595,9 @@ static int vqa_decode_frame(AVCodecContext *avctx,
return -1;
}
- vqa_decode_chunk(s);
+ ret = vqa_decode_chunk(s);
+ if (ret < 0)
+ return ret;
/* make the palette available on the way out */
memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4);
diff --git a/tests/ref/fate/vqa-cc b/tests/ref/fate/vqa-cc
index fdc7e72..e15e727 100644
--- a/tests/ref/fate/vqa-cc
+++ b/tests/ref/fate/vqa-cc
@@ -68,7 +68,6 @@
1, 218996, 2940, 0xac8bb6c8
0, 222000, 192000, 0xb58c1566
1, 224996, 2940, 0xa503c73b
-0, 228000, 192000, 0xb58c1566
1, 230996, 2940, 0x7cd588a3
1, 236996, 2940, 0xa6974b04
1, 242996, 2940, 0xbf448241
--
1.7.8.3
More information about the ffmpeg-devel
mailing list