[FFmpeg-devel] [PATCH] Fix decoding large Cinepak files
Kostya
kostya.shishkov
Mon Jan 12 19:05:45 CET 2009
As it turned out, Cinepak format use 24-bit sizes instead of
16 bits as it was thought before. Naturally, the problem
manifested itself only for slices >= 64k.
With this patch it's possible to correctly decode ross.mov
for issue 744 and garbage is gone for
http://samples.mplayerhq.hu/V-codecs/CVID/tn.avi
-------------- next part --------------
Index: libavcodec/cinepak.c
===================================================================
--- libavcodec/cinepak.c (revision 15993)
+++ libavcodec/cinepak.c (working copy)
@@ -77,12 +77,12 @@
int i, n;
/* check if this chunk contains 4- or 6-element vectors */
- n = (chunk_id & 0x0400) ? 4 : 6;
+ n = (chunk_id & 0x04) ? 4 : 6;
flag = 0;
mask = 0;
for (i=0; i < 256; i++) {
- if ((chunk_id & 0x0100) && !(mask >>= 1)) {
+ if ((chunk_id & 0x01) && !(mask >>= 1)) {
if ((data + 4) > eod)
break;
@@ -91,7 +91,7 @@
mask = 0x80000000;
}
- if (!(chunk_id & 0x0100) || (flag & mask)) {
+ if (!(chunk_id & 0x01) || (flag & mask)) {
if ((data + n) > eod)
break;
@@ -144,7 +144,7 @@
iv[1] = iv[0] + s->frame.linesize[2];
for (x=strip->x1; x < strip->x2; x+=4) {
- if ((chunk_id & 0x0100) && !(mask >>= 1)) {
+ if ((chunk_id & 0x01) && !(mask >>= 1)) {
if ((data + 4) > eod)
return -1;
@@ -153,8 +153,8 @@
mask = 0x80000000;
}
- if (!(chunk_id & 0x0100) || (flag & mask)) {
- if (!(chunk_id & 0x0200) && !(mask >>= 1)) {
+ if (!(chunk_id & 0x01) || (flag & mask)) {
+ if (!(chunk_id & 0x02) && !(mask >>= 1)) {
if ((data + 4) > eod)
return -1;
@@ -163,7 +163,7 @@
mask = 0x80000000;
}
- if ((chunk_id & 0x0200) || (~flag & mask)) {
+ if ((chunk_id & 0x02) || (~flag & mask)) {
if (data >= eod)
return -1;
@@ -274,8 +274,8 @@
return -1;
while ((data + 4) <= eod) {
- chunk_id = AV_RB16 (&data[0]);
- chunk_size = AV_RB16 (&data[2]) - 4;
+ chunk_id = data[0];
+ chunk_size = AV_RB24 (&data[1]) - 4;
if(chunk_size < 0)
return -1;
@@ -284,25 +284,25 @@
switch (chunk_id) {
- case 0x2000:
- case 0x2100:
- case 0x2400:
- case 0x2500:
+ case 0x20:
+ case 0x21:
+ case 0x24:
+ case 0x25:
cinepak_decode_codebook (strip->v4_codebook, chunk_id,
chunk_size, data);
break;
- case 0x2200:
- case 0x2300:
- case 0x2600:
- case 0x2700:
+ case 0x22:
+ case 0x23:
+ case 0x26:
+ case 0x27:
cinepak_decode_codebook (strip->v1_codebook, chunk_id,
chunk_size, data);
break;
- case 0x3000:
- case 0x3100:
- case 0x3200:
+ case 0x30:
+ case 0x31:
+ case 0x32:
return cinepak_decode_vectors (s, strip, chunk_id,
chunk_size, data);
}
@@ -363,7 +363,7 @@
s->strips[i].y2 = y0 + AV_RB16 (&s->data[8]);
s->strips[i].x2 = s->avctx->width;
- strip_size = AV_RB16 (&s->data[2]) - 12;
+ strip_size = AV_RB24 (&s->data[1]) - 12;
s->data += 12;
strip_size = ((s->data + strip_size) > eod) ? (eod - s->data) : strip_size;
More information about the ffmpeg-devel
mailing list