aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michael@niedermayer.cc>2019-06-13 15:05:54 +0200
committerMichael Niedermayer <michael@niedermayer.cc>2019-11-14 23:30:37 +0100
commit3bdd16fd68c32b13fc0e24e68af3fa4ce3d5df85 (patch)
treeb9db0b89a77000c1614d1514399652aff1d0cae3
parent9a7d3304ff40bc5c93f92aaa375d4177672b8b5e (diff)
downloadffmpeg-3bdd16fd68c32b13fc0e24e68af3fa4ce3d5df85.tar.gz
avcodec/hevc_ps: Fix integer overflow with num_tile_rows and num_tile_columns
Fixes: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int' Fixes: 14880/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_HEVC_fuzzer-5130977304641536 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> (cherry picked from commit c692051252693155c4eecd16f4f8a79caf66cd54) Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r--libavcodec/hevc_ps.c23
-rw-r--r--libavcodec/hevc_ps.h4
2 files changed, 15 insertions, 12 deletions
diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 6f3af2daec..de75d30de4 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1582,22 +1582,25 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx,
pps->entropy_coding_sync_enabled_flag = get_bits1(gb);
if (pps->tiles_enabled_flag) {
- pps->num_tile_columns = get_ue_golomb_long(gb) + 1;
- pps->num_tile_rows = get_ue_golomb_long(gb) + 1;
- if (pps->num_tile_columns <= 0 ||
- pps->num_tile_columns >= sps->width) {
+ int num_tile_columns_minus1 = get_ue_golomb(gb);
+ int num_tile_rows_minus1 = get_ue_golomb(gb);
+
+ if (num_tile_columns_minus1 < 0 ||
+ num_tile_columns_minus1 >= sps->width - 1) {
av_log(avctx, AV_LOG_ERROR, "num_tile_columns_minus1 out of range: %d\n",
- pps->num_tile_columns - 1);
- ret = AVERROR_INVALIDDATA;
+ num_tile_columns_minus1);
+ ret = num_tile_columns_minus1 < 0 ? num_tile_columns_minus1 : AVERROR_INVALIDDATA;
goto err;
}
- if (pps->num_tile_rows <= 0 ||
- pps->num_tile_rows >= sps->height) {
+ if (num_tile_rows_minus1 < 0 ||
+ num_tile_rows_minus1 >= sps->height - 1) {
av_log(avctx, AV_LOG_ERROR, "num_tile_rows_minus1 out of range: %d\n",
- pps->num_tile_rows - 1);
- ret = AVERROR_INVALIDDATA;
+ num_tile_rows_minus1);
+ ret = num_tile_rows_minus1 < 0 ? num_tile_rows_minus1 : AVERROR_INVALIDDATA;
goto err;
}
+ pps->num_tile_columns = num_tile_columns_minus1 + 1;
+ pps->num_tile_rows = num_tile_rows_minus1 + 1;
pps->column_width = av_malloc_array(pps->num_tile_columns, sizeof(*pps->column_width));
pps->row_height = av_malloc_array(pps->num_tile_rows, sizeof(*pps->row_height));
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index f19d022469..552a6426b5 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -343,8 +343,8 @@ typedef struct HEVCPPS {
uint8_t tiles_enabled_flag;
uint8_t entropy_coding_sync_enabled_flag;
- int num_tile_columns; ///< num_tile_columns_minus1 + 1
- int num_tile_rows; ///< num_tile_rows_minus1 + 1
+ uint16_t num_tile_columns; ///< num_tile_columns_minus1 + 1
+ uint16_t num_tile_rows; ///< num_tile_rows_minus1 + 1
uint8_t uniform_spacing_flag;
uint8_t loop_filter_across_tiles_enabled_flag;