542
542
return AVERROR_INVALIDDATA;
545
s->width = bytestream2_get_be32(&s->gb);
546
s->height = bytestream2_get_be32(&s->gb);
545
if (s->state & PNG_IHDR) {
546
av_log(avctx, AV_LOG_ERROR, "Multiple IHDR\n");
547
return AVERROR_INVALIDDATA;
550
s->width = s->cur_w = bytestream2_get_be32(&s->gb);
551
s->height = s->cur_h = bytestream2_get_be32(&s->gb);
547
552
if (av_image_check_size(s->width, s->height, 0, avctx)) {
548
s->width = s->height = 0;
553
s->cur_w = s->cur_h = s->width = s->height = 0;
549
554
av_log(avctx, AV_LOG_ERROR, "Invalid image size\n");
550
555
return AVERROR_INVALIDDATA;
552
if (s->cur_w == 0 && s->cur_h == 0) {
553
// Only set cur_w/h if update_thread_context() has not set it
555
s->cur_h = s->height;
557
557
s->bit_depth = bytestream2_get_byte(&s->gb);
558
558
s->color_type = bytestream2_get_byte(&s->gb);
559
559
s->compression_type = bytestream2_get_byte(&s->gb);
817
817
uint32_t sequence_number;
818
int cur_w, cur_h, x_offset, y_offset, dispose_op, blend_op;
819
820
if (length != 26)
820
821
return AVERROR_INVALIDDATA;
823
if (!(s->state & PNG_IHDR)) {
824
av_log(avctx, AV_LOG_ERROR, "fctl before IHDR\n");
825
return AVERROR_INVALIDDATA;
822
828
s->last_w = s->cur_w;
823
829
s->last_h = s->cur_h;
824
830
s->last_x_offset = s->x_offset;
826
832
s->last_dispose_op = s->dispose_op;
828
834
sequence_number = bytestream2_get_be32(&s->gb);
829
s->cur_w = bytestream2_get_be32(&s->gb);
830
s->cur_h = bytestream2_get_be32(&s->gb);
831
s->x_offset = bytestream2_get_be32(&s->gb);
832
s->y_offset = bytestream2_get_be32(&s->gb);
835
cur_w = bytestream2_get_be32(&s->gb);
836
cur_h = bytestream2_get_be32(&s->gb);
837
x_offset = bytestream2_get_be32(&s->gb);
838
y_offset = bytestream2_get_be32(&s->gb);
833
839
bytestream2_skip(&s->gb, 4); /* delay_num (2), delay_den (2) */
834
s->dispose_op = bytestream2_get_byte(&s->gb);
835
s->blend_op = bytestream2_get_byte(&s->gb);
840
dispose_op = bytestream2_get_byte(&s->gb);
841
blend_op = bytestream2_get_byte(&s->gb);
836
842
bytestream2_skip(&s->gb, 4); /* crc */
838
844
if (sequence_number == 0 &&
839
(s->cur_w != s->width ||
840
s->cur_h != s->height ||
843
s->cur_w <= 0 || s->cur_h <= 0 ||
844
s->x_offset < 0 || s->y_offset < 0 ||
845
s->cur_w > s->width - s->x_offset|| s->cur_h > s->height - s->y_offset)
845
(cur_w != s->width ||
846
cur_h != s->height ||
849
cur_w <= 0 || cur_h <= 0 ||
850
x_offset < 0 || y_offset < 0 ||
851
cur_w > s->width - x_offset|| cur_h > s->height - y_offset)
846
852
return AVERROR_INVALIDDATA;
848
854
if (sequence_number == 0 && s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) {
1259
1272
(ret = ff_thread_ref_frame(&pdst->picture, &psrc->picture)) < 0)
1261
1274
if (CONFIG_APNG_DECODER && dst->codec_id == AV_CODEC_ID_APNG) {
1275
pdst->width = psrc->width;
1276
pdst->height = psrc->height;
1277
pdst->bit_depth = psrc->bit_depth;
1278
pdst->color_type = psrc->color_type;
1279
pdst->compression_type = psrc->compression_type;
1280
pdst->interlace_type = psrc->interlace_type;
1281
pdst->filter_type = psrc->filter_type;
1262
1282
pdst->cur_w = psrc->cur_w;
1263
1283
pdst->cur_h = psrc->cur_h;
1264
1284
pdst->x_offset = psrc->x_offset;
1265
1285
pdst->y_offset = psrc->y_offset;
1266
1287
pdst->dispose_op = psrc->dispose_op;
1289
memcpy(pdst->palette, psrc->palette, sizeof(pdst->palette));
1291
pdst->state |= psrc->state & (PNG_IHDR | PNG_PLTE);
1268
1293
ff_thread_release_buffer(dst, &pdst->last_picture);
1269
1294
if (psrc->last_picture.f->data[0])
1270
1295
return ff_thread_ref_frame(&pdst->last_picture, &psrc->last_picture);