Skip to content

Commit a8ab5b3

Browse files
committed
src/wav_w64.c : Fix heap write overflow.
Heap write could occur if the number of channels is less than the length of the file's channel map. Found using the afl (http://lcamtuf.coredump.cx/afl/) fuzzer.
1 parent e67d42d commit a8ab5b3

File tree

Image for: File tree

1 file changed

Image for: 1 file changed
+6
-4
lines changed

1 file changed

Image for: 1 file changed
+6
-4
lines changed

‎src/wav_w64.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** Copyright (C) 1999-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
2+
** Copyright (C) 1999-2014 Erik de Castro Lopo <erikd@mega-nerd.com>
33
** Copyright (C) 2004-2005 David Viens <davidv@plogue.com>
44
**
55
** This program is free software; you can redistribute it and/or modify
@@ -324,7 +324,7 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, int fmtsize)
324324
/* Terminate the buffer we're going to append_snprintf into. */
325325
buffer [0] = 0 ;
326326

327-
for (bit = k = 0 ; bit < ARRAY_LEN (channel_mask_bits) ; bit++)
327+
for (bit = k = 0 ; bit < ARRAY_LEN (channel_mask_bits) && k < psf->sf.channels ; bit++)
328328
{
329329
if (wav_fmt->ext.channelmask & (1 << bit))
330330
{ if (k > psf->sf.channels)
@@ -339,8 +339,10 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, int fmtsize)
339339

340340
/* Remove trailing ", ". */
341341
bit = strlen (buffer) ;
342-
buffer [--bit] = 0 ;
343-
buffer [--bit] = 0 ;
342+
if (bit >= 2)
343+
{ buffer [--bit] = 0 ;
344+
buffer [--bit] = 0 ;
345+
} ;
344346

345347
if (k != psf->sf.channels)
346348
{ psf_log_printf (psf, " Channel Mask : 0x%X\n", wav_fmt->ext.channelmask) ;

0 commit comments

Image for: 0 commit comments
Comments
 (0)