Skip to content

Commit 0caef9f

Browse files
committed
vp8: reset above_context in init_encode_frame_mb_context
When encoding multiple frames with VP8_TUNE_SSIM, xd->above_context was not reset during frame context initialization. This caused xd->above_context to retain an out-of-bounds pointer from the end of the previous frame's macroblock row traversal, leading to a heap buffer overflow in vp8_optimize_mby() during build_activity_map(). Unittest added. Bug: 550179428 Change-Id: I3b33fc3e6d1670c2e5e7952508c9097b48ecf0cf
1 parent ac888d6 commit 0caef9f

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

test/encode_api_test.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,33 @@ TEST(EncodeAPI, Vp8DenoiserResolutionChange) {
10821082

10831083
ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK);
10841084
}
1085+
1086+
// Test VP8 SSIM tuning with multiple frames.
1087+
TEST(EncodeAPI, Vp8SSIMMultipleFrames) {
1088+
vpx_codec_iface_t *const iface = vpx_codec_vp8_cx();
1089+
vpx_codec_ctx_t enc;
1090+
vpx_codec_enc_cfg_t cfg;
1091+
ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK);
1092+
ASSERT_EQ(vpx_codec_enc_init(&enc, iface, &cfg, 0), VPX_CODEC_OK);
1093+
1094+
// Set VP8_TUNE_SSIM.
1095+
ASSERT_EQ(vpx_codec_control(&enc, VP8E_SET_TUNING, VP8_TUNE_SSIM),
1096+
VPX_CODEC_OK);
1097+
1098+
vpx_image_t *const img =
1099+
CreateImage(VPX_BITS_8, VPX_IMG_FMT_I420, cfg.g_w, cfg.g_h);
1100+
ASSERT_NE(img, nullptr);
1101+
1102+
// Encode multiple frames with GOOD_QUALITY to enable coefficient
1103+
// optimization.
1104+
for (int frame = 0; frame < 2; ++frame) {
1105+
ASSERT_EQ(vpx_codec_encode(&enc, img, frame, 1, 0, VPX_DL_GOOD_QUALITY),
1106+
VPX_CODEC_OK);
1107+
}
1108+
1109+
vpx_img_free(img);
1110+
ASSERT_EQ(vpx_codec_destroy(&enc), VPX_CODEC_OK);
1111+
}
10851112
#endif // CONFIG_VP8_ENCODER
10861113

10871114
// Set up 2 spatial streams with 2 temporal layers per stream, and generate

vp8/encoder/encodeframe.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ static void init_encode_frame_mb_context(VP8_COMP *cpi) {
613613

614614
x->mvc = cm->fc.mvc;
615615

616+
xd->above_context = cm->above_context;
616617
memset(cm->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * cm->mb_cols);
617618

618619
/* Special case treatment when GF and ARF are not sensible options

0 commit comments

Comments
 (0)