changeset 10545:e5a8a6b9a717 libavcodec

Implement missing case for decoding samples with large pivot value in APE decoder. This fixes issue 1555
author kostya
date Fri, 20 Nov 2009 07:49:53 +0000
parents b9fdb6b4c2dc
children 759ad4f2f7fe
files apedec.c
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/apedec.c	Fri Nov 20 07:26:17 2009 +0000
+++ b/apedec.c	Fri Nov 20 07:49:53 2009 +0000
@@ -408,8 +408,24 @@
             overflow |= range_decode_bits(ctx, 16);
         }
 
-        base = range_decode_culfreq(ctx, pivot);
-        range_decode_update(ctx, 1, base);
+        if (pivot < 0x10000) {
+            base = range_decode_culfreq(ctx, pivot);
+            range_decode_update(ctx, 1, base);
+        } else {
+            int base_hi = pivot, base_lo;
+            int bbits = 0;
+
+            while (base_hi & ~0xFFFF) {
+                base_hi >>= 1;
+                bbits++;
+            }
+            base_hi = range_decode_culfreq(ctx, base_hi + 1);
+            range_decode_update(ctx, 1, base_hi);
+            base_lo = range_decode_culfreq(ctx, 1 << bbits);
+            range_decode_update(ctx, 1, base_lo);
+
+            base = (base_hi << bbits) + base_lo;
+        }
 
         x = base + overflow * pivot;
     }