Skip to content

Commit

Permalink
wav_io: check for EOF when seeking in wav
Browse files Browse the repository at this point in the history
Fixes hang discovered by fuzzing: #9
  • Loading branch information
tmatth committed Sep 11, 2018
1 parent 243470f commit 0aaf169
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/wav_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);*/

Expand Down

0 comments on commit 0aaf169

Please sign in to comment.