fix: crash when parsing heredocs with identifiers >= 256 chars#287
Open
look wants to merge 1 commit intotree-sitter:masterfrom
Open
fix: crash when parsing heredocs with identifiers >= 256 chars#287look wants to merge 1 commit intotree-sitter:masterfrom
look wants to merge 1 commit intotree-sitter:masterfrom
Conversation
The heredoc word length was serialized as a single byte, which silently truncated identifiers of >= 256 characters. The deserializer would then read the wrong length, leaving unread bytes in the buffer, and hit the assert(size == length) check.
look
commented
Feb 10, 2026
| for (uint32_t i = 0; i < scanner->open_heredocs.size; i++) { | ||
| Heredoc *heredoc = array_get(&scanner->open_heredocs, i); | ||
| if (size + 2 + heredoc->word.size >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) { | ||
| if (size + 3 + sizeof(uint32_t) + heredoc->word.size >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) { |
Author
There was a problem hiding this comment.
I believe 2 is incorrect in the old code: we write 3 bools below, not 2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I identified a crash in GitHub's symbol extraction system related to tree-sitter-ruby. Investigation revealed it was caused by very long HEREDOC identifiers (these are legal in Ruby, I checked...).
The heredoc word length was serialized as a single byte, which silently truncated identifiers of >= 256 characters. The deserializer would then read the wrong length, leaving unread bytes in the buffer, and hit the
assert(size == length)check.To fix, I adopted the approach used in tree-sitter-bash and tree-sitter-php: store the HEREDOC identifier length in a
uint32_t.This PR includes a reproduction test. If you run
tree-sitter testonmasterwithtest/corpus/literals.txtyou will get:On this branch, it is fixed.
Disclaimer: I used GitHub Copilot to help diagnose and fix this bug.