From dc964e10225cddc10103dfefec87384d0fbbd3fb Mon Sep 17 00:00:00 2001 From: Arman Thakur Date: Tue, 10 Nov 2026 20:48:59 +0530 Subject: [PATCH] Reject malformed --service all values instead of aborting (#2405) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit parse_708_services() took the charset of "all[X]" by slicing the value from byte 4 to one before the end whenever it was longer than "all". It never checked for the brackets, so: - "all1" and "all[" panicked (the range starts at 4 but ends at 3), and "allé" panicked slicing inside a character. The panic can't unwind out of ccxr_parse_parameters, so the process aborted (SIGABRT, exit 134). - "all[EUC-KR" lost its last letter and failed later in iconv with charset "EUC-K"; "allEUC-KR]" became "UC-KR". This came with the Rust parser (#1619). The C parser only took a charset when the value was longer than "all[]", so it never panicked, though it did not check the brackets either. Accept "all" and "all[charset]" only, and report anything else as a malformed parameter (exit 7), as #2393 does for service numbers. --- src/rust/src/parser.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/rust/src/parser.rs b/src/rust/src/parser.rs index 83c4b98a..5da24fc8 100644 --- a/src/rust/src/parser.rs +++ b/src/rust/src/parser.rs @@ -63,6 +63,16 @@ fn parse_service_number(service: &str) -> Option { .filter(|svc| (1..=DTVCC_MAX_SERVICES).contains(svc)) } +/// The charset of a --service value that starts with "all": "" for "all", +/// "X" for "all[X]". None if the value has any other form. +fn all_services_charset(services: &str) -> Option<&str> { + let rest = services.strip_prefix("all")?; + if rest.is_empty() { + return Some(""); + } + rest.strip_prefix('[')?.strip_suffix(']') +} + fn atoi_hex(s: &str) -> Result where T: Integer + std::str::FromStr, @@ -289,7 +299,12 @@ impl OptionsExt for Options { fn parse_708_services(&mut self, s: &str) { if s.starts_with("all") { - let charset = if s.len() > 3 { &s[4..s.len() - 1] } else { "" }; + let Some(charset) = all_services_charset(s) else { + fatal!( + cause = ExitCause::MalformedParameter; + "[CEA-708] Malformed parameter: Invalid service list ({}), use all or all[charset].\n", s + ); + }; self.settings_dtvcc.enabled = true; self.enc_cfg.dtvcc_extract = true; @@ -2488,6 +2503,19 @@ pub mod tests { assert_eq!(parse_service_number("99999999999999999999999"), None); } + #[test] + fn test_all_services_charset() { + assert_eq!(all_services_charset("all"), Some("")); + assert_eq!(all_services_charset("all[EUC-KR]"), Some("EUC-KR")); + assert_eq!(all_services_charset("all[]"), Some("")); + // These used to panic slicing the value, or silently cut the charset. + assert_eq!(all_services_charset("all1"), None); + assert_eq!(all_services_charset("all["), None); + assert_eq!(all_services_charset("allé"), None); + assert_eq!(all_services_charset("all[EUC-KR"), None); + assert_eq!(all_services_charset("allEUC-KR]"), None); + } + #[test] fn test_koc_enables_keep_output_closed() { let (options, _) = parse_args(&["--koc"]);