Submitted By: Xi Ruoyao Date: 2023-09-29 Initial Package Version: 1.13.0 Upstream Status: Committed Origin: Upstream commits (need a rebase for 1.13.0): - af6dedd715f4307669366944cca6e0417b290282 - 3fbd1dca6a4d2dad332a2110d646e4ffef36d590 Description: Fixes CVE-2023-5217, a security vulnerability allowing a remote attacker to potentially exploit heap corruption via a crafted HTML page. Google is aware that an exploit for CVE-2023-5217 exists in the wild. diff --color -Naur libvpx-1.13.0/test/encode_api_test.cc libvpx-1.13.0-patched/test/encode_api_test.cc --- libvpx-1.13.0/test/encode_api_test.cc 2023-02-08 09:33:51.000000000 +0800 +++ libvpx-1.13.0-patched/test/encode_api_test.cc 2023-09-29 15:59:54.691661323 +0800 @@ -304,7 +304,6 @@ void InitCodec(const vpx_codec_iface_t &iface, int width, int height, vpx_codec_ctx_t *enc, vpx_codec_enc_cfg_t *cfg) { - ASSERT_EQ(vpx_codec_enc_config_default(&iface, cfg, 0), VPX_CODEC_OK); cfg->g_w = width; cfg->g_h = height; cfg->g_lag_in_frames = 0; @@ -342,6 +341,7 @@ vpx_codec_ctx_t ctx = {}; } enc; + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); EXPECT_NO_FATAL_FAILURE( InitCodec(*iface, kWidth, kHeight, &enc.ctx, &cfg)); if (IsVP9(iface)) { @@ -353,6 +353,50 @@ for (const auto threads : { 1, 4, 8, 6, 2, 1 }) { cfg.g_threads = threads; + EXPECT_NO_FATAL_FAILURE(EncodeWithConfig(cfg, &enc.ctx)) + << "iteration: " << i << " threads: " << threads; + } + } + } +} + +TEST(EncodeAPI, ConfigResizeChangeThreadCount) { + constexpr int kInitWidth = 1024; + constexpr int kInitHeight = 1024; + + for (const auto *iface : kCodecIfaces) { + SCOPED_TRACE(vpx_codec_iface_name(iface)); + for (int i = 0; i < (IsVP9(iface) ? 2 : 1); ++i) { + vpx_codec_enc_cfg_t cfg = {}; + struct Encoder { + ~Encoder() { EXPECT_EQ(vpx_codec_destroy(&ctx), VPX_CODEC_OK); } + vpx_codec_ctx_t ctx = {}; + } enc; + + ASSERT_EQ(vpx_codec_enc_config_default(iface, &cfg, 0), VPX_CODEC_OK); + // Start in threaded mode to ensure resolution and thread related + // allocations are updated correctly across changes in resolution and + // thread counts. See https://crbug.com/1486441. + cfg.g_threads = 4; + EXPECT_NO_FATAL_FAILURE( + InitCodec(*iface, kInitWidth, kInitHeight, &enc.ctx, &cfg)); + if (IsVP9(iface)) { + EXPECT_EQ(vpx_codec_control_(&enc.ctx, VP9E_SET_TILE_COLUMNS, 6), + VPX_CODEC_OK); + EXPECT_EQ(vpx_codec_control_(&enc.ctx, VP9E_SET_ROW_MT, i), + VPX_CODEC_OK); + } + + cfg.g_w = 1000; + cfg.g_h = 608; + EXPECT_EQ(vpx_codec_enc_config_set(&enc.ctx, &cfg), VPX_CODEC_OK) + << vpx_codec_error_detail(&enc.ctx); + + cfg.g_w = 16; + cfg.g_h = 720; + + for (const auto threads : { 1, 4, 8, 6, 2, 1 }) { + cfg.g_threads = threads; EXPECT_NO_FATAL_FAILURE(EncodeWithConfig(cfg, &enc.ctx)) << "iteration: " << i << " threads: " << threads; } diff --color -Naur libvpx-1.13.0/vp8/encoder/onyx_if.c libvpx-1.13.0-patched/vp8/encoder/onyx_if.c --- libvpx-1.13.0/vp8/encoder/onyx_if.c 2023-02-08 09:33:51.000000000 +0800 +++ libvpx-1.13.0-patched/vp8/encoder/onyx_if.c 2023-09-29 15:57:03.428141260 +0800 @@ -1443,6 +1443,11 @@ last_h = cpi->oxcf.Height; prev_number_of_layers = cpi->oxcf.number_of_layers; + if (cpi->initial_width) { + // TODO(https://crbug.com/1486441): Allow changing thread counts; the + // allocation is done once in vp8_create_compressor(). + oxcf->multi_threaded = cpi->oxcf.multi_threaded; + } cpi->oxcf = *oxcf; switch (cpi->oxcf.Mode) {