History

lavc/pngdec: use a separate bytestream reader for each chunk

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.

Anton Khirnov committed 5 years ago

Commit 19e81031 parent ae08eec1 file · +72 −94Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t