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

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