Commit bdc39225 authored by Tristan Matthews's avatar Tristan Matthews

wav_io: check for EOF when seeking in wav

Fixes hang discovered by fuzzing: https://github.com/xiph/speex/issues/9
parent 0c021215
......@@ -75,8 +75,11 @@ int read_wav_header(FILE *file, int *rate, int *channels, int *format, spx_int32
itmp = le_int(itmp);
/*fprintf (stderr, "skip=%d\n", itmp);*/
/*strange way of seeking, but it works even for pipes*/
for (i=0;i<itmp;i++)
fgetc(file);
for (i=0;i<itmp;i++) {
if (fgetc(file) == EOF) {
break;
}
}
/*fseek(file, itmp, SEEK_CUR);*/
fread(ch, 1, 4, file);
if (feof(file))
......@@ -152,9 +155,13 @@ int read_wav_header(FILE *file, int *rate, int *channels, int *format, spx_int32
/*strange way of seeking, but it works even for pipes*/
if (skip_bytes>0)
for (i=0;i<skip_bytes;i++)
fgetc(file);
if (skip_bytes>0) {
for (i=0;i<skip_bytes;i++) {
if (fgetc(file) == EOF) {
break;
}
}
}
/*fseek(file, skip_bytes, SEEK_CUR);*/
......@@ -164,8 +171,11 @@ int read_wav_header(FILE *file, int *rate, int *channels, int *format, spx_int32
fread(&itmp, 4, 1, file);
itmp = le_int(itmp);
/*strange way of seeking, but it works even for pipes*/
for (i=0;i<itmp;i++)
fgetc(file);
for (i=0;i<itmp;i++) {
if (fgetc(file) == EOF) {
break;
}
}
/*fseek(file, itmp, SEEK_CUR);*/
fread(ch, 1, 4, file);
if (feof(file))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment