From fa5d8add56f38a464e156e98e0c23e4f2cc4b9c5 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Wed, 21 Sep 2016 15:24:06 +0200 Subject: [PATCH] src/io/source_wavread.c: skip chunks until data is found, or abort --- src/io/source_wavread.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/io/source_wavread.c b/src/io/source_wavread.c index f63447c2..ea07641d 100644 --- a/src/io/source_wavread.c +++ b/src/io/source_wavread.c @@ -229,9 +229,23 @@ aubio_source_wavread_t * new_aubio_source_wavread(const char_t * path, uint_t sa // Subchunk2ID bytes_read += fread(buf, 1, 4, s->fid); buf[4] = '\0'; - if ( strcmp((const char *)buf, "data") != 0 ) { - AUBIO_ERR("source_wavread: data RIFF header not found in %s\n", s->path); - goto beach; + while ( strcmp((const char *)buf, "data") != 0 ) { + if (feof(s->fid) || ferror(s->fid)) { + AUBIO_ERR("source_wavread: no data RIFF header found in %s\n", s->path); + goto beach; + } + bytes_junk = fread(buf, 1, 4, s->fid); + buf[4] = '\0'; + bytes_junk += read_little_endian(buf, 4); + if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) { + AUBIO_ERR("source_wavread: could not seek past unknown chunk in %s (%s)\n", + s->path, strerror(errno)); + goto beach; + } + bytes_read += bytes_junk; + bytes_expected += bytes_junk+ 4; + bytes_read += fread(buf, 1, 4, s->fid); + buf[4] = '\0'; } // Subchunk2Size -- 2.11.0