This makes sure that reading a truncated chunk will never overflow into the following chunk. It also allows to remove many repeated lines skipping over the trailing crc checksum.
Unified · Split
| @@ -421,13 +421,12 @@ the_end:; · 420 unmodified lines | ||
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | −static int png_decode_idat(PNGDecContext *s, int length, | |
| 424 | +static int png_decode_idat(PNGDecContext *s, GetByteContext *gb, | |
| 425 | 425 | uint8_t *dst, ptrdiff_t dst_stride) |
| 426 | 426 | { |
| 427 | 427 | int ret; |
| 428 | − s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb)); | |
| 429 | − s->zstream.next_in = s->gb.buffer; | |
| 430 | − bytestream2_skip(&s->gb, length); | |
| 428 | + s->zstream.avail_in = bytestream2_get_bytes_left(gb); | |
| 429 | + s->zstream.next_in = gb->buffer; | |
| 431 | 430 | |
| 432 | 431 | /* decode one line if possible */ |
| 433 | 432 | while (s->zstream.avail_in > 0) { |
| @@ -520,11 +519,11 @@ static uint8_t *iso88591_to_utf8(const uint8_t *in, size_t size_in) · 86 unmodified lines | ||
| 520 | 519 | return out; |
| 521 | 520 | } |
| 522 | 521 | |
| 523 | −static int decode_text_chunk(PNGDecContext *s, uint32_t length, int compressed) | |
| 522 | +static int decode_text_chunk(PNGDecContext *s, GetByteContext *gb, int compressed) | |
| 524 | 523 | { |
| 525 | 524 | int ret, method; |
| 526 | − const uint8_t *data = s->gb.buffer; | |
| 527 | − const uint8_t *data_end = data + length; | |
| 525 | + const uint8_t *data = gb->buffer; | |
| 526 | + const uint8_t *data_end = gb->buffer_end; | |
| 528 | 527 | const uint8_t *keyword = data; |
| 529 | 528 | const uint8_t *keyword_end = memchr(keyword, 0, data_end - keyword); |
| 530 | 529 | uint8_t *kw_utf8 = NULL, *text, *txt_utf8 = NULL; |
| @@ -568,9 +567,9 @@ static int decode_text_chunk(PNGDecContext *s, uint32_t length, int compressed) · 37 unmodified lines | ||
| 568 | 567 | } |
| 569 | 568 | |
| 570 | 569 | static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s, |
| 571 | − uint32_t length) | |
| 570 | + GetByteContext *gb) | |
| 572 | 571 | { |
| 573 | − if (length != 13) | |
| 572 | + if (bytestream2_get_bytes_left(gb) != 13) | |
| 574 | 573 | return AVERROR_INVALIDDATA; |
| 575 | 574 | |
| 576 | 575 | if (s->pic_state & PNG_IDAT) { |
| @@ -583,28 +582,27 @@ static int decode_ihdr_chunk(AVCodecContext *avctx, PNGDecContext *s, · 6 unmodified lines | ||
| 583 | 582 | return AVERROR_INVALIDDATA; |
| 584 | 583 | } |
| 585 | 584 | |
| 586 | − s->width = s->cur_w = bytestream2_get_be32(&s->gb); | |
| 587 | − s->height = s->cur_h = bytestream2_get_be32(&s->gb); | |
| 585 | + s->width = s->cur_w = bytestream2_get_be32(gb); | |
| 586 | + s->height = s->cur_h = bytestream2_get_be32(gb); | |
| 588 | 587 | if (av_image_check_size(s->width, s->height, 0, avctx)) { |
| 589 | 588 | s->cur_w = s->cur_h = s->width = s->height = 0; |
| 590 | 589 | av_log(avctx, AV_LOG_ERROR, "Invalid image size\n"); |
| 591 | 590 | return AVERROR_INVALIDDATA; |
| 592 | 591 | } |
| 593 | − s->bit_depth = bytestream2_get_byte(&s->gb); | |
| 592 | + s->bit_depth = bytestream2_get_byte(gb); | |
| 594 | 593 | if (s->bit_depth != 1 && s->bit_depth != 2 && s->bit_depth != 4 && |
| 595 | 594 | s->bit_depth != 8 && s->bit_depth != 16) { |
| 596 | 595 | av_log(avctx, AV_LOG_ERROR, "Invalid bit depth\n"); |
| 597 | 596 | goto error; |
| 598 | 597 | } |
| 599 | − s->color_type = bytestream2_get_byte(&s->gb); | |
| 600 | − s->compression_type = bytestream2_get_byte(&s->gb); | |
| 598 | + s->color_type = bytestream2_get_byte(gb); | |
| 599 | + s->compression_type = bytestream2_get_byte(gb); | |
| 601 | 600 | if (s->compression_type) { |
| 602 | 601 | av_log(avctx, AV_LOG_ERROR, "Invalid compression method %d\n", s->compression_type); |
| 603 | 602 | goto error; |
| 604 | 603 | } |
| 605 | − s->filter_type = bytestream2_get_byte(&s->gb); | |
| 606 | − s->interlace_type = bytestream2_get_byte(&s->gb); | |
| 607 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 604 | + s->filter_type = bytestream2_get_byte(gb); | |
| 605 | + s->interlace_type = bytestream2_get_byte(gb); | |
| 608 | 606 | s->hdr_state |= PNG_IHDR; |
| 609 | 607 | if (avctx->debug & FF_DEBUG_PICT_INFO) |
| 610 | 608 | av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d " |
| @@ -619,24 +617,24 @@ error: · 8 unmodified lines | ||
| 619 | 617 | return AVERROR_INVALIDDATA; |
| 620 | 618 | } |
| 621 | 619 | |
| 622 | −static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s) | |
| 620 | +static int decode_phys_chunk(AVCodecContext *avctx, PNGDecContext *s, | |
| 621 | + GetByteContext *gb) | |
| 623 | 622 | { |
| 624 | 623 | if (s->pic_state & PNG_IDAT) { |
| 625 | 624 | av_log(avctx, AV_LOG_ERROR, "pHYs after IDAT\n"); |
| 626 | 625 | return AVERROR_INVALIDDATA; |
| 627 | 626 | } |
| 628 | − avctx->sample_aspect_ratio.num = bytestream2_get_be32(&s->gb); | |
| 629 | − avctx->sample_aspect_ratio.den = bytestream2_get_be32(&s->gb); | |
| 627 | + avctx->sample_aspect_ratio.num = bytestream2_get_be32(gb); | |
| 628 | + avctx->sample_aspect_ratio.den = bytestream2_get_be32(gb); | |
| 630 | 629 | if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.den < 0) |
| 631 | 630 | avctx->sample_aspect_ratio = (AVRational){ 0, 1 }; |
| 632 | − bytestream2_skip(&s->gb, 1); /* unit specifier */ | |
| 633 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 631 | + bytestream2_skip(gb, 1); /* unit specifier */ | |
| 634 | 632 | |
| 635 | 633 | return 0; |
| 636 | 634 | } |
| 637 | 635 | |
| 638 | 636 | static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, |
| 639 | − uint32_t length, AVFrame *p) | |
| 637 | + GetByteContext *gb, AVFrame *p) | |
| 640 | 638 | { |
| 641 | 639 | int ret; |
| 642 | 640 | size_t byte_depth = s->bit_depth > 8 ? 2 : 1; |
| @@ -773,7 +771,7 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, · 130 unmodified lines | ||
| 773 | 771 | if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE) |
| 774 | 772 | s->bpp -= byte_depth; |
| 775 | 773 | |
| 776 | − ret = png_decode_idat(s, length, p->data[0], p->linesize[0]); | |
| 774 | + ret = png_decode_idat(s, gb, p->data[0], p->linesize[0]); | |
| 777 | 775 | |
| 778 | 776 | if (s->has_trns && s->color_type != PNG_COLOR_TYPE_PALETTE) |
| 779 | 777 | s->bpp += byte_depth; |
| @@ -781,14 +779,13 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, · 1 unmodified line | ||
| 781 | 779 | if (ret < 0) |
| 782 | 780 | return ret; |
| 783 | 781 | |
| 784 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 785 | − | |
| 786 | 782 | return 0; |
| 787 | 783 | } |
| 788 | 784 | |
| 789 | 785 | static int decode_plte_chunk(AVCodecContext *avctx, PNGDecContext *s, |
| 790 | − uint32_t length) | |
| 786 | + GetByteContext *gb) | |
| 791 | 787 | { |
| 788 | + int length = bytestream2_get_bytes_left(gb); | |
| 792 | 789 | int n, i, r, g, b; |
| 793 | 790 | |
| 794 | 791 | if ((length % 3) != 0 || length > 256 * 3) |
| @@ -796,22 +793,22 @@ static int decode_plte_chunk(AVCodecContext *avctx, PNGDecContext *s, · 1 unmodified line | ||
| 796 | 793 | /* read the palette */ |
| 797 | 794 | n = length / 3; |
| 798 | 795 | for (i = 0; i < n; i++) { |
| 799 | − r = bytestream2_get_byte(&s->gb); | |
| 800 | − g = bytestream2_get_byte(&s->gb); | |
| 801 | − b = bytestream2_get_byte(&s->gb); | |
| 796 | + r = bytestream2_get_byte(gb); | |
| 797 | + g = bytestream2_get_byte(gb); | |
| 798 | + b = bytestream2_get_byte(gb); | |
| 802 | 799 | s->palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | b; |
| 803 | 800 | } |
| 804 | 801 | for (; i < 256; i++) |
| 805 | 802 | s->palette[i] = (0xFFU << 24); |
| 806 | 803 | s->hdr_state |= PNG_PLTE; |
| 807 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 808 | 804 | |
| 809 | 805 | return 0; |
| 810 | 806 | } |
| 811 | 807 | |
| 812 | 808 | static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s, |
| 813 | − uint32_t length) | |
| 809 | + GetByteContext *gb) | |
| 814 | 810 | { |
| 811 | + int length = bytestream2_get_bytes_left(gb); | |
| 815 | 812 | int v, i; |
| 816 | 813 | |
| 817 | 814 | if (!(s->hdr_state & PNG_IHDR)) { |
| @@ -829,7 +826,7 @@ static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s, · 11 unmodified lines | ||
| 829 | 826 | return AVERROR_INVALIDDATA; |
| 830 | 827 | |
| 831 | 828 | for (i = 0; i < length; i++) { |
| 832 | − unsigned v = bytestream2_get_byte(&s->gb); | |
| 829 | + unsigned v = bytestream2_get_byte(gb); | |
| 833 | 830 | s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24); |
| 834 | 831 | } |
| 835 | 832 | } else if (s->color_type == PNG_COLOR_TYPE_GRAY || s->color_type == PNG_COLOR_TYPE_RGB) { |
| @@ -840,7 +837,7 @@ static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s, · 4 unmodified lines | ||
| 840 | 837 | |
| 841 | 838 | for (i = 0; i < length / 2; i++) { |
| 842 | 839 | /* only use the least significant bits */ |
| 843 | − v = av_mod_uintp2(bytestream2_get_be16(&s->gb), s->bit_depth); | |
| 840 | + v = av_mod_uintp2(bytestream2_get_be16(gb), s->bit_depth); | |
| 844 | 841 | |
| 845 | 842 | if (s->bit_depth > 8) |
| 846 | 843 | AV_WB16(&s->transparent_color_be[2 * i], v); |
| @@ -851,35 +848,30 @@ static int decode_trns_chunk(AVCodecContext *avctx, PNGDecContext *s, · 4 unmodified lines | ||
| 851 | 848 | return AVERROR_INVALIDDATA; |
| 852 | 849 | } |
| 853 | 850 | |
| 854 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 855 | 851 | s->has_trns = 1; |
| 856 | 852 | |
| 857 | 853 | return 0; |
| 858 | 854 | } |
| 859 | 855 | |
| 860 | −static int decode_iccp_chunk(PNGDecContext *s, int length, AVFrame *f) | |
| 856 | +static int decode_iccp_chunk(PNGDecContext *s, GetByteContext *gb, AVFrame *f) | |
| 861 | 857 | { |
| 862 | 858 | int ret, cnt = 0; |
| 863 | 859 | AVBPrint bp; |
| 864 | 860 | |
| 865 | − while ((s->iccp_name[cnt++] = bytestream2_get_byte(&s->gb)) && cnt < 81); | |
| 861 | + while ((s->iccp_name[cnt++] = bytestream2_get_byte(gb)) && cnt < 81); | |
| 866 | 862 | if (cnt > 80) { |
| 867 | 863 | av_log(s->avctx, AV_LOG_ERROR, "iCCP with invalid name!\n"); |
| 868 | 864 | ret = AVERROR_INVALIDDATA; |
| 869 | 865 | goto fail; |
| 870 | 866 | } |
| 871 | 867 | |
| 872 | − length = FFMAX(length - cnt, 0); | |
| 873 | − | |
| 874 | − if (bytestream2_get_byte(&s->gb) != 0) { | |
| 868 | + if (bytestream2_get_byte(gb) != 0) { | |
| 875 | 869 | av_log(s->avctx, AV_LOG_ERROR, "iCCP with invalid compression!\n"); |
| 876 | 870 | ret = AVERROR_INVALIDDATA; |
| 877 | 871 | goto fail; |
| 878 | 872 | } |
| 879 | 873 | |
| 880 | − length = FFMAX(length - 1, 0); | |
| 881 | − | |
| 882 | − if ((ret = decode_zbuf(&bp, s->gb.buffer, s->gb.buffer + length)) < 0) | |
| 874 | + if ((ret = decode_zbuf(&bp, gb->buffer, gb->buffer_end)) < 0) | |
| 883 | 875 | return ret; |
| 884 | 876 | |
| 885 | 877 | av_freep(&s->iccp_data); |
| @@ -888,9 +880,6 @@ static int decode_iccp_chunk(PNGDecContext *s, int length, AVFrame *f) · 2 unmodified lines | ||
| 888 | 880 | return ret; |
| 889 | 881 | s->iccp_data_len = bp.len; |
| 890 | 882 | |
| 891 | − /* ICC compressed data and CRC */ | |
| 892 | − bytestream2_skip(&s->gb, length + 4); | |
| 893 | − | |
| 894 | 883 | return 0; |
| 895 | 884 | fail: |
| 896 | 885 | s->iccp_name[0] = 0; |
| @@ -971,12 +960,12 @@ static void handle_small_bpp(PNGDecContext *s, AVFrame *p) · 74 unmodified lines | ||
| 971 | 960 | } |
| 972 | 961 | |
| 973 | 962 | static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s, |
| 974 | − uint32_t length) | |
| 963 | + GetByteContext *gb) | |
| 975 | 964 | { |
| 976 | 965 | uint32_t sequence_number; |
| 977 | 966 | int cur_w, cur_h, x_offset, y_offset, dispose_op, blend_op; |
| 978 | 967 | |
| 979 | − if (length != 26) | |
| 968 | + if (bytestream2_get_bytes_left(gb) != 26) | |
| 980 | 969 | return AVERROR_INVALIDDATA; |
| 981 | 970 | |
| 982 | 971 | if (!(s->hdr_state & PNG_IHDR)) { |
| @@ -995,15 +984,14 @@ static int decode_fctl_chunk(AVCodecContext *avctx, PNGDecContext *s, · 12 unmodified lines | ||
| 995 | 984 | s->last_y_offset = s->y_offset; |
| 996 | 985 | s->last_dispose_op = s->dispose_op; |
| 997 | 986 | |
| 998 | − sequence_number = bytestream2_get_be32(&s->gb); | |
| 999 | − cur_w = bytestream2_get_be32(&s->gb); | |
| 1000 | − cur_h = bytestream2_get_be32(&s->gb); | |
| 1001 | − x_offset = bytestream2_get_be32(&s->gb); | |
| 1002 | − y_offset = bytestream2_get_be32(&s->gb); | |
| 1003 | − bytestream2_skip(&s->gb, 4); /* delay_num (2), delay_den (2) */ | |
| 1004 | − dispose_op = bytestream2_get_byte(&s->gb); | |
| 1005 | − blend_op = bytestream2_get_byte(&s->gb); | |
| 1006 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 987 | + sequence_number = bytestream2_get_be32(gb); | |
| 988 | + cur_w = bytestream2_get_be32(gb); | |
| 989 | + cur_h = bytestream2_get_be32(gb); | |
| 990 | + x_offset = bytestream2_get_be32(gb); | |
| 991 | + y_offset = bytestream2_get_be32(gb); | |
| 992 | + bytestream2_skip(gb, 4); /* delay_num (2), delay_den (2) */ | |
| 993 | + dispose_op = bytestream2_get_byte(gb); | |
| 994 | + blend_op = bytestream2_get_byte(gb); | |
| 1007 | 995 | |
| 1008 | 996 | if (sequence_number == 0 && |
| 1009 | 997 | (cur_w != s->width || |
| @@ -1194,6 +1182,8 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, · 184 unmodified lines | ||
| 1194 | 1182 | int i, ret; |
| 1195 | 1183 | |
| 1196 | 1184 | for (;;) { |
| 1185 | + GetByteContext gb_chunk; | |
| 1186 | + | |
| 1197 | 1187 | length = bytestream2_get_bytes_left(&s->gb); |
| 1198 | 1188 | if (length <= 0) { |
| 1199 | 1189 | |
| @@ -1233,8 +1223,7 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, · 33 unmodified lines | ||
| 1233 | 1223 | goto fail; |
| 1234 | 1224 | } |
| 1235 | 1225 | av_log(avctx, AV_LOG_ERROR, ", skipping\n"); |
| 1236 | − bytestream2_skip(&s->gb, 4); /* tag */ | |
| 1237 | − goto skip_tag; | |
| 1226 | + bytestream2_skip(&s->gb, length + 8); /* tag */ | |
| 1238 | 1227 | } |
| 1239 | 1228 | } |
| 1240 | 1229 | tag = bytestream2_get_le32(&s->gb); |
| @@ -1242,6 +1231,9 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, · 1 unmodified line | ||
| 1242 | 1231 | av_log(avctx, AV_LOG_DEBUG, "png: tag=%s length=%u\n", |
| 1243 | 1232 | av_fourcc2str(tag), length); |
| 1244 | 1233 | |
| 1234 | + bytestream2_init(&gb_chunk, s->gb.buffer, length); | |
| 1235 | + bytestream2_skip(&s->gb, length + 4); | |
| 1236 | + | |
| 1245 | 1237 | if (avctx->codec_id == AV_CODEC_ID_PNG && |
| 1246 | 1238 | avctx->skip_frame == AVDISCARD_ALL) { |
| 1247 | 1239 | switch(tag) { |
| @@ -1252,62 +1244,57 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, · 4 unmodified lines | ||
| 1252 | 1244 | case MKTAG('t', 'R', 'N', 'S'): |
| 1253 | 1245 | break; |
| 1254 | 1246 | default: |
| 1255 | − goto skip_tag; | |
| 1247 | + continue; | |
| 1256 | 1248 | } |
| 1257 | 1249 | } |
| 1258 | 1250 | |
| 1259 | 1251 | switch (tag) { |
| 1260 | 1252 | case MKTAG('I', 'H', 'D', 'R'): |
| 1261 | − if ((ret = decode_ihdr_chunk(avctx, s, length)) < 0) | |
| 1253 | + if ((ret = decode_ihdr_chunk(avctx, s, &gb_chunk)) < 0) | |
| 1262 | 1254 | goto fail; |
| 1263 | 1255 | break; |
| 1264 | 1256 | case MKTAG('p', 'H', 'Y', 's'): |
| 1265 | − if ((ret = decode_phys_chunk(avctx, s)) < 0) | |
| 1257 | + if ((ret = decode_phys_chunk(avctx, s, &gb_chunk)) < 0) | |
| 1266 | 1258 | goto fail; |
| 1267 | 1259 | break; |
| 1268 | 1260 | case MKTAG('f', 'c', 'T', 'L'): |
| 1269 | 1261 | if (!CONFIG_APNG_DECODER || avctx->codec_id != AV_CODEC_ID_APNG) |
| 1270 | − goto skip_tag; | |
| 1271 | − if ((ret = decode_fctl_chunk(avctx, s, length)) < 0) | |
| 1262 | + continue; | |
| 1263 | + if ((ret = decode_fctl_chunk(avctx, s, &gb_chunk)) < 0) | |
| 1272 | 1264 | goto fail; |
| 1273 | 1265 | decode_next_dat = 1; |
| 1274 | 1266 | break; |
| 1275 | 1267 | case MKTAG('f', 'd', 'A', 'T'): |
| 1276 | 1268 | if (!CONFIG_APNG_DECODER || avctx->codec_id != AV_CODEC_ID_APNG) |
| 1277 | − goto skip_tag; | |
| 1278 | − if (!decode_next_dat || length < 4) { | |
| 1269 | + continue; | |
| 1270 | + if (!decode_next_dat || bytestream2_get_bytes_left(&gb_chunk) < 4) { | |
| 1279 | 1271 | ret = AVERROR_INVALIDDATA; |
| 1280 | 1272 | goto fail; |
| 1281 | 1273 | } |
| 1282 | − bytestream2_get_be32(&s->gb); | |
| 1283 | − length -= 4; | |
| 1274 | + bytestream2_get_be32(&gb_chunk); | |
| 1284 | 1275 | /* fallthrough */ |
| 1285 | 1276 | case MKTAG('I', 'D', 'A', 'T'): |
| 1286 | 1277 | if (CONFIG_APNG_DECODER && avctx->codec_id == AV_CODEC_ID_APNG && !decode_next_dat) |
| 1287 | − goto skip_tag; | |
| 1288 | − if ((ret = decode_idat_chunk(avctx, s, length, p)) < 0) | |
| 1278 | + continue; | |
| 1279 | + if ((ret = decode_idat_chunk(avctx, s, &gb_chunk, p)) < 0) | |
| 1289 | 1280 | goto fail; |
| 1290 | 1281 | break; |
| 1291 | 1282 | case MKTAG('P', 'L', 'T', 'E'): |
| 1292 | − if (decode_plte_chunk(avctx, s, length) < 0) | |
| 1293 | − goto skip_tag; | |
| 1283 | + decode_plte_chunk(avctx, s, &gb_chunk); | |
| 1294 | 1284 | break; |
| 1295 | 1285 | case MKTAG('t', 'R', 'N', 'S'): |
| 1296 | − if (decode_trns_chunk(avctx, s, length) < 0) | |
| 1297 | − goto skip_tag; | |
| 1286 | + decode_trns_chunk(avctx, s, &gb_chunk); | |
| 1298 | 1287 | break; |
| 1299 | 1288 | case MKTAG('t', 'E', 'X', 't'): |
| 1300 | − if (decode_text_chunk(s, length, 0) < 0) | |
| 1289 | + if (decode_text_chunk(s, &gb_chunk, 0) < 0) | |
| 1301 | 1290 | av_log(avctx, AV_LOG_WARNING, "Broken tEXt chunk\n"); |
| 1302 | − bytestream2_skip(&s->gb, length + 4); | |
| 1303 | 1291 | break; |
| 1304 | 1292 | case MKTAG('z', 'T', 'X', 't'): |
| 1305 | − if (decode_text_chunk(s, length, 1) < 0) | |
| 1293 | + if (decode_text_chunk(s, &gb_chunk, 1) < 0) | |
| 1306 | 1294 | av_log(avctx, AV_LOG_WARNING, "Broken zTXt chunk\n"); |
| 1307 | − bytestream2_skip(&s->gb, length + 4); | |
| 1308 | 1295 | break; |
| 1309 | 1296 | case MKTAG('s', 'T', 'E', 'R'): { |
| 1310 | − int mode = bytestream2_get_byte(&s->gb); | |
| 1297 | + int mode = bytestream2_get_byte(&gb_chunk); | |
| 1311 | 1298 | |
| 1312 | 1299 | if (mode == 0 || mode == 1) { |
| 1313 | 1300 | s->stereo_mode = mode; |
| @@ -1315,33 +1302,31 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, · 1 unmodified line | ||
| 1315 | 1302 | av_log(avctx, AV_LOG_WARNING, |
| 1316 | 1303 | "Unknown value in sTER chunk (%d)\n", mode); |
| 1317 | 1304 | } |
| 1318 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 1319 | 1305 | break; |
| 1320 | 1306 | } |
| 1321 | 1307 | case MKTAG('i', 'C', 'C', 'P'): { |
| 1322 | − if ((ret = decode_iccp_chunk(s, length, p)) < 0) | |
| 1308 | + if ((ret = decode_iccp_chunk(s, &gb_chunk, p)) < 0) | |
| 1323 | 1309 | goto fail; |
| 1324 | 1310 | break; |
| 1325 | 1311 | } |
| 1326 | 1312 | case MKTAG('c', 'H', 'R', 'M'): { |
| 1327 | 1313 | s->have_chrm = 1; |
| 1328 | 1314 | |
| 1329 | − s->white_point[0] = bytestream2_get_be32(&s->gb); | |
| 1330 | − s->white_point[1] = bytestream2_get_be32(&s->gb); | |
| 1315 | + s->white_point[0] = bytestream2_get_be32(&gb_chunk); | |
| 1316 | + s->white_point[1] = bytestream2_get_be32(&gb_chunk); | |
| 1331 | 1317 | |
| 1332 | 1318 | /* RGB Primaries */ |
| 1333 | 1319 | for (i = 0; i < 3; i++) { |
| 1334 | − s->display_primaries[i][0] = bytestream2_get_be32(&s->gb); | |
| 1335 | − s->display_primaries[i][1] = bytestream2_get_be32(&s->gb); | |
| 1320 | + s->display_primaries[i][0] = bytestream2_get_be32(&gb_chunk); | |
| 1321 | + s->display_primaries[i][1] = bytestream2_get_be32(&gb_chunk); | |
| 1336 | 1322 | } |
| 1337 | 1323 | |
| 1338 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 1339 | 1324 | break; |
| 1340 | 1325 | } |
| 1341 | 1326 | case MKTAG('g', 'A', 'M', 'A'): { |
| 1342 | 1327 | AVBPrint bp; |
| 1343 | 1328 | char *gamma_str; |
| 1344 | − int num = bytestream2_get_be32(&s->gb); | |
| 1329 | + int num = bytestream2_get_be32(&gb_chunk); | |
| 1345 | 1330 | |
| 1346 | 1331 | av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); |
| 1347 | 1332 | av_bprintf(&bp, "%i/%i", num, 100000); |
| @@ -1351,7 +1336,6 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, · 3 unmodified lines | ||
| 1351 | 1336 | |
| 1352 | 1337 | av_dict_set(&s->frame_metadata, "gamma", gamma_str, AV_DICT_DONT_STRDUP_VAL); |
| 1353 | 1338 | |
| 1354 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 1355 | 1339 | break; |
| 1356 | 1340 | } |
| 1357 | 1341 | case MKTAG('I', 'E', 'N', 'D'): |
| @@ -1361,13 +1345,7 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, · 3 unmodified lines | ||
| 1361 | 1345 | ret = AVERROR_INVALIDDATA; |
| 1362 | 1346 | goto fail; |
| 1363 | 1347 | } |
| 1364 | − bytestream2_skip(&s->gb, 4); /* crc */ | |
| 1365 | 1348 | goto exit_loop; |
| 1366 | − default: | |
| 1367 | − /* skip tag */ | |
| 1368 | −skip_tag: | |
| 1369 | − bytestream2_skip(&s->gb, length + 4); | |
| 1370 | − break; | |
| 1371 | 1349 | } |
| 1372 | 1350 | } |
| 1373 | 1351 | exit_loop: |