From 6efc8afc8a0e1ad401005fac848098b7759e62fa Mon Sep 17 00:00:00 2001 From: Chun-Min Chang Date: Mon, 23 Dec 2024 17:55:45 +0000 Subject: [PATCH] VideoEncoder: Return unsupported for codec strings with spaces This patch fixes a crash that occurs when a codec string with leading spaces is passed to `VideoEncoder::IsConfigSupported`. The crash happens because `VideoEncoderConfigInternal::ToEncoderConfig` assumes that its codec string member begins with a supported codec name (which should be non-space character). When the codec string has leading spaces, this assumption is invalidated, leading to a crash. To resolve this issue, the patch removes the space-trimming in `CanEncode` and calling `IsSupportedVideoCodec` with the given codec string directly before `ToEncoderConfig`. By doing so, codec strings with leading spaces are correctly identified as "unsupported", and `ToEncoderConfig` is not invoked with invalid input, preventing the crash. Additionally, this patch adds a WPT to ensure that codec string containing spaces are reported as "unsupported" and the no crash occurs when such strings are processed. Differential Revision: https://phabricator.services.mozilla.com/D231719 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1936352 gecko-commit: 00a6b47b218e193d0018ffbd2996e0112d2a90f3 gecko-reviewers: media-playback-reviewers, alwu --- webcodecs/video-encoder-config.https.any.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/webcodecs/video-encoder-config.https.any.js b/webcodecs/video-encoder-config.https.any.js index 5ee90c74c407a6..b692bd14f7848f 100644 --- a/webcodecs/video-encoder-config.https.any.js +++ b/webcodecs/video-encoder-config.https.any.js @@ -183,6 +183,14 @@ const validButUnsupportedConfigs = [ height: 480, }, }, + { + comment: 'codec with spaces', + config: { + codec: ' vp09.00.10.08 ', + width: 640, + height: 480, + } + } ]; validButUnsupportedConfigs.forEach(entry => {