oxc/crates/oxc_parser
overlookmotel 62bc8c5cea
fix(parser): error on source larger than 4 GiB (#1860)
`Token` and `Span` both represent `start` and `end` as `u32`.

This limits size of source which can be parsed to `u32::MAX`.


19577709db/crates/oxc_span/src/span.rs (L14-L20)

However, this constraint is currently not enforced.

In a release build, code will not panic on arithmetic overflow, so
`start`/`end` could wrap around back to zero if source is 4 GiB or more.

That'd produce nonsense spans. But worse, the lexer relies in some
places on `self.current.token.start` being correct, so if the value
wrapped around, possibly it'd keep rewinding to the start of the source
and lexing it again, causing an infinite loop.

In worst case, if for some reason an application's public API used OXC's
parser with user-supplied source code (parser-as-a-service!), this could
be exploited for denial of service.

This PR adds an assertion to catch this at the start of parsing instead.

This does add an extra instruction, but I imagine the effect will be
negligible compared to the work required to parse the code.
2024-01-02 11:05:28 +08:00
..
examples chore(clippy): enable undocumented_unsafe_blocks 2023-10-16 15:18:14 +08:00
src fix(parser): error on source larger than 4 GiB (#1860) 2024-01-02 11:05:28 +08:00
Cargo.toml chore(deps): bump the dependencies group with 11 updates (#1865) 2024-01-01 08:06:33 +00:00