Skip to content

Commit ab7d38f

Browse files
committed
avcodec/cscd: Fix "CamStudio Lossless Codec 1.0" gzip files
Fixes: tickets/10241/cscd_1_0_306_306_gzip.avi Signed-off-by: Michael Niedermayer <[email protected]>
1 parent d2a0464 commit ab7d38f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

libavcodec/cscd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
7070
int buf_size = avpkt->size;
7171
CamStudioContext *c = avctx->priv_data;
7272
int ret;
73+
int bpp = avctx->bits_per_coded_sample / 8;
74+
int bugdelta = FFALIGN(avctx->width * bpp, 4) * avctx->height
75+
- (avctx->width & ~3) * bpp * avctx->height;
7376

7477
if (buf_size < 2) {
7578
av_log(avctx, AV_LOG_ERROR, "coded frame too small\n");
@@ -83,9 +86,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
8386
switch ((buf[0] >> 1) & 7) {
8487
case 0: { // lzo compression
8588
int outlen = c->decomp_size, inlen = buf_size - 2;
86-
int bpp = avctx->bits_per_coded_sample / 8;
87-
int bugdelta = FFALIGN(avctx->width * bpp, 4) * avctx->height
88-
- (avctx->width & ~3) * bpp * avctx->height;
8989
if (av_lzo1x_decode(c->decomp_buf, &outlen, &buf[2], &inlen) || (outlen && outlen != bugdelta)) {
9090
av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n");
9191
return AVERROR_INVALIDDATA;
@@ -95,7 +95,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
9595
case 1: { // zlib compression
9696
#if CONFIG_ZLIB
9797
unsigned long dlen = c->decomp_size;
98-
if (uncompress(c->decomp_buf, &dlen, &buf[2], buf_size - 2) != Z_OK || dlen != c->decomp_size) {
98+
if (uncompress(c->decomp_buf, &dlen, &buf[2], buf_size - 2) != Z_OK || (dlen != c->decomp_size && dlen != c->decomp_size - bugdelta)) {
9999
av_log(avctx, AV_LOG_ERROR, "error during zlib decompression\n");
100100
return AVERROR_INVALIDDATA;
101101
}

0 commit comments

Comments
 (0)