Skip to content

Commit 27bc134

Browse files
marco99zzmibrunin
authored andcommitted
[Backport] Security bug 329674887 (1/2)
Cherry-pick of patch orignally reviewed on https://chromium-review.googlesource.com/c/webm/libvpx/+/5370376: Fix to buffer alloc for vp9_bitstream_worker_data The code was using the bitstream_worker_data when it wasn't allocated for big enough size. This is because the existing condition was to only re-alloc the bitstream_worker_data when current dest_size was larger than the current frame_size. But under resolution change where frame_size is increased, beyond the current dest_size, we need to allow re-alloc to the new size. The existing condition to re-alloc when dest_size is larger than frame_size (which is not required) is kept for now. Also increase the dest_size to account for image format. Added tests, for both ROW_MT=0 and 1, that reproduce the failures in the bugs below. Note: this issue only affects the REALTIME encoding path. Bug: b/329088759, b/329674887, b/329179808 Change-Id: Icd65dbc5317120304d803f648d4bd9405710db6f Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/554625 Reviewed-by: Michal Klocek <[email protected]>
1 parent bae0d69 commit 27bc134

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

chromium/third_party/libvpx/source/libvpx/vp9/encoder/vp9_bitstream.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,14 @@ void vp9_bitstream_encode_tiles_buffer_dealloc(VP9_COMP *const cpi) {
962962
}
963963
}
964964

965+
static int encode_tiles_buffer_alloc_size(VP9_COMP *const cpi) {
966+
VP9_COMMON *const cm = &cpi->common;
967+
const int image_bps =
968+
(8 + 2 * (8 >> (cm->subsampling_x + cm->subsampling_y))) *
969+
(1 + (cm->bit_depth > 8));
970+
return cpi->oxcf.width * cpi->oxcf.height * image_bps / 8;
971+
}
972+
965973
static void encode_tiles_buffer_alloc(VP9_COMP *const cpi) {
966974
VP9_COMMON *const cm = &cpi->common;
967975
int i;
@@ -972,7 +980,7 @@ static void encode_tiles_buffer_alloc(VP9_COMP *const cpi) {
972980
memset(cpi->vp9_bitstream_worker_data, 0, worker_data_size);
973981
for (i = 1; i < cpi->num_workers; ++i) {
974982
cpi->vp9_bitstream_worker_data[i].dest_size =
975-
cpi->oxcf.width * cpi->oxcf.height;
983+
encode_tiles_buffer_alloc_size(cpi);
976984
CHECK_MEM_ERROR(&cm->error, cpi->vp9_bitstream_worker_data[i].dest,
977985
vpx_malloc(cpi->vp9_bitstream_worker_data[i].dest_size));
978986
}
@@ -987,8 +995,8 @@ static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr) {
987995
int tile_col = 0;
988996

989997
if (!cpi->vp9_bitstream_worker_data ||
990-
cpi->vp9_bitstream_worker_data[1].dest_size >
991-
(cpi->oxcf.width * cpi->oxcf.height)) {
998+
cpi->vp9_bitstream_worker_data[1].dest_size !=
999+
encode_tiles_buffer_alloc_size(cpi)) {
9921000
vp9_bitstream_encode_tiles_buffer_dealloc(cpi);
9931001
encode_tiles_buffer_alloc(cpi);
9941002
}

0 commit comments

Comments
 (0)