Conversation
GrigoryEvko
added a commit
to GrigoryEvko/tree-sitter-cpp
that referenced
this pull request
Sep 17, 2026
An object-like macro with a replacement list of one identifier expands to that identifier. When the identifier is the name of a function-like macro, the group after the alias is an argument list ([cpp.rescan] p1). In bde, `#define P_ BSLIM_TESTUTIL_P_` makes `P_(LINE)` a call of `BSLIM_TESTUTIL_P_`. The seed gave such an alias only the object-macro row. The rule of tree-sitter#370 reads an object row with no function row as a macro with no arguments, so the seed must also give the alias the function row of its target. The reader of the #define lines gives the identifier of such a list as the alias target. The collector gives each alias the macro kinds of each name on its chain of aliases. A chain that comes back to a name stops there. Over the 64 corpus projects, 53,624 names are aliases. In 38 projects, 6,710 seed rows get the word function-macro: WebKit 3,109, boost 2,120, llvm-project 420, mongo 217, root 112, pytorch 90, godot 78, hhvm 58, and 57 or less in each of the 30 other projects. The collector adds no row, removes no row, and changes no type word. The seed of simdjson does not change. The scanner of the base reads a macro row as a row with a macro bit, so no tree changes, with a seed or with no seed. One class stays open: an object-like macro with a list of more tokens that ends with the name of a function-like macro. A line scan finds 97 such names.
This branch has not been deployed
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