fix: reject oversized state in deserialize - #370
Open
dekobon wants to merge 1 commit into
Open
Conversation
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.
This PR seeks to fix #368 where in
src/scanner.c:135-143, we have the following function:Here the greater than zero check is insufficiently guarding memcpy.
The variable
Scanneris{ uint8_t delimiter_length; wchar_t delimiter[16] }(68 bytes total on Linux/macOS, of which 64 are the delimiter; 32 wherewchar_tis 2 bytes).Elsewhere in the file we check to ensure that
delimiter_length <= MAX_DELIMITER_LENGTH, but only in this function are we able to break that contract.I've taken this through ASan and have a PoC of breaking through this guard, but in interest of safety, I think this is all the information needed to see why we need a better guard here.
AI disclosure: used for debugging and running ASan, formatting, and verification - poorly written prose is 100% organic human
Thank you for the great work with tree-sitter!
Downstream issue prompting PR: dekobon/big-code-analysis#1058
Fixes #368