Skip to content

Commit d04aa42

Browse files
committed
prevent buffer overflow on invalid format chunk sizes. Really fix MestreLion#5
1 parent 431c97a commit d04aa42

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

audio.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,18 @@ int wav_open(FILE *in, wavegain_opt *opt,
672672
* (40 bytes accommodates WAVEFORMATEXTENSIBLE conforming files.)
673673
*/
674674
if (len != 16 && len != 18 && len != 40)
675-
fprintf(stderr, "Warning: INVALID format chunk in wav header.\n"
675+
fprintf(stderr, "Warning: INVALID format chunk in WAV header.\n"
676676
" Trying to read anyway (may not work)...\n");
677677

678+
/* Prevent buffer overflow in invalid / malicious files
679+
*/
680+
if (len > sizeof(buf)) {
681+
fprintf(stderr, "Warning: format chunk size (%lld) in WAV header"
682+
" is larger than permitted (%d).\n",
683+
len, sizeof(buf));
684+
len = sizeof(buf);
685+
}
686+
678687
/* Deal with stupid broken apps. Don't use these programs.
679688
*/
680689

0 commit comments

Comments
 (0)