GetByteContext gb;
uint8_t *video[2];
unsigned video_size;
- uint32_t *pal[2];
+ uint32_t *pal;
} IffContext;
#define LUT8_PART(plane, v) \
break;
} else if (chunk_id == MKTAG('C', 'M', 'A', 'P')) {
int count = data_size / 3;
- uint32_t *pal = s->pal[0];
+ uint32_t *pal = s->pal;
if (count > 256)
return AVERROR_INVALIDDATA;
av_freep(&s->ham_palbuf);
av_freep(&s->video[0]);
av_freep(&s->video[1]);
- av_freep(&s->pal[0]);
- av_freep(&s->pal[1]);
+ av_freep(&s->pal);
return 0;
}
s->video_size = FFALIGN(avctx->width, 2) * avctx->height * s->bpp;
s->video[0] = av_calloc(FFALIGN(avctx->width, 2) * avctx->height, s->bpp);
s->video[1] = av_calloc(FFALIGN(avctx->width, 2) * avctx->height, s->bpp);
- s->pal[0] = av_calloc(256, sizeof(*s->pal[0]));
- s->pal[1] = av_calloc(256, sizeof(*s->pal[1]));
- if (!s->video[0] || !s->video[1] || !s->pal[0] || !s->pal[1])
+ s->pal = av_calloc(256, sizeof(*s->pal));
+ if (!s->video[0] || !s->video[1] || !s->pal)
return AVERROR(ENOMEM);
}
for (g = 0; g < groups; g++) {
offset = bytestream2_get_be16(&gb);
- if (bytestream2_get_bytes_left(&gb) < 1)
+ if (cols * bpp == 0 || bytestream2_get_bytes_left(&gb) < cols * bpp) {
+ av_log(NULL, AV_LOG_ERROR, "cols*bpp is invalid (%d*%d)", cols, bpp);
return;
+ }
if (kludge_j)
offset = ((offset / (320 / 8)) * pitch) + (offset % (320 / 8)) - kludge_j;
for (d = 0; d < bpp; d++) {
unsigned noffset = offset + (r * pitch) + d * planepitch;
- if (bytestream2_get_bytes_left(&gb) < 1)
+ if (!bytes || bytestream2_get_bytes_left(&gb) < bytes) {
+ av_log(NULL, AV_LOG_ERROR, "bytes %d is invalid", bytes);
return;
+ }
for (b = 0; b < bytes; b++) {
uint8_t value = bytestream2_get_byte(&gb);
bytestream2_init(&dgb, buf + 2 * poff0, buf_end - (buf + 2 * poff0));
bytestream2_init(&ogb, buf + 2 * poff1, buf_end - (buf + 2 * poff1));
- while ((bytestream2_peek_be16(&ogb)) != 0xFFFF && bytestream2_get_bytes_left(&ogb) >= 4) {
+ while (bytestream2_peek_be16(&ogb) != 0xFFFF && bytestream2_get_bytes_left(&ogb) >= 4) {
uint32_t offset = bytestream2_get_be16(&ogb);
int16_t cnt = bytestream2_get_be16(&ogb);
uint16_t data;
offset = ((2 * offset) / planepitch_byte) * pitch + ((2 * offset) % planepitch_byte) + k * planepitch;
if (cnt < 0) {
+ if (bytestream2_get_bytes_left(&dgb) < 2)
+ break;
bytestream2_seek_p(&pb, offset, SEEK_SET);
cnt = -cnt;
data = bytestream2_get_be16(&dgb);
bytestream2_skip_p(&pb, dstpitch - 2);
}
} else {
+ if (bytestream2_get_bytes_left(&dgb) < 2*cnt)
+ break;
bytestream2_seek_p(&pb, offset, SEEK_SET);
for (i = 0; i < cnt; i++) {
data = bytestream2_get_be16(&dgb);
if (s->compression <= 0xff && (avctx->codec_tag == MKTAG('A', 'N', 'I', 'M'))) {
if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
- memcpy(s->pal[0], s->frame->data[1], 256 * 4);
+ memcpy(s->pal, s->frame->data[1], 256 * 4);
}
switch (s->compression) {
}
if (s->compression <= 0xff && (avctx->codec_tag == MKTAG('A', 'N', 'I', 'M'))) {
- memcpy(s->pal[1], s->pal[0], 256 * 4);
memcpy(s->video[1], s->video[0], s->video_size);
}
buf += s->planesize;
}
}
- memcpy(frame->data[1], s->pal[0], 256 * 4);
+ memcpy(frame->data[1], s->pal, 256 * 4);
} else if (s->ham) {
int i, count = 1 << s->ham;
buf = s->video[0];
memset(s->ham_palbuf, 0, (1 << s->ham) * 2 * sizeof(uint32_t));
for (i = 0; i < count; i++) {
- s->ham_palbuf[i*2+1] = s->pal[0][i];
+ s->ham_palbuf[i*2+1] = s->pal[i];
}
for (i = 0; i < count; i++) {
uint32_t tmp = i << (8 - s->ham);
if (!s->is_brush) {
FFSWAP(uint8_t *, s->video[0], s->video[1]);
- FFSWAP(uint32_t *, s->pal[0], s->pal[1]);
}
}