shithub: opus-tools

Download patch

ref: d8e1592db3ecd720e3c7891ed222e07bfbd3c322
parent: b7bd409c5074bf8a2572da1ff9a0f4f49388cd6c
author: Gregory Maxwell <greg@xiph.org>
date: Tue May 29 10:58:30 EDT 2012

Fix for the infinite loop on preskip>samples found by Tim.

This creates a hard failure in cases that would have been
a silent failure before which might have been hiding other
bugs, so it needs testing.

Also adds so paranoia to avoid infinite loops, even if the
caller of audio_write is stupid.

--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -459,7 +459,7 @@
    short out[MAX_FRAME_SIZE*channels];
    float buf[MAX_FRAME_SIZE*channels];
    float *output;
-
+   maxout=maxout<0?0:maxout;
    do {
      if (skip){
        tmp_skip = (*skip>frame_size) ? (int)frame_size : *skip;
@@ -744,6 +744,7 @@
                if (!quiet)
                   print_comments((char*)op.packet, op.bytes);
             } else {
+               opus_int64 maxout;
                int lost=0;
                if (loss_percent>0 && 100*((float)rand())/RAND_MAX<loss_percent)
                   lost=1;
@@ -787,7 +788,13 @@
                   fputc (ch, stderr);
                   fprintf (stderr, "Bitrate in use: %d bytes/packet     ", tmp);
                }
-               outsamp=audio_write(output, channels, frame_size, fout, resampler, &preskip, dither?&shapemem:0, strlen(outFile)!=0,((page_granule-gran_offset)*rate/48000)-link_out);
+               maxout=((page_granule-gran_offset)*rate/48000)-link_out;
+               if (maxout<0)
+               {
+                  fprintf (stderr, "Decoding error: needed to write a negative number of samples. The input is probably corrupted.\n");
+                  exit(1);
+               }
+               outsamp=audio_write(output, channels, frame_size, fout, resampler, &preskip, dither?&shapemem:0, strlen(outFile)!=0,maxout);
                link_out+=outsamp;
                audio_size+=sizeof(short)*outsamp*channels;
             }