Browse code

avcodec/shorten: properly handle bitshift > 31

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2016/04/11 20:06:10
Showing 1 changed files
... ...
@@ -164,9 +164,13 @@ static void fix_bitshift(ShortenContext *s, int32_t *buffer)
164 164
 {
165 165
     int i;
166 166
 
167
-    if (s->bitshift != 0)
167
+    if (s->bitshift == 32) {
168
+        for (i = 0; i < s->blocksize; i++)
169
+            buffer[i] = 0;
170
+    } else if (s->bitshift != 0) {
168 171
         for (i = 0; i < s->blocksize; i++)
169 172
             buffer[i] <<= s->bitshift;
173
+    }
170 174
 }
171 175
 
172 176
 static int init_offset(ShortenContext *s)
... ...
@@ -602,7 +606,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
602 602
                 break;
603 603
             case FN_BITSHIFT: {
604 604
                 unsigned bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
605
-                if (bitshift > 31) {
605
+                if (bitshift > 32) {
606 606
                     av_log(avctx, AV_LOG_ERROR, "bitshift %d is invalid\n",
607 607
                            bitshift);
608 608
                     return AVERROR_INVALIDDATA;
... ...
@@ -680,7 +684,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
680 680
                 if (s->version < 2)
681 681
                     s->offset[channel][s->nmean - 1] = sum / s->blocksize;
682 682
                 else
683
-                    s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift;
683
+                    s->offset[channel][s->nmean - 1] = s->bitshift == 32 ? 0 : (sum / s->blocksize) << s->bitshift;
684 684
             }
685 685
 
686 686
             /* copy wrap samples for use with next block */