From: Paul Brossier Date: Wed, 21 Sep 2016 13:24:06 +0000 (+0200) Subject: src/io/source_wavread.c: skip chunks until data is found, or abort X-Git-Tag: 0.4.4~216 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=fa5d8add56f38a464e156e98e0c23e4f2cc4b9c5;p=aubio.git src/io/source_wavread.c: skip chunks until data is found, or abort --- 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