shithub: opus-tools

Download patch

ref: 7738aa7096620caca74bf4ce54823b970d1969e6
parent: f6963f289a4644bc11ab68934b9ce2df870a8516
author: Gregory Maxwell <greg@xiph.org>
date: Mon Dec 1 08:12:47 EST 2014

Opusdec doesn't handle chaining that changes the channel count. Exit in that case.

Also handle malloc failure in a few more cases.

--- a/src/lpc.c
+++ b/src/lpc.c
@@ -65,6 +65,8 @@
   double epsilon;
   int i,j;
 
+  if(!aut || !lpc)return 0;
+
   /* autocorrelation, p+1 lag coefficients */
   j=m+1;
   while(j--){
@@ -141,6 +143,8 @@
   long i,j,o,p;
   float y;
   float *work=malloc(sizeof(*work)*(m+n));
+
+  if(!work)return;
 
   if(!prime)
     for(i=0;i<m;i++)
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -908,10 +908,19 @@
             /*If first packet in a logical stream, process the Opus header*/
             if (packet_count==0)
             {
+               int old_channels = channels;
                st = process_header(&op, &rate, &mapping_family, &channels, &preskip, &gain, manual_gain, &streams, wav_format, quiet);
                if (!st)
                   quit(1);
 
+               if (output && channels!=old_channels)
+               {
+                   fprintf(stderr,"\nError: Apparent chaining changes channel count from %d to %d.\n",
+                     old_channels,channels);
+                   fprintf(stderr,"This is currently unhandled by opusdec.\n");
+                   quit(1);
+               }
+
                if(ogg_stream_packetout(&os, &op)!=0 || og.header[og.header_len-1]==255)
                {
                   /*The format specifies that the initial header and tags packets are on their
@@ -934,6 +943,11 @@
                   shapemem.fs=rate;
                }
                if(!output)output=malloc(sizeof(float)*MAX_FRAME_SIZE*channels);
+               if(!shapemem.a_buf||!shapemem.b_buf||!output)
+               {
+                  fprintf(stderr, "Memory allocation failure.\n");
+                  quit(1);
+               }
 
                /*Normal players should just play at 48000 or their maximum rate,
                  as described in the OggOpus spec.  But for commandline tools
@@ -1051,6 +1065,11 @@
             int drain;
 
             zeros=(float *)calloc(100*channels,sizeof(float));
+            if(!zeros)
+            {
+                fprintf(stderr, "Memory allocation failure.\n");
+                quit(1);
+            }
             drain = speex_resampler_get_input_latency(resampler);
             do {
                opus_int64 outsamp;
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -516,6 +516,11 @@
           }
           if(opt_ctls==0)opt_ctls_ctlval=malloc(sizeof(int)*3);
           else opt_ctls_ctlval=realloc(opt_ctls_ctlval,sizeof(int)*(opt_ctls+1)*3);
+          if(!opt_ctls_ctlval)
+          {
+            fprintf(stderr, "Memory allocation failure.\n");
+            exit(1);
+          }
           opt_ctls_ctlval[opt_ctls*3]=target;
           opt_ctls_ctlval[opt_ctls*3+1]=atoi(tpos+1);
           opt_ctls_ctlval[opt_ctls*3+2]=atoi(spos+1);