shithub: opus-tools

Download patch

ref: 4a703f083e6230bd544d959babaa2995c0adb45d
parent: 3c2f4a8ecaf00274858fbd40e9f94cf77c0c681a
author: Mark Harris <mark.hsj@gmail.com>
date: Wed Sep 30 21:32:06 EDT 2015

opusenc: Sanitize WAV/AIFF fourccs

Don't print control characters and other invalid bytes from invalid
WAV/AIFF fourccs to the terminal.

--- a/src/audio-in.c
+++ b/src/audio-in.c
@@ -158,6 +158,14 @@
     return NULL;
 }
 
+static void sanitize_fourcc(unsigned char *buf)
+{
+    int i;
+    for(i = 0; i < 4; ++i)
+        if(buf[i] < ' ' || buf[i] > '~')
+            buf[i] = '?';
+}
+
 static int seek_forward(FILE *in, ogg_int64_t length)
 {
     ogg_int64_t remaining = length;
@@ -202,8 +210,8 @@
 
         if(memcmp(buf, type, 4))
         {
-            buf[4] = 0;
-            fprintf(stderr, _("Skipping chunk of type \"%s\", length %u\n"),
+            sanitize_fourcc(buf);
+            fprintf(stderr, _("Skipping chunk of type \"%.4s\", length %u\n"),
                 buf, chunklen);
 
             if(!seek_forward(in, (ogg_int64_t)chunklen + (chunklen & 1)))
@@ -389,7 +397,9 @@
         }
         else
         {
-            fprintf(stderr, _("Warning: Can't handle compressed AIFF-C (%c%c%c%c)\n"), *(buffer+18), *(buffer+19), *(buffer+20), *(buffer+21));
+            sanitize_fourcc(buffer+18);
+            fprintf(stderr, _("ERROR: Can't handle compressed AIFF-C \"%.4s\"\n"),
+                buffer+18);
             return 0; /* Compressed. Can't handle */
         }
     }