From f566dee902440e06d0e3f251d9cf8f40b5b3fc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Thu, 19 Sep 2024 14:50:50 +0200 Subject: [PATCH] Make requested_resolution throw on invalid dimensions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As mandated by the scaleResolutionDownTo spec. Bug: chromium:363544347 Change-Id: Ic78cad708a271bbd6a1980c08430dbb8ae07663a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/362980 Auto-Submit: Henrik Boström Commit-Queue: Henrik Boström Reviewed-by: Ilya Nikolaevskiy Cr-Commit-Position: refs/heads/main@{#43058} --- media/base/media_engine.cc | 5 +++++ ...eer_connection_encodings_integrationtest.cc | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/media/base/media_engine.cc b/media/base/media_engine.cc index dff4de0b14..c4b4f817ac 100644 --- a/media/base/media_engine.cc +++ b/media/base/media_engine.cc @@ -186,6 +186,11 @@ webrtc::RTCError CheckRtpParametersValues( if (rtp_parameters.encodings[i].requested_resolution.has_value()) { has_requested_resolution = true; + if (rtp_parameters.encodings[i].requested_resolution->width <= 0 || + rtp_parameters.encodings[i].requested_resolution->height <= 0) { + LOG_AND_RETURN_ERROR(RTCErrorType::INVALID_MODIFICATION, + "The resolution dimensions must be positive."); + } } if (!field_trials.IsEnabled("WebRTC-MixedCodecSimulcast")) { diff --git a/pc/peer_connection_encodings_integrationtest.cc b/pc/peer_connection_encodings_integrationtest.cc index ed087894e7..208f33fc8f 100644 --- a/pc/peer_connection_encodings_integrationtest.cc +++ b/pc/peer_connection_encodings_integrationtest.cc @@ -2134,6 +2134,15 @@ TEST_F(PeerConnectionEncodingsIntegrationTest, EXPECT_EQ(transceiver_or_error.error().type(), RTCErrorType::UNSUPPORTED_OPERATION); + // AddTransceiver: Width and height must not be zero. + init.send_encodings[0].requested_resolution = {.width = 1280, .height = 0}; + init.send_encodings[1].requested_resolution = {.width = 0, .height = 720}; + transceiver_or_error = + pc_wrapper->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO, init); + EXPECT_FALSE(transceiver_or_error.ok()); + EXPECT_EQ(transceiver_or_error.error().type(), + RTCErrorType::UNSUPPORTED_OPERATION); + // AddTransceiver: Specifying both `requested_resolution` and // `scale_resolution_down_by` is allowed (the latter is ignored). init.send_encodings[0].requested_resolution = {.width = 640, .height = 480}; @@ -2154,6 +2163,15 @@ TEST_F(PeerConnectionEncodingsIntegrationTest, EXPECT_FALSE(error.ok()); EXPECT_EQ(error.type(), RTCErrorType::INVALID_MODIFICATION); + // SetParameters: Width and height must not be zero. + sender = transceiver_or_error.value()->sender(); + parameters = sender->GetParameters(); + parameters.encodings[0].requested_resolution = {.width = 1280, .height = 0}; + parameters.encodings[1].requested_resolution = {.width = 0, .height = 720}; + error = sender->SetParameters(parameters); + EXPECT_FALSE(error.ok()); + EXPECT_EQ(error.type(), RTCErrorType::INVALID_MODIFICATION); + // SetParameters: Specifying both `requested_resolution` and // `scale_resolution_down_by` is allowed (the latter is ignored). parameters = sender->GetParameters();