Skip to content

Commit

Permalink
VideoEncoder: Return unsupported for codec strings with spaces
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ChunMinChang authored and moz-wptsync-bot committed Dec 24, 2024
1 parent 1d70c9c commit 6efc8af
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions webcodecs/video-encoder-config.https.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 6efc8af

Please sign in to comment.