Skip to content

Commit 263682c

Browse files
committed
Fix bug with smaller width bigger size
Fixed previous patch that clusterfuzz failed on. Bug: webm:1642 Change-Id: If0e08e72abd2e042efe4dcfac21e4cc51afdfdb9
1 parent 3fbd1dc commit 263682c

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

Diff for: test/resize_test.cc

+3-8
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,8 @@ void ScaleForFrameNumber(unsigned int frame, unsigned int initial_w,
102102
if (frame < 30) {
103103
return;
104104
}
105-
if (frame < 100) {
106-
*w = initial_w * 7 / 10;
107-
*h = initial_h * 16 / 10;
108-
return;
109-
}
105+
*w = initial_w * 7 / 10;
106+
*h = initial_h * 16 / 10;
110107
return;
111108
}
112109
if (frame < 10) {
@@ -559,9 +556,7 @@ TEST_P(ResizeRealtimeTest, TestExternalResizeWorks) {
559556
}
560557
}
561558

562-
// TODO(https://crbug.com/webm/1642): This causes a segfault in
563-
// init_encode_frame_mb_context().
564-
TEST_P(ResizeRealtimeTest, DISABLED_TestExternalResizeSmallerWidthBiggerSize) {
559+
TEST_P(ResizeRealtimeTest, TestExternalResizeSmallerWidthBiggerSize) {
565560
ResizingVideoSource video;
566561
video.flag_codec_ = true;
567562
video.smaller_width_larger_size_ = true;

Diff for: vp9/common/vp9_alloccommon.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@ int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) {
135135
cm->free_mi(cm);
136136
if (cm->alloc_mi(cm, new_mi_size)) goto fail;
137137
}
138-
139-
if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) {
140-
// Create the segmentation map structure and set to 0.
141-
free_seg_map(cm);
142-
if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) goto fail;
143-
}
144-
145138
if (cm->above_context_alloc_cols < cm->mi_cols) {
146139
vpx_free(cm->above_context);
147140
cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc(
@@ -156,6 +149,12 @@ int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) {
156149
cm->above_context_alloc_cols = cm->mi_cols;
157150
}
158151

152+
if (cm->seg_map_alloc_size < cm->mi_rows * cm->mi_cols) {
153+
// Create the segmentation map structure and set to 0.
154+
free_seg_map(cm);
155+
if (alloc_seg_map(cm, cm->mi_rows * cm->mi_cols)) goto fail;
156+
}
157+
159158
if (vp9_alloc_loop_filter(cm)) goto fail;
160159

161160
return 0;

Diff for: vp9/encoder/vp9_encoder.c

+25-2
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,17 @@ static void alloc_copy_partition_data(VP9_COMP *cpi) {
20472047
}
20482048
}
20492049

2050+
static void free_copy_partition_data(VP9_COMP *cpi) {
2051+
vpx_free(cpi->prev_partition);
2052+
cpi->prev_partition = NULL;
2053+
vpx_free(cpi->prev_segment_id);
2054+
cpi->prev_segment_id = NULL;
2055+
vpx_free(cpi->prev_variance_low);
2056+
cpi->prev_variance_low = NULL;
2057+
vpx_free(cpi->copied_frame_cnt);
2058+
cpi->copied_frame_cnt = NULL;
2059+
}
2060+
20502061
void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
20512062
VP9_COMMON *const cm = &cpi->common;
20522063
RATE_CONTROL *const rc = &cpi->rc;
@@ -2126,6 +2137,8 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
21262137
new_mi_size = cm->mi_stride * calc_mi_size(cm->mi_rows);
21272138
if (cm->mi_alloc_size < new_mi_size) {
21282139
vp9_free_context_buffers(cm);
2140+
vp9_free_pc_tree(&cpi->td);
2141+
vpx_free(cpi->mbmi_ext_base);
21292142
alloc_compressor_data(cpi);
21302143
realloc_segmentation_maps(cpi);
21312144
cpi->initial_width = cpi->initial_height = 0;
@@ -2144,8 +2157,18 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
21442157
update_frame_size(cpi);
21452158

21462159
if (last_w != cpi->oxcf.width || last_h != cpi->oxcf.height) {
2147-
memset(cpi->consec_zero_mv, 0,
2148-
cm->mi_rows * cm->mi_cols * sizeof(*cpi->consec_zero_mv));
2160+
vpx_free(cpi->consec_zero_mv);
2161+
CHECK_MEM_ERROR(
2162+
&cm->error, cpi->consec_zero_mv,
2163+
vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(*cpi->consec_zero_mv)));
2164+
2165+
vpx_free(cpi->skin_map);
2166+
CHECK_MEM_ERROR(
2167+
&cm->error, cpi->skin_map,
2168+
vpx_calloc(cm->mi_rows * cm->mi_cols, sizeof(cpi->skin_map[0])));
2169+
2170+
free_copy_partition_data(cpi);
2171+
alloc_copy_partition_data(cpi);
21492172
if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
21502173
vp9_cyclic_refresh_reset_resize(cpi);
21512174
rc->rc_1_frame = 0;

0 commit comments

Comments
 (0)