shithub: opus

Download patch

ref: 3b34e188ede286d7a4ecc9fdf66831397a352cb3
parent: ae2fb591b89a8a5cc29fcb89fc53639ebfe84314
author: Gregory Maxwell <[email protected]>
date: Tue Oct 28 16:28:28 EDT 2008

In some conditions the allocation could run out of bits and attempt to allocate a negative number of pulses.

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -377,10 +377,12 @@
       remaining_bits -= curr_bits;
       if (remaining_bits < 0)
       {
-         q--;
          remaining_bits += curr_bits;
-         curr_bits = BPbits[i][q];
-         remaining_bits -= curr_bits;
+         if (q>0) {
+           q--;
+           curr_bits = BPbits[i][q];
+           remaining_bits -= curr_bits;
+         }
       }
       balance += pulses[i] + tell;
       
@@ -462,10 +464,12 @@
       remaining_bits -= curr_bits;
       if (remaining_bits < 0)
       {
-         q--;
          remaining_bits += curr_bits;
-         curr_bits = BPbits[i][q];
-         remaining_bits -= curr_bits;
+         if (q>0) {
+           q--;
+           curr_bits = BPbits[i][q];
+           remaining_bits -= curr_bits;
+         }
       }
       balance += pulses[i] + tell;