-
- if (avctx->codec->id == AV_CODEC_ID_XAN_WC3) {
- const uint8_t *buf_end = buf + buf_size;
- int tag = 0;
- while (buf_end - buf > 8 && tag != VGA__TAG) {
- unsigned *tmpptr;
- uint32_t new_pal;
- int size;
- int i;
- tag = bytestream_get_le32(&buf);
- size = bytestream_get_be32(&buf);
- size = FFMIN(size, buf_end - buf);
- switch (tag) {
- case PALT_TAG:
- if (size < PALETTE_SIZE)
- return AVERROR_INVALIDDATA;
- if (s->palettes_count >= PALETTES_MAX)
- return AVERROR_INVALIDDATA;
- tmpptr = av_realloc(s->palettes,
- (s->palettes_count + 1) * AVPALETTE_SIZE);
- if (!tmpptr)
- return AVERROR(ENOMEM);
- s->palettes = tmpptr;
- tmpptr += s->palettes_count * AVPALETTE_COUNT;
- for (i = 0; i < PALETTE_COUNT; i++) {
+ GetByteContext ctx;
+ int tag = 0;
+
+ bytestream2_init(&ctx, buf, buf_size);
+ while (bytestream2_get_bytes_left(&ctx) > 8 && tag != VGA__TAG) {
+ unsigned *tmpptr;
+ uint32_t new_pal;
+ int size;
+ int i;
+ tag = bytestream2_get_le32(&ctx);
+ size = bytestream2_get_be32(&ctx);
+ size = FFMIN(size, bytestream2_get_bytes_left(&ctx));
+ switch (tag) {
+ case PALT_TAG:
+ if (size < PALETTE_SIZE)
+ return AVERROR_INVALIDDATA;
+ if (s->palettes_count >= PALETTES_MAX)
+ return AVERROR_INVALIDDATA;
+ tmpptr = av_realloc(s->palettes,
+ (s->palettes_count + 1) * AVPALETTE_SIZE);
+ if (!tmpptr)
+ return AVERROR(ENOMEM);
+ s->palettes = tmpptr;
+ tmpptr += s->palettes_count * AVPALETTE_COUNT;
+ for (i = 0; i < PALETTE_COUNT; i++) {