[FFmpeg-cvslog] avformat/wavdec: w64: do not error out for broken files if data start is found

Paul B Mahol git at videolan.org
Sat Oct 7 12:21:26 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sat Oct  7 10:53:10 2023 +0200| [71716406e68a1f139717c5025e49f648e3666b0e] | committer: Paul B Mahol

avformat/wavdec: w64: do not error out for broken files if data start is found

Also attempt to fix invalid block_align value.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=71716406e68a1f139717c5025e49f648e3666b0e
---

 libavformat/wavdec.c | 18 ++++++++++++++++--
 1 file 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;



More information about the ffmpeg-cvslog mailing list