From a2bf49b29110804b286f6fc5dc1e4ba70774d47e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 20 Nov 2026 16:27:12 -0800 Subject: [PATCH] fix(hang): refuse malformed H.264 codec fields (backport #6847) A non-ASCII byte in an avc1/avc3 profile field sliced the codec string inside a UTF-8 character and panicked the catalog parser. Co-Authored-By: Claude Opus 5.5 --- rs/hang/src/catalog/video/h264.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rs/hang/src/catalog/video/h264.rs b/rs/hang/src/catalog/video/h264.rs index 34866317a00..86ea0d94eae 100644 --- a/rs/hang/src/catalog/video/h264.rs +++ b/rs/hang/src/catalog/video/h264.rs @@ -47,7 +47,7 @@ impl FromStr for H264 { }; let part = parts.next().ok_or(Error::InvalidCodec)?; - if part.len() != 6 { + if part.len() != 6 || !part.bytes().all(|byte| byte.is_ascii_hexdigit()) { return Err(Error::InvalidCodec); } @@ -68,6 +68,19 @@ mod tests { use super::*; + #[test] + fn malformed_hex_fields_are_invalid() { + for prefix in ["avc1", "avc3"] { + for part in ["aé123", "12aé3", "123aé", "+12345", "12+345", "1234+5", "12gg56"] { + let encoded = format!("{prefix}.{part}"); + assert!( + matches!(VideoCodec::from_str(&encoded), Err(Error::InvalidCodec)), + "{encoded}" + ); + } + } + } + #[test] fn test_h264_avc1() { let encoded = "avc1.42c01e";