Use size_t for getLine column accumulator to prevent int overflow#35
Open
billdenney wants to merge 2 commits into
Open
Use size_t for getLine column accumulator to prevent int overflow#35billdenney wants to merge 2 commits into
billdenney wants to merge 2 commits into
Conversation
`getLine` (src/parseSyntaxErrors.h) walks `src` to find the column of a syntax error. The column accumulator was a signed `int col` and the subsequent allocation was `R_Calloc(col + 1, char)`. On a source line wider than INT_MAX bytes, `col` wraps to a negative int; the allocation either fails or is undersized, and the following `memcpy(buf, src + i, col)` writes past the buffer. Switch the accumulator to `size_t`, add an explicit `col == INT_MAX` guard inside the column-counting loop, and add an `i + col > INT_MAX` overflow check before the cast back to `int` for the R_Calloc call. Adds tests/testthat/test-mem-getline-col-overflow.R as a regression test. The boundary test is `skip()`ed because it requires constructing an INT_MAX-byte single-line input. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #35 +/- ##
==========================================
- Coverage 89.44% 89.44% -0.01%
==========================================
Files 60 60
Lines 6360 6365 +5
==========================================
+ Hits 5689 5693 +4
- Misses 671 672 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
getLine(src/parseSyntaxErrors.h) walkssrcto find the column of a syntax error. The column accumulator was a signedint coland the subsequent allocation wasR_Calloc(col + 1, char). On a source line wider than INT_MAX bytes,colwraps to a negative int; the allocation either fails or is undersized, and the followingmemcpy(buf, src + i, col)writes past the buffer.Switch the accumulator to
size_t, add an explicitcol == INT_MAXguard inside the column-counting loop, and add ani + col > INT_MAXoverflow check before the cast back tointfor the R_Calloc call.Adds tests/testthat/test-mem-getline-col-overflow.R as a regression test. The boundary test is
skip()ed because it requires constructing an INT_MAX-byte single-line input.