From 3ae6646183c9a4128de1ea7d3202ce637e1f993a Mon Sep 17 00:00:00 2001 From: Andrew Hickman Date: Mon, 28 Feb 2022 20:37:12 +0000 Subject: [PATCH] Fix out-of-bounds array index (#597) Co-authored-by: Lucio Franco --- prost-build/src/code_generator.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/prost-build/src/code_generator.rs b/prost-build/src/code_generator.rs index 53c0372ea..6bcbf8a95 100644 --- a/prost-build/src/code_generator.rs +++ b/prost-build/src/code_generator.rs @@ -963,7 +963,7 @@ fn unescape_c_escape_string(s: &str) -> Vec { dst.push(octal); } b'x' | b'X' => { - if p + 2 > len { + if p + 3 > len { panic!( "invalid c-escaped default binary value ({}): incomplete hex value", s @@ -1074,6 +1074,12 @@ mod tests { ); } + #[test] + #[should_panic(expected = "incomplete hex value")] + fn test_unescape_c_escape_string_incomplete_hex_value() { + unescape_c_escape_string(r#"\x1"#); + } + #[test] fn test_strip_enum_prefix() { assert_eq!(strip_enum_prefix("Foo", "FooBar"), "Bar");