Blame SOURCES/vorbis-tools-1.4.0-CVE-2014-9638-CVE-2014-9639.patch

729e65
From 32c4958c4d113562f879ce76664fe785f93bba7c Mon Sep 17 00:00:00 2001
729e65
From: Kamil Dudka <kdudka@redhat.com>
729e65
Date: Thu, 19 Feb 2015 15:32:24 +0100
729e65
Subject: [PATCH] oggenc: validate count of channels in the header
729e65
729e65
... in order to prevent a division by zero (CVE-2014-9638) and integer
729e65
overflow (CVE-2014-9639).
729e65
729e65
Bug: https://trac.xiph.org/ticket/2136
729e65
Bug: https://trac.xiph.org/ticket/2137
729e65
---
729e65
 oggenc/audio.c | 19 +++++++++++++++++--
729e65
 1 file changed, 17 insertions(+), 2 deletions(-)
729e65
729e65
diff --git a/oggenc/audio.c b/oggenc/audio.c
729e65
index 22bbed4..1cbb214 100644
729e65
--- a/oggenc/audio.c
729e65
+++ b/oggenc/audio.c
729e65
@@ -13,6 +13,7 @@
729e65
 #include <config.h>
729e65
 #endif
729e65
 
729e65
+#include <limits.h>
729e65
 #include <stdlib.h>
729e65
 #include <stdio.h>
729e65
 #include <string.h>
729e65
@@ -251,6 +252,7 @@ int aiff_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen)
729e65
     aiff_fmt format;
729e65
     aifffile *aiff = malloc(sizeof(aifffile));
729e65
     int i;
729e65
+    long channels;
729e65
 
729e65
     if(buf[11]=='C')
729e65
         aifc=1;
729e65
@@ -277,11 +279,17 @@ int aiff_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen)
729e65
         return 0;
729e65
     }
729e65
 
729e65
-    format.channels = READ_U16_BE(buffer);
729e65
+    format.channels = channels = READ_U16_BE(buffer);
729e65
     format.totalframes = READ_U32_BE(buffer+2);
729e65
     format.samplesize = READ_U16_BE(buffer+6);
729e65
     format.rate = (int)read_IEEE80(buffer+8);
729e65
 
729e65
+    if(channels <= 0L || SHRT_MAX < channels)
729e65
+    {
729e65
+        fprintf(stderr, _("Warning: Unsupported count of channels in AIFF header\n"));
729e65
+        return 0;
729e65
+    }
729e65
+
729e65
     aiff->bigendian = 1;
729e65
 
729e65
     if(aifc)
729e65
@@ -412,6 +420,7 @@ int wav_open(FILE *in, oe_enc_opt *opt, unsigned char *oldbuf, int buflen)
729e65
     wav_fmt format;
729e65
     wavfile *wav = malloc(sizeof(wavfile));
729e65
     int i;
729e65
+    long channels;
729e65
 
729e65
     /* Ok. At this point, we know we have a WAV file. Now we have to detect
729e65
      * whether we support the subtype, and we have to find the actual data
729e65
@@ -449,12 +458,18 @@ int wav_open(FILE *in, oe_enc_opt *opt, unsigned char *oldbuf, int buflen)
729e65
     }
729e65
 
729e65
     format.format =      READ_U16_LE(buf);
729e65
-    format.channels =    READ_U16_LE(buf+2);
729e65
+    format.channels = channels = READ_U16_LE(buf+2);
729e65
     format.samplerate =  READ_U32_LE(buf+4);
729e65
     format.bytespersec = READ_U32_LE(buf+8);
729e65
     format.align =       READ_U16_LE(buf+12);
729e65
     format.samplesize =  READ_U16_LE(buf+14);
729e65
 
729e65
+    if(channels <= 0L || SHRT_MAX < channels)
729e65
+    {
729e65
+        fprintf(stderr, _("Warning: Unsupported count of channels in WAV header\n"));
729e65
+        return 0;
729e65
+    }
729e65
+
729e65
     if(format.format == -2) /* WAVE_FORMAT_EXTENSIBLE */
729e65
     {
729e65
       if(len<40)
729e65
-- 
729e65
2.1.0
729e65