Browse code

Implement missing case for decoding samples with large pivot value in APE decoder. This fixes issue 1555

Originally committed as revision 20560 to svn://svn.ffmpeg.org/ffmpeg/trunk

Kostya Shishkov authored on 2009/11/20 16:49:53
Showing 1 changed files
... ...
@@ -408,8 +408,24 @@ static inline int ape_decode_value(APEContext * ctx, APERice *rice)
408 408
             overflow |= range_decode_bits(ctx, 16);
409 409
         }
410 410
 
411
-        base = range_decode_culfreq(ctx, pivot);
412
-        range_decode_update(ctx, 1, base);
411
+        if (pivot < 0x10000) {
412
+            base = range_decode_culfreq(ctx, pivot);
413
+            range_decode_update(ctx, 1, base);
414
+        } else {
415
+            int base_hi = pivot, base_lo;
416
+            int bbits = 0;
417
+
418
+            while (base_hi & ~0xFFFF) {
419
+                base_hi >>= 1;
420
+                bbits++;
421
+            }
422
+            base_hi = range_decode_culfreq(ctx, base_hi + 1);
423
+            range_decode_update(ctx, 1, base_hi);
424
+            base_lo = range_decode_culfreq(ctx, 1 << bbits);
425
+            range_decode_update(ctx, 1, base_lo);
426
+
427
+            base = (base_hi << bbits) + base_lo;
428
+        }
413 429
 
414 430
         x = base + overflow * pivot;
415 431
     }