Skip to content

Truly independent web browser

LibJS: Offset into the tail of a reparsed source with wrapping_add

Shannon Boothc425b2430abf
diff --git a/Libraries/LibJS/Parser/Rust/src/base.rs b/Libraries/LibJS/Parser/Rust/src/base.rs
index a8bc61c1812..8b028453bf8 100644
--- a/Libraries/LibJS/Parser/Rust/src/base.rs
+++ b/Libraries/LibJS/Parser/Rust/src/base.rs
@@ -333,6 +333,8 @@ pub struct Parser<'a, 'k, U: Unit> {
pub(crate) validate_regex: ValidateRegex,
/// How many bindings of the function being parsed have a place in its summary.
pub(crate) summary_ordinal: u32,
+ /// Where the unit at offset 0 of the source is. A parse of a function again may have only a tail of the source,
+ /// which puts this outside of what it can read.
pub(crate) src: *const U,
pub len: u32,
pub(crate) pos: u32,
diff --git a/Libraries/LibJS/Parser/Rust/src/lexer.rs b/Libraries/LibJS/Parser/Rust/src/lexer.rs
index 11e41632d19..7d42e7c3561 100644
--- a/Libraries/LibJS/Parser/Rust/src/lexer.rs
+++ b/Libraries/LibJS/Parser/Rust/src/lexer.rs
@@ -60,20 +60,20 @@ impl<'a: 'k, 'k, U: Unit> Parser<'a, 'k, U> {
#[inline(always)]
pub fn at(&self, index: usize) -> u32 {
// SAFETY: The lexer never goes further than one block into the padding.
- unsafe { (*self.src.add(index)).code() }
+ unsafe { (*self.src.wrapping_add(index)).code() }
}
/// The source text from `start` up to `end`.
pub(crate) fn source_view(&self, start: usize, end: usize) -> &[U] {
debug_assert!(start <= end && end <= self.len as usize);
// SAFETY: The range is within the source.
- unsafe { ak::slice_from_raw_parts(self.src.add(start), end - start) }
+ unsafe { ak::slice_from_raw_parts(self.src.wrapping_add(start), end - start) }
}
#[inline(always)]
fn block(&self, index: usize) -> Block {
// SAFETY: As for at().
- unsafe { U::load(self.src.add(index)) }
+ unsafe { U::load(self.src.wrapping_add(index)) }
}
#[inline(always)]