Commit b62ed56e authored by Paul B Mahol's avatar Paul B Mahol

avcodec/shorten: properly handle bitshift > 31

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 15fa0178
...@@ -164,9 +164,13 @@ static void fix_bitshift(ShortenContext *s, int32_t *buffer) ...@@ -164,9 +164,13 @@ static void fix_bitshift(ShortenContext *s, int32_t *buffer)
{ {
int i; int i;
if (s->bitshift != 0) if (s->bitshift == 32) {
for (i = 0; i < s->blocksize; i++)
buffer[i] = 0;
} else if (s->bitshift != 0) {
for (i = 0; i < s->blocksize; i++) for (i = 0; i < s->blocksize; i++)
buffer[i] <<= s->bitshift; buffer[i] <<= s->bitshift;
}
} }
static int init_offset(ShortenContext *s) static int init_offset(ShortenContext *s)
...@@ -602,7 +606,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, ...@@ -602,7 +606,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
break; break;
case FN_BITSHIFT: { case FN_BITSHIFT: {
unsigned bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE); unsigned bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
if (bitshift > 31) { if (bitshift > 32) {
av_log(avctx, AV_LOG_ERROR, "bitshift %d is invalid\n", av_log(avctx, AV_LOG_ERROR, "bitshift %d is invalid\n",
bitshift); bitshift);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
...@@ -680,7 +684,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data, ...@@ -680,7 +684,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
if (s->version < 2) if (s->version < 2)
s->offset[channel][s->nmean - 1] = sum / s->blocksize; s->offset[channel][s->nmean - 1] = sum / s->blocksize;
else else
s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift; s->offset[channel][s->nmean - 1] = s->bitshift == 32 ? 0 : (sum / s->blocksize) << s->bitshift;
} }
/* copy wrap samples for use with next block */ /* copy wrap samples for use with next block */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment