Skip to content

Use size_t for getLine column accumulator to prevent int overflow#35

Open
billdenney wants to merge 2 commits into
mainfrom
fix/mem-getline-col-overflow
Open

Use size_t for getLine column accumulator to prevent int overflow#35
billdenney wants to merge 2 commits into
mainfrom
fix/mem-getline-col-overflow

Conversation

@billdenney
Copy link
Copy Markdown
Contributor

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.

billdenney and others added 2 commits May 1, 2026 21:26
`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
Copy link
Copy Markdown

codecov Bot commented May 3, 2026

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.44%. Comparing base (ca1ffea) to head (849b320).

Files with missing lines Patch % Lines
src/parseSyntaxErrors.h 77.77% 2 Missing ⚠️
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.
📢 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.

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