shithub: sox

Download patch

ref: f3194c05dc66be967185e001a88f15d7268b0b91
parent: 4ff0d0961058d4aeade3be03d30129f0d8684612
author: cbagwell <cbagwell>
date: Tue Oct 18 20:38:40 EDT 2005

Fix for non-padded wav files from looking up sox.

--- a/Changelog
+++ b/Changelog
@@ -38,6 +38,8 @@
     to help simplify developer interface to libst.  See libst.3..
   o Force word-alignment on AIFF SSND and APPL chunks on input.
     Matthew Hodgson.
+  o Add fix to WAV handler to only return data in multiples
+    of sample_size*channels to better handle corrupt files.
 
 sox-12.17.8
 -----------
--- a/TODO
+++ b/TODO
@@ -1,6 +1,11 @@
 People are encouraged to pick some of these and implement it.  Send
 all patches to cbagwell@users.sourceforge.net.
 
+  o Update all read routines to be like WAV handler and only
+    return data in multiples of sample_size*channels.  This
+    will prevent corrupt files from causing sox to go into
+    infinit loop trying to read just a couple more bytes.
+
   o Make "mix" an alias of "avg" since thats closer to what it
     really is.  For 2->2 mixes, make a 2 option L->L and R->R
     shortcut.  Similar 4 option for 4->4.
--- a/sox.1
+++ b/sox.1
@@ -153,7 +153,7 @@
 the audio sample data type and apply one or more
 sound effects to the file during this translation.  
 .P
-If more then one input file is specified then they are concatenated into the
+If more than one input file is specified then they are concatenated into the
 output file.  In this case, it has a restriction that all input files
 must be of the same data type and sample rates.
 .P
--- a/src/wav.c
+++ b/src/wav.c
@@ -1147,7 +1147,14 @@
                 st_warn("Premature EOF on .wav input file");
         }
 
-        wav->numSamples -= (done/ft->info.channels);
+        /* Only return buffers that contain a totally playable
+         * amount of audio.
+         */
+        done -= (done % (ft->info.channels * ft->info.size));
+        if (done/ft->info.channels > wav->numSamples)
+            wav->numSamples = 0;
+        else
+            wav->numSamples -= (done/ft->info.channels);
         return done;
 }