flacdec: be less strict when parsing attached pictures.

Only return an error if memory allocation fails or error recognition is
set to explode. Otherwise just print an error message and continue
reading the file.
This commit is contained in:
Anton Khirnov 2012-07-06 22:30:17 +02:00
parent dba5b06ead
commit b7d3a9a015
1 changed files with 18 additions and 7 deletions

View File

@ -46,9 +46,12 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
type = avio_rb32(pb); type = avio_rb32(pb);
if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) { if (type >= FF_ARRAY_ELEMS(ff_id3v2_picture_types) || type < 0) {
av_log(s, AV_LOG_ERROR, "Invalid picture type: %d.\n", type); av_log(s, AV_LOG_ERROR, "Invalid picture type: %d.\n", type);
if (s->error_recognition & AV_EF_EXPLODE) {
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
type = 0;
}
/* picture mimetype */ /* picture mimetype */
len = avio_rb32(pb); len = avio_rb32(pb);
@ -56,6 +59,7 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
avio_read(pb, mimetype, FFMIN(len, sizeof(mimetype) - 1)) != len) { avio_read(pb, mimetype, FFMIN(len, sizeof(mimetype) - 1)) != len) {
av_log(s, AV_LOG_ERROR, "Could not read mimetype from an attached " av_log(s, AV_LOG_ERROR, "Could not read mimetype from an attached "
"picture.\n"); "picture.\n");
if (s->error_recognition & AV_EF_EXPLODE)
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
@ -71,6 +75,7 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
if (id == CODEC_ID_NONE) { if (id == CODEC_ID_NONE) {
av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n", av_log(s, AV_LOG_ERROR, "Unknown attached picture mimetype: %s.\n",
mimetype); mimetype);
if (s->error_recognition & AV_EF_EXPLODE)
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
@ -84,6 +89,8 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
} }
if (avio_read(pb, desc, len) != len) { if (avio_read(pb, desc, len) != len) {
av_log(s, AV_LOG_ERROR, "Error reading attached picture description.\n");
if (s->error_recognition & AV_EF_EXPLODE)
ret = AVERROR(EIO); ret = AVERROR(EIO);
goto fail; goto fail;
} }
@ -98,6 +105,8 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
/* picture data */ /* picture data */
len = avio_rb32(pb); len = avio_rb32(pb);
if (len <= 0) { if (len <= 0) {
av_log(s, AV_LOG_ERROR, "Invalid attached picture size: %d.\n", len);
if (s->error_recognition & AV_EF_EXPLODE)
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto fail; goto fail;
} }
@ -106,6 +115,8 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
goto fail; goto fail;
} }
if (avio_read(pb, data, len) != len) { if (avio_read(pb, data, len) != len) {
av_log(s, AV_LOG_ERROR, "Error reading attached picture data.\n");
if (s->error_recognition & AV_EF_EXPLODE)
ret = AVERROR(EIO); ret = AVERROR(EIO);
goto fail; goto fail;
} }