wavdec: fix duration calculation for files with invalid data size
authorJames Almer <jamrial@gmail.com>
Thu, 27 Dec 2012 22:30:40 +0000 (19:30 -0300)
committerPaul B Mahol <onemda@gmail.com>
Sat, 29 Dec 2012 17:46:01 +0000 (17:46 +0000)
Some wav files report a data size that is bigger than the actual file size.
Fall back to estimation from bitrate in such cases.

Fixes ticket #2065.

Signed-off-by: James Almer <jamrial@gmail.com>
libavformat/wavdec.c

index 62bf263..9d09865 100644 (file)
@@ -365,7 +365,7 @@ break_loop:
 
     avio_seek(pb, data_ofs, SEEK_SET);
 
-    if (!sample_count && st->codec->channels && av_get_bits_per_sample(st->codec->codec_id))
+    if (!sample_count && st->codec->channels && av_get_bits_per_sample(st->codec->codec_id) && wav->data_end <= avio_size(pb))
         sample_count = (data_size<<3) / (st->codec->channels * (uint64_t)av_get_bits_per_sample(st->codec->codec_id));
     if (sample_count)
         st->duration = sample_count;