ref: fa5d8add56f38a464e156e98e0c23e4f2cc4b9c5
parent: a27576bb97a9ff602034d784cb502c4dc065ac36
author: Paul Brossier <piem@piem.org>
date: Wed Sep 21 11:24:06 EDT 2016
src/io/source_wavread.c: skip chunks until data is found, or abort
--- a/src/io/source_wavread.c
+++ b/src/io/source_wavread.c
@@ -229,9 +229,23 @@
// 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