[FFmpeg-devel] [PATCH]Decode some invalid wav files

Daniel Verkamp daniel
Wed Feb 3 11:34:43 CET 2010


On Mon, Feb 1, 2010 at 7:15 PM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
> Daniel Verkamp <daniel <at> drv.nu> writes:
>
>> This doesn't look right - data_size is only set in the rf64 case (read
>> from a special rf64-only header), so it is some random value at this
>> point for a non-rf64 file. ?This probably works by accident (on my
>> system, it currently happens to get initialized to a large positive
>> value).
>
> Thanks for having a look and explaining.
>
> How can wav->data_end be set correctly?
>
> Carl Eugen
>

Something like the attached looks like it should work (tested with -f
framecrc, results match for broken file and correct one).  This just
assumes the data chunk runs until the end of the file if the size is
not valid. In theory this breaks actual 0-length files with more
chunks after the data chunk, but I doubt it should matter in practice.

Thanks,
-- Daniel Verkamp
-------------- next part --------------
>From 0b94931fab41318e3e2b3309a820acaede5eba81 Mon Sep 17 00:00:00 2001
From: Daniel Verkamp <daniel at drv.nu>
Date: Wed, 3 Feb 2010 05:24:24 -0500
Subject: [PATCH] Demux WAV files with data chunk size = 0

---
 libavformat/wav.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/libavformat/wav.c b/libavformat/wav.c
index f4b2d61..0b108f1 100644
--- a/libavformat/wav.c
+++ b/libavformat/wav.c
@@ -227,6 +227,7 @@ static int wav_read_header(AVFormatContext *s,
         size = data_size;
     if (size < 0)
         return -1;
+    else if (size > 0)
     wav->data_end= url_ftell(pb) + size;
     return 0;
 }
@@ -267,7 +268,7 @@ static int wav_read_packet(AVFormatContext *s,
     st = s->streams[0];
 
     left = wav->data_end - url_ftell(s->pb);
-    if (left <= 0){
+    if (wav->data_end && left <= 0){
         if (CONFIG_W64_DEMUXER && wav->w64)
             left = find_guid(s->pb, guid_data) - 24;
         else
@@ -283,6 +284,7 @@ static int wav_read_packet(AVFormatContext *s,
             size = st->codec->block_align;
         size = (size / st->codec->block_align) * st->codec->block_align;
     }
+    if (wav->data_end)
     size = FFMIN(size, left);
     ret  = av_get_packet(s->pb, pkt, size);
     if (ret < 0)
@@ -391,6 +393,7 @@ static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap)
         av_log(s, AV_LOG_ERROR, "could not find data guid\n");
         return -1;
     }
+    else if (size > 0)
     wav->data_end = url_ftell(pb) + size - 24;
     wav->w64      = 1;
 
-- 
1.6.6.rc3



More information about the ffmpeg-devel mailing list