Skip to content

[clang] grow biniou input buffers for oversized AST strings - #2336

Merged
dulmarod merged 1 commit into
meta:mainfrom
VladimirMakaev:pr/clang-biniou-buffers-1126
Nov 27, 2026
Merged

dulmarod merged 1 commit into
meta:mainfrom
VladimirMakaev:pr/clang-biniou-buffers-1126

Conversation

@VladimirMakaev

Copy link
Copy Markdown
Contributor

Clang can export identifiers and type names longer than the initial AST input buffer.
Biniou's channel reader requires each token to fit and otherwise raises Invalid_argument.

Use a resizing refill callback that preserves unread bytes before delegating the existing
channel refill. Share this reader between piped and saved AST inputs. Geometric growth avoids
repeated small reallocations without buffering the entire stream.

For example, generate a valid identifier that previously crashed capture:

name = "v" + "x" * 70000
print(f"int {name}; int main() {{ return {name}; }}")

Limitations: a large token requires a correspondingly large contiguous allocation.

Test plan

Buffer growth with unread prefixes, multiple larger tokens, exact offsets and truncated-input
EOF; pipe and saved-file capture of a 70001-character identifier with full name preservation;
normal identifier regressions, complete suite and paired corpus reports/summaries.

Clang can export identifiers and type names longer than the initial AST input buffer.
Biniou's channel reader requires each token to fit and otherwise raises Invalid_argument.

Use a resizing refill callback that preserves unread bytes before delegating the existing
channel refill. Share this reader between piped and saved AST inputs. Geometric growth avoids
repeated small reallocations without buffering the entire stream.

For example, generate a valid identifier that previously crashed capture:

```python
name = "v" + "x" * 70000
print(f"int {name}; int main() {{ return {name}; }}")
```

Limitations: a large token requires a correspondingly large contiguous allocation.

## Test plan
Buffer growth with unread prefixes, multiple larger tokens, exact offsets and truncated-input
EOF; pipe and saved-file capture of a 70001-character identifier with full name preservation;
normal identifier regressions, complete suite and paired corpus reports/summaries.
@meta-cla meta-cla Bot added the CLA Signed label Nov 26, 2026
@dulmarod

Copy link
Copy Markdown
Contributor

biniou_input is declared and only used in tests, is the use coming in another diff?

@VladimirMakaev

Copy link
Copy Markdown
Contributor Author

biniou_input is already used here by validate_decl_from_channel in Capture.ml, which both the plugin pipe and saved Biniou files pass through. The .mli export lets the unit tests start with an 8-byte buffer to exercise growth and unread-byte preservation.

I rechecked the actual capture path with a 70,001-character identifier: both current main and the PR base raise Invalid_argument Bi_inbuf.refill_from_channel; this head captures it from both the pipe and a saved AST and preserves the full name in the IR. No later production-use diff is needed.

@dulmarod
dulmarod merged commit 8aa75ba into meta:main Nov 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants