Skip to content

Commit

Permalink
issue #33, sanitize size of unknown chunks before malloc()
Browse files Browse the repository at this point in the history
  • Loading branch information
dbry committed Apr 25, 2018
1 parent 0a72951 commit 6f8bb34
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion cli/dsdiff.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,14 @@ int ParseDsdiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpa
else { // just copy unknown chunks to output file

int bytes_to_copy = (int)(((dff_chunk_header.ckDataSize) + 1) & ~(int64_t)1);
char *buff = malloc (bytes_to_copy);
char *buff;

if (bytes_to_copy < 0 || bytes_to_copy > 4194304) {
error_line ("%s is not a valid .DFF file!", infilename);
return WAVPACK_SOFT_ERROR;
}

buff = malloc (bytes_to_copy);

if (debug_logging_mode)
error_line ("extra unknown chunk \"%c%c%c%c\" of %d bytes",
Expand Down
9 changes: 8 additions & 1 deletion cli/riff.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,14 @@ int ParseRiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpack
else { // just copy unknown chunks to output file

int bytes_to_copy = (chunk_header.ckSize + 1) & ~1L;
char *buff = malloc (bytes_to_copy);
char *buff;

if (bytes_to_copy < 0 || bytes_to_copy > 4194304) {
error_line ("%s is not a valid .WAV file!", infilename);
return WAVPACK_SOFT_ERROR;
}

buff = malloc (bytes_to_copy);

if (debug_logging_mode)
error_line ("extra unknown chunk \"%c%c%c%c\" of %d bytes",
Expand Down
9 changes: 8 additions & 1 deletion cli/wave64.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,14 @@ int ParseWave64HeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpa
}
else { // just copy unknown chunks to output file
int bytes_to_copy = (chunk_header.ckSize + 7) & ~7L;
char *buff = malloc (bytes_to_copy);
char *buff;

if (bytes_to_copy < 0 || bytes_to_copy > 4194304) {
error_line ("%s is not a valid .W64 file!", infilename);
return WAVPACK_SOFT_ERROR;
}

buff = malloc (bytes_to_copy);

if (debug_logging_mode)
error_line ("extra unknown chunk \"%c%c%c%c\" of %d bytes",
Expand Down

0 comments on commit 6f8bb34

Please sign in to comment.