Skip to content

[fix] regex: error on a group index that overflows int64 (LET-25)#164

Merged
vt128 merged 1 commit into
masterfrom
fix/let-25-regex-group-index
Jun 13, 2026
Merged

[fix] regex: error on a group index that overflows int64 (LET-25)#164
vt128 merged 1 commit into
masterfrom
fix/let-25-regex-group-index

Conversation

@vt128

@vt128 vt128 commented Jun 13, 2026

Copy link
Copy Markdown
Member

What

Match.group / start / end / span resolve their group selector through groupIndex, which called starlark.Int.Int64() and discarded the ok flag. For an index too large for int64, Int64() returns 0, so the bounds check passed and the call silently selected group 0 (the whole match) instead of erroring — m.group(1 << 70) returned the full match text.

Fix

Capture ok and reject an overflowing (or out-of-range) index with no such group, comparing as int64 to avoid truncation and formatting the original value (which prints as 0 via %d). groupIndex is the single chokepoint, so this fixes group/start/end/span together — matching CPython, which raises IndexError: no such group.

Test-first

A new section in regex_test.go asserts group/start/end/span all fail with no such group on 1 << 70; it passes for a normal index. Fails before the fix.

Verification

go test -race -count=2 ./..., go vet, gofmt -l clean, Docker golang:1.19 race run green.

Requirement: LET-25

Match.group/start/end/span resolve the group selector through
groupIndex, which called starlark.Int.Int64() and discarded the ok
flag. For an index too large for int64, Int64 returns 0, so the bounds
check passed and the call silently selected group 0 (the whole match)
instead of erroring — e.g. m.group(1 << 70) returned the full match.

Capture ok and reject the overflowing index with "no such group"
(compared as int64 to avoid truncation, formatted from the original
value). groupIndex is the single chokepoint, so this fixes group,
start, end and span together, matching CPython (IndexError: no such
group).

Test-first: a new section in regex_test asserts group/start/end/span
all fail on 1 << 70. Requirement: LET-25.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@codacy-production

codacy-production Bot commented Jun 13, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.02% coverage variation

Metric Results
Coverage variation +0.02% coverage variation (-1.00%)
Diff coverage 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (433eae0) 7692 7276 94.59%
Head commit (2486917) 7697 (+5) 7282 (+6) 94.61% (+0.02%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#164) 8 8 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Jun 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.41%. Comparing base (433eae0) to head (2486917).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #164      +/-   ##
==========================================
+ Coverage   93.39%   93.41%   +0.01%     
==========================================
  Files          49       49              
  Lines        6177     6177              
==========================================
+ Hits         5769     5770       +1     
+ Misses        260      258       -2     
- Partials      148      149       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vt128 vt128 merged commit dc7b1b0 into master Jun 13, 2026
12 checks passed
@vt128 vt128 deleted the fix/let-25-regex-group-index branch June 13, 2026 07:01
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.

1 participant