Skip to content

Avoid invalidated tag slices in codec validation - #10741

Merged
rtfeldman merged 1 commit into
mainfrom
issue-10695-derived-parse-tag-args
Aug 13, 2026
Merged

Avoid invalidated tag slices in codec validation#10741
rtfeldman merged 1 commit into
mainfrom
issue-10695-derived-parse-tag-args

Conversation

@rtfeldman

Copy link
Copy Markdown
Contributor

Derived parser validation held a borrowed tag-range slice across recursive type-store growth, so reallocation could corrupt the next tag's argument range and crash. Traverse tag and argument spans through stable indexed store access in both derived parse and encode validation, which also removes temporary per-tag allocations. Fixes #10695.

@rtfeldman
rtfeldman marked this pull request as ready for review August 13, 2026 00:08
@rtfeldman
rtfeldman merged commit c473cba into main Aug 13, 2026
19 of 21 checks passed
@rtfeldman
rtfeldman deleted the issue-10695-derived-parse-tag-args branch August 13, 2026 00:09
@greptile-apps

greptile-apps Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR replaces borrowed tag slices and temporary argument copies with stable indexed type-store traversal in derived parse and encode validation.

  • Iterates tag unions through getTagAt and getVarAt so recursive store growth cannot invalidate borrowed slices.
  • Adds and registers a regression test for the derived parse crash involving repeated aliased tag-union fields.

Confidence Score: 4/5

The PR appears safe to merge, with the non-blocking caveat that the encode-side traversal change should receive equivalent regression coverage.

The indexed access APIs preserve stable ranges and values across type-store reallocations, addressing the invalid borrowed-slice path; the remaining concern is limited to incomplete test coverage of the parallel encode implementation.

Files Needing Attention: src/check/Check.zig, src/check/test/issue_10695_test.zig

Important Files Changed

Filename Overview
src/check/Check.zig Safely converts parse and encode tag-union validation to index-based traversal; the encode-side change lacks matching regression coverage.
src/check/test/issue_10695_test.zig Adds a focused parse regression that checks the reported repeated-alias scenario completes without compiler errors.
src/check/mod.zig Registers the new issue regression test with the check test suite.

Reviews (1): Last reviewed commit: "Avoid invalidated tag slices in codec va..." | Re-trigger Greptile

Comment thread src/check/Check.zig
Comment on lines +31471 to +31474
for (0..tag_union.tags.count) |tag_offset| {
const tag_args_range = self.types.getTagAt(tag_union.tags, @intCast(tag_offset)).args;
for (0..tag_args_range.count) |tag_arg_offset| {
const tag_arg = self.types.getVarAt(tag_args_range, @intCast(tag_arg_offset));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Encode traversal lacks regression coverage

The encode tag-union traversal now uses the same indexed access strategy, but the regression source invokes only Json.parse. Add an encode case with recursive or repeatedly aliased tag-union fields so an encode-specific traversal regression does not pass undetected.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Out-of-range tag argument slice in validateDerivedParseTagUnion

1 participant