diff --git a/src/sources/statsd/parser.rs b/src/sources/statsd/parser.rs index 5afa97d535..4da0bf9c28 100644 --- a/src/sources/statsd/parser.rs +++ b/src/sources/statsd/parser.rs @@ -94,7 +94,10 @@ impl Parser { { parts[0].parse()? } else { - parts[0][1..].parse()? + parts[0] + .get(1..) + .ok_or(ParseError::Malformed("invalid gauge prefix"))? + .parse()? }; match parse_direction(parts[0])? { @@ -423,6 +426,16 @@ mod test { ); } + #[test] + fn gauge_with_multibyte_prefix_does_not_panic() { + // OBE-10714: a gauge value whose first character is a multi-byte UTF-8 codepoint (here + // `±`, U+00B1, 2 bytes) must not panic on a non-char-boundary byte slice. + assert!(matches!( + unsanitized_parse("x:\u{00B1}1|g"), + Err(ParseError::Malformed(_)) + )); + } + #[test] fn sets() { assert_event_data_eq!(