avcodec/golomb: get_ur_golomb_jpegls: Fix reading huge k values
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 17 May 2015 17:07:17 +0000 (19:07 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 17 May 2015 17:36:32 +0000 (19:36 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/golomb.h

index 76da6a2..134e6ac 100644 (file)
@@ -334,8 +334,16 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit,
 
         if (i < limit - 1) {
             if (k) {
-                buf = SHOW_UBITS(re, gb, k);
-                LAST_SKIP_BITS(re, gb, k);
+                if (k > MIN_CACHE_BITS - 1) {
+                    buf = SHOW_UBITS(re, gb, 16) << (k-16);
+                    LAST_SKIP_BITS(re, gb, 16);
+                    UPDATE_CACHE(re, gb);
+                    buf |= SHOW_UBITS(re, gb, k-16);
+                    LAST_SKIP_BITS(re, gb, k-16);
+                } else {
+                    buf = SHOW_UBITS(re, gb, k);
+                    LAST_SKIP_BITS(re, gb, k);
+                }
             } else {
                 buf = 0;
             }