[fix] regex: error on a group index that overflows int64 (LET-25)#164
Conversation
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>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
🟢 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 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
What
Match.group/start/end/spanresolve their group selector throughgroupIndex, which calledstarlark.Int.Int64()and discarded theokflag. For an index too large for int64,Int64()returns0, 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
okand reject an overflowing (or out-of-range) index withno such group, comparing asint64to avoid truncation and formatting the original value (which prints as0via%d).groupIndexis the single chokepoint, so this fixesgroup/start/end/spantogether — matching CPython, which raisesIndexError: no such group.Test-first
A new section in
regex_test.goassertsgroup/start/end/spanall fail withno such groupon1 << 70; it passes for a normal index. Fails before the fix.Verification
go test -race -count=2 ./...,go vet,gofmt -lclean, Dockergolang:1.19race run green.Requirement: LET-25