shithub: sox

Download patch

ref: 56a5fc5e840fab4ad6a8d3381b8a7c087efee9f5
parent: 4927023d0978615c74e8a511ce981cf4c29031f1
author: Chris Bagwell <chris@cnpbagwell.com>
date: Sun Oct 5 18:04:51 EDT 2014

Fix for max size text chunks in aiff files.

Stop size rolling over to size zero.

--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,7 @@
 File formats:
 
   o Add optional support for reading Ogg Opus files. (John Stumpo)
+  o Fix for max size text chunks in aiff files. (cbagwell)
 
 Effects:
 
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -459,24 +459,32 @@
 {
   uint32_t chunksize;
   lsx_readdw(ft, &chunksize);
+
   /* allocate enough memory to hold the text including a terminating \0 */
-  *text = lsx_malloc((size_t) chunksize + 1);
+  if (chunksize != SOX_SIZE_MAX)
+    *text = lsx_malloc((size_t)chunksize+1);
+  else
+    *text = lsx_malloc((size_t)chunksize);
+
   if (lsx_readbuf(ft, *text, (size_t) chunksize) != chunksize)
   {
     lsx_fail_errno(ft,SOX_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
     return(SOX_EOF);
   }
-  *(*text + chunksize) = '\0';
-        if (chunksize % 2)
-        {
-                /* Read past pad byte */
-                char c;
-                if (lsx_readbuf(ft, &c, (size_t)1) != 1)
-                {
-                lsx_fail_errno(ft,SOX_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
-                        return(SOX_EOF);
-                }
-        }
+  if (chunksize != SOX_SIZE_MAX)
+    *(*text + chunksize) = '\0';
+  else
+    *(*text + chunksize-1) = '\0';
+  if (chunksize % 2)
+  {
+    /* Read past pad byte */
+    char c;
+    if (lsx_readbuf(ft, &c, (size_t)1) != 1)
+    {
+      lsx_fail_errno(ft,SOX_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
+      return(SOX_EOF);
+    }
+  }
   lsx_debug("%-10s   \"%s\"", chunkDescription, *text);
   return(SOX_SUCCESS);
 }