aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-09-23 15:46:52 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-09-23 15:46:52 +0200
commit0bb5ad7a06ebcda9102357f8755d18b63f56aa29 (patch)
treee5dcf1265d91afad742e913b616c1c65ef2e7150 /libavcodec
parent6b2caa321fc2539c937978e040fab139d5823857 (diff)
downloadffmpeg-0bb5ad7a06ebcda9102357f8755d18b63f56aa29.tar.gz
avcodec/asvenc: Fix integer overflow in level
Warn if the qscale is too low for the input data and clip levels to minimize artifacts Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/asvenc.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/libavcodec/asvenc.c b/libavcodec/asvenc.c
index bbf4494866..ccd8182e1e 100644
--- a/libavcodec/asvenc.c
+++ b/libavcodec/asvenc.c
@@ -50,7 +50,7 @@ static inline void asv1_put_level(PutBitContext *pb, int level)
}
}
-static inline void asv2_put_level(PutBitContext *pb, int level)
+static inline void asv2_put_level(ASV1Context *a, PutBitContext *pb, int level)
{
unsigned int index = level + 31;
@@ -58,6 +58,10 @@ static inline void asv2_put_level(PutBitContext *pb, int level)
put_bits(pb, ff_asv2_level_tab[index][1], ff_asv2_level_tab[index][0]);
} else {
put_bits(pb, ff_asv2_level_tab[31][1], ff_asv2_level_tab[31][0]);
+ if (level < -128 || level > 127) {
+ av_log(a->avctx, AV_LOG_WARNING, "Cliping level %d, increase qscale\n", level);
+ level = av_clip_int8(level);
+ }
asv2_put_bits(pb, 8, level & 0xFF);
}
}
@@ -150,13 +154,13 @@ static inline void asv2_encode_block(ASV1Context *a, int16_t block[64])
if (ccp) {
if (ccp & 8)
- asv2_put_level(&a->pb, block[index + 0]);
+ asv2_put_level(a, &a->pb, block[index + 0]);
if (ccp & 4)
- asv2_put_level(&a->pb, block[index + 8]);
+ asv2_put_level(a, &a->pb, block[index + 8]);
if (ccp & 2)
- asv2_put_level(&a->pb, block[index + 1]);
+ asv2_put_level(a, &a->pb, block[index + 1]);
if (ccp & 1)
- asv2_put_level(&a->pb, block[index + 9]);
+ asv2_put_level(a, &a->pb, block[index + 9]);
}
}
}