Improve handling of serialization buffer overflows #3318
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refs tree-sitter/tree-sitter-julia#128
This is a bug in the Julia grammar's external scanner, where the scanner will write past the size of the serialization buffer. Previously, there was no explicit guard against this happening, it would just corrupt other state, and cause confusing crashes downstream.
Now, it is handled better in two different ways:
When running a parser natively, we can at least crash with a more informative error location if the scanner indicates that it has written beyond the end of the buffer:
When running a parser via WASM (e.g. in Zed), because the parser is only writing to the wasm memory, we can completely prevent a crash, and prevent it from affecting anything, except for failing the current parse.