aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2017-03-21 23:46:14 +0100
committerMichael Niedermayer <michael@niedermayer.cc>2017-04-08 22:31:05 +0200
commit1833ec53349ca1b1b1d21f1f8a3c63373e19123d (patch)
tree0308e0ec659492cc1f5e1fa7e97dd83e4fbd14b4
parentc9c977be2761dc48c7595c9483282b9a12011771 (diff)
downloadffmpeg-1833ec53349ca1b1b1d21f1f8a3c63373e19123d.tar.gz
avcodec/h264: Check weight values to be within the specs limits.
Fixes: integer overflows Fixes: 911/clusterfuzz-testcase-5415105606975488 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg Reviewed-by: "Ronald S. Bultje" <rsbultje@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit 08117a40157464f8a9dcc2df393fa5fe299c1e98) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/h264_parse.c9
-rw-r--r--libavcodec/h264_slice.c7
2 files changed, 14 insertions, 2 deletions
diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
index 0c873196dc..ea202e759c 100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@ -59,6 +59,9 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
if (luma_weight_flag) {
pwt->luma_weight[i][list][0] = get_se_golomb(gb);
pwt->luma_weight[i][list][1] = get_se_golomb(gb);
+ if ((int8_t)pwt->luma_weight[i][list][0] != pwt->luma_weight[i][list][0] ||
+ (int8_t)pwt->luma_weight[i][list][1] != pwt->luma_weight[i][list][1])
+ goto out_range_weight;
if (pwt->luma_weight[i][list][0] != luma_def ||
pwt->luma_weight[i][list][1] != 0) {
pwt->use_weight = 1;
@@ -76,6 +79,9 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
for (j = 0; j < 2; j++) {
pwt->chroma_weight[i][list][j][0] = get_se_golomb(gb);
pwt->chroma_weight[i][list][j][1] = get_se_golomb(gb);
+ if ((int8_t)pwt->chroma_weight[i][list][j][0] != pwt->chroma_weight[i][list][j][0] ||
+ (int8_t)pwt->chroma_weight[i][list][j][1] != pwt->chroma_weight[i][list][j][1])
+ goto out_range_weight;
if (pwt->chroma_weight[i][list][j][0] != chroma_def ||
pwt->chroma_weight[i][list][j][1] != 0) {
pwt->use_weight_chroma = 1;
@@ -104,6 +110,9 @@ int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
}
pwt->use_weight = pwt->use_weight || pwt->use_weight_chroma;
return 0;
+out_range_weight:
+ avpriv_request_sample(logctx, "Out of range weight\n");
+ return AVERROR_INVALIDDATA;
}
/**
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index fa1e9ae829..44a0b9fb17 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1778,9 +1778,12 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
}
if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||
(pps->weighted_bipred_idc == 1 &&
- sl->slice_type_nos == AV_PICTURE_TYPE_B))
- ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,
+ sl->slice_type_nos == AV_PICTURE_TYPE_B)) {
+ ret = ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,
sl->slice_type_nos, &sl->pwt, h->avctx);
+ if (ret < 0)
+ return ret;
+ }
sl->explicit_ref_marking = 0;
if (nal->ref_idc) {