Skip to content

Commit

Permalink
fix overflow bug in resumption
Browse files Browse the repository at this point in the history
  • Loading branch information
V0ldek committed Oct 30, 2023
1 parent eca69c2 commit 858b344
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions crates/rsonpath-lib/src/classification/structural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,30 @@ mod tests {
assert_eq!(Some(Comma(30 + offset)), resumed_classifier.next().unwrap());
});
}

#[test]
fn resumption_at_block_boundary() {
use BracketType::*;
use Structural::*;

let simd = simd::configure();
config_simd!(simd => |simd| {
let mut json_string = "{".to_owned();
json_string += &" ".repeat(128);
json_string += "}";
let input = BorrowedBytes::new(json_string.as_bytes());
let iter = input.iter_blocks(&EmptyRecorder);
let quotes = simd.classify_quoted_sequences(iter);
let offset = input.leading_padding_len();

let mut classifier = simd.classify_structural_characters(quotes);

assert_eq!(Some(Opening(Curly, offset)), classifier.next().unwrap());

let resume_state = classifier.stop();
let mut resumed_classifier = simd.resume_structural_classification(resume_state);

assert_eq!(Some(Closing(Curly, 129 + offset)), resumed_classifier.next().unwrap());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ macro_rules! structural_classifier {
let block = state.block.map(|b| {
// SAFETY: target_feature invariant
let mut block = unsafe { classifier.classify(b.block) };
let idx_mask = <$mask_ty>::MAX << b.idx;
let idx_mask = <$mask_ty>::MAX.checked_shl(b.idx as u32).unwrap_or(0);
block.structural_mask &= idx_mask;

block
Expand Down

0 comments on commit 858b344

Please sign in to comment.