History

pngdec: add ability to check chunk CRC

By default now, if AV_EF_CRCCHECK or AV_EF_IGNORE_ERR are enabled the decoder will skip the chunk and carry on with the next one. This should make the decoder able to decode more corrupt files because the functions which decode individual chunks will very likely error out if fed invalid data and stop the decoding of the entire image.

Lynne committed 7 years ago

Commit b8d9bc21 parent e69f4071 file · +17 −0Browse files

Unified · Split

libavcodec/pngdec.c+17−0
@@ -23,6 +23,7 @@ · 22 unmodified lines
23 23
24#include "libavutil/avassert.h"24#include "libavutil/avassert.h"
25#include "libavutil/bprint.h"25#include "libavutil/bprint.h"
26#include "libavutil/crc.h"
26#include "libavutil/imgutils.h"27#include "libavutil/imgutils.h"
27#include "libavutil/intreadwrite.h"28#include "libavutil/intreadwrite.h"
28#include "libavutil/stereo3d.h"29#include "libavutil/stereo3d.h"
@@ -1179,6 +1180,7 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, · 1150 unmodified lines
1179static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,1180static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s,
1180 AVFrame *p, AVPacket *avpkt)1181 AVFrame *p, AVPacket *avpkt)
1181{1182{
1183 const AVCRC *crc_tab = av_crc_get_table(AV_CRC_32_IEEE_LE);
1182 AVDictionary **metadatap = NULL;1184 AVDictionary **metadatap = NULL;
1183 uint32_t tag, length;1185 uint32_t tag, length;
1184 int decode_next_dat = 0;1186 int decode_next_dat = 0;
@@ -1213,6 +1215,21 @@ static int decode_frame_common(AVCodecContext *avctx, PNGDecContext *s, · 28 unmodified lines
1213 ret = AVERROR_INVALIDDATA;1215 ret = AVERROR_INVALIDDATA;
1214 goto fail;1216 goto fail;
1215 }1217 }
1218 if (avctx->err_recognition & (AV_EF_CRCCHECK | AV_EF_IGNORE_ERR)) {
1219 uint32_t crc_sig = AV_RB32(s->gb.buffer + length + 4);
1220 uint32_t crc_cal = ~av_crc(crc_tab, UINT32_MAX, s->gb.buffer, length + 4);
1221 if (crc_sig ^ crc_cal) {
1222 av_log(avctx, AV_LOG_ERROR, "CRC mismatch in chunk");
1223 if (avctx->err_recognition & AV_EF_EXPLODE) {
1224 av_log(avctx, AV_LOG_ERROR, ", quitting\n");
1225 ret = AVERROR_INVALIDDATA;
1226 goto fail;
1227 }
1228 av_log(avctx, AV_LOG_ERROR, ", skipping\n");
1229 bytestream2_skip(&s->gb, 4); /* tag */
1230 goto skip_tag;
1231 }
1232 }
1216 tag = bytestream2_get_le32(&s->gb);1233 tag = bytestream2_get_le32(&s->gb);
1217 if (avctx->debug & FF_DEBUG_STARTCODE)1234 if (avctx->debug & FF_DEBUG_STARTCODE)
1218 av_log(avctx, AV_LOG_DEBUG, "png: tag=%s length=%u\n",1235 av_log(avctx, AV_LOG_DEBUG, "png: tag=%s length=%u\n",

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