diff options
author | Paul B Mahol <onemda@gmail.com> | 2023-10-07 10:53:10 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2023-10-07 11:19:54 +0200 |
commit | 71716406e68a1f139717c5025e49f648e3666b0e (patch) | |
tree | 28b60360dab055ab9848cdbf3b20becf2941cc02 /libavformat/wavdec.c | |
parent | 84e0e2f43e424c8a9ae0d18711f204ffebd961ba (diff) | |
download | ffmpeg-71716406e68a1f139717c5025e49f648e3666b0e.tar.gz |
avformat/wavdec: w64: do not error out for broken files if data start is found
Also attempt to fix invalid block_align value.
Diffstat (limited to 'libavformat/wavdec.c')
-rw-r--r-- | libavformat/wavdec.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index 97e69ab2ee..2814466897 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -885,8 +885,11 @@ static int w64_read_header(AVFormatContext *s) if (avio_read(pb, guid, 16) != 16) break; size = avio_rl64(pb); - if (size <= 24 || INT64_MAX - size < avio_tell(pb)) + if (size <= 24 || INT64_MAX - size < avio_tell(pb)) { + if (data_ofs) + break; return AVERROR_INVALIDDATA; + } if (!memcmp(guid, ff_w64_guid_fmt, 16)) { /* subtract chunk header size - normal wav file doesn't count it */ @@ -894,7 +897,18 @@ static int w64_read_header(AVFormatContext *s) if (ret < 0) return ret; avio_skip(pb, FFALIGN(size, INT64_C(8)) - size); - + if (st->codecpar->block_align) { + int block_align = st->codecpar->block_align; + + block_align = FFMAX(block_align, + ((st->codecpar->bits_per_coded_sample + 7) / 8) * + st->codecpar->ch_layout.nb_channels); + if (block_align > st->codecpar->block_align) { + av_log(s, AV_LOG_WARNING, "invalid block_align: %d, broken file.\n", + st->codecpar->block_align); + st->codecpar->block_align = block_align; + } + } avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); } else if (!memcmp(guid, ff_w64_guid_fact, 16)) { int64_t samples; |