Fixes reading WAV files with odd-sized ID3v2 headers.

CC:[email protected]
---
 libavformat/wavdec.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index f65a66a..65d763f 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -39,6 +39,7 @@
 #include "riff.h"
 
 typedef struct WAVDemuxContext {
+    int64_t riff_start;
     int64_t data_end;
     int w64;
 } WAVDemuxContext;
@@ -52,13 +53,14 @@ static int64_t next_tag(AVIOContext *pb, uint32_t *tag)
 }
 
 /* RIFF chunks are always on a even offset. */
-static int64_t wav_seek_tag(AVIOContext *s, int64_t offset, int whence)
+static int64_t wav_seek_tag(WAVDemuxContext *wav, AVIOContext *s,
+                            int64_t offset, int whence)
 {
-    return avio_seek(s, offset + (offset & 1), whence);
+    return avio_seek(s, offset + ((offset - wav->riff_start) & 1), whence);
 }
 
 /* return the size of the found tag */
-static int64_t find_tag(AVIOContext *pb, uint32_t tag1)
+static int64_t find_tag(WAVDemuxContext *wav, AVIOContext *pb, uint32_t tag1)
 {
     unsigned int tag;
     int64_t size;
@@ -69,7 +71,7 @@ static int64_t find_tag(AVIOContext *pb, uint32_t tag1)
         size = next_tag(pb, &tag);
         if (tag == tag1)
             break;
-        wav_seek_tag(pb, size, SEEK_CUR);
+        wav_seek_tag(wav, pb, size, SEEK_CUR);
     }
     return size;
 }
@@ -222,6 +224,8 @@ static int wav_read_header(AVFormatContext *s)
     int ret, got_fmt = 0;
     int64_t next_tag_ofs, data_ofs = -1;
 
+    wav->riff_start = avio_tell(pb);
+
     /* check RIFF header */
     tag = avio_rl32(pb);
 
@@ -315,7 +319,7 @@ static int wav_read_header(AVFormatContext *s)
 
         /* seek to next tag unless we know that we'll run into EOF */
         if ((avio_size(pb) > 0 && next_tag_ofs >= avio_size(pb)) ||
-            wav_seek_tag(pb, next_tag_ofs, SEEK_SET) < 0) {
+            wav_seek_tag(wav, pb, next_tag_ofs, SEEK_SET) < 0) {
             break;
         }
     }
@@ -384,7 +388,7 @@ static int wav_read_packet(AVFormatContext *s, AVPacket 
*pkt)
         if (CONFIG_W64_DEMUXER && wav->w64)
             left = find_guid(s->pb, guid_data) - 24;
         else
-            left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a'));
+            left = find_tag(wav, s->pb, MKTAG('d', 'a', 't', 'a'));
         if (left < 0)
             return AVERROR_EOF;
         wav->data_end = avio_tell(s->pb) + left;
-- 
2.0.0

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to