From 06b9ace2b715501a4bec724514d988fc253015ed Mon Sep 17 00:00:00 2001 From: Devin Jean Date: Wed, 15 Nov 2023 08:08:18 -0600 Subject: [PATCH] disallow empty location sequences --- src/bytecode.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bytecode.rs b/src/bytecode.rs index 68c562e..b57d2a4 100644 --- a/src/bytecode.rs +++ b/src/bytecode.rs @@ -1249,13 +1249,14 @@ impl Locations { } } None => { - if i & 1 == 0 && !suffix.is_empty() { + if i < 2 || (i & 1 == 0 && !suffix.is_empty()) { return Err(CompileError::InvalidLocation { loc }); } break; } } } + debug_assert!(values.len() >= 1); value_map.push((pos, values)); } @@ -1356,11 +1357,17 @@ fn test_locations_formats() { test_vals(&map! { 43 => "31_-24", 2 => "-2_-342", 6 => "23&" }).unwrap_err(); test_vals(&map! { 43 => "31_-24&", 2 => "-2_-342&", 6 => "23&" }).unwrap(); test_vals(&map! { 43 => "31::-24&", 2 => "-2::-342&", 6 => "23&" }).unwrap(); + test_vals(&map! { 43 => "31::-24&", 2 => "-2::-342&", 6 => "23&", 7 => "&" }).unwrap_err(); + test_vals(&map! { 43 => "31::-24&", 2 => "-2::-342&", 6 => "23&", 0 => "&" }).unwrap_err(); test_vals(&map! { 43 => "31::-24&", 2 => "-2::-342&", 6 => "23&" }).unwrap(); test_vals(&map! { 43 => "31::-24&", 2 => "-2::-342&", 6 => "23&&" }).unwrap_err(); test_vals(&map! { 43 => "<>31::-24&", 2 => "<>-2::-342:.:5::-22&", 6 => "<>23&" }).unwrap_err(); test_vals(&map! { 43 => "<>31::-24&", 2 => "<>-2::-342::5::-22&", 6 => "<>23&" }).unwrap(); + test_vals(&map! { 43 => "<>31::-24&", 2 => "<>-2::-342::5::-22&", 6 => "<>&" }).unwrap_err(); + test_vals(&map! { 43 => "<>31::-24&", 2 => "<>-2::-342::5::-22&", 0 => "<>&" }).unwrap_err(); test_vals(&map! { 43 => "<>31::-24&", 2 => "<>-2::-342::5::-22&", 6 => "<>23" }).unwrap_err(); + test_vals(&map! { 43 => "31,-24", 2 => "-2,-342,5,-22", 6 => "23", 7 => "" }).unwrap_err(); + test_vals(&map! { 43 => "31,-24", 2 => "-2,-342,5,-22", 6 => "23", 0 => "" }).unwrap_err(); } struct ByteCodeBuilder<'a: 'b, 'b> {