Guard sbuf size calculations against int overflow#33
Open
billdenney wants to merge 3 commits into
Open
Conversation
`sAppendN`/`sAppend`/`addLine` (s and lProp paths) compute the new
allocation size as
int mx = sbb->o + 2 + n + SBUF_MXBUF;
where `n` is a user-controlled length. When `n` is large enough the
addition overflows `int` to a negative value; `R_Realloc` then
interprets that as a huge unsigned size and crashes (or fails) instead
of returning an informative R error.
Add a check `n > INT_MAX - <existing summands>` immediately before each
allocation expression, raising `string buffer size overflow: input too
large` (and `line array size overflow: too many lines` for the lProp
path) before the unsigned wrap can happen.
Mirror of the fix in rxode2 inst/include/sbuf.c. monolix2rx ships its
own copy of the same buffer routines so it is fixed independently.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Skipped by default because triggering the overflow needs a ~2.147 GB identifier string (~2.5 GB peak RAM during the test). Mirrors the test added to rxode2 and nonmem2rx for the same fix. Manual-run instructions are in the test body. 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 #33 +/- ##
==========================================
- Coverage 89.44% 89.44% -0.01%
==========================================
Files 60 60
Lines 6360 6368 +8
==========================================
+ Hits 5689 5696 +7
- 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.
sAppendN/sAppend/addLine(s and lProp paths) compute the new allocation size asint mx = sbb->o + 2 + n + SBUF_MXBUF;
where
nis a user-controlled length. Whennis large enough the addition overflowsintto a negative value;R_Reallocthen interprets that as a huge unsigned size and crashes (or fails) instead of returning an informative R error.Add a check
n > INT_MAX - <existing summands>immediately before each allocation expression, raisingstring buffer size overflow: input too large(andline array size overflow: too many linesfor the lProp path) before the unsigned wrap can happen.Mirror of the fix in rxode2 inst/include/sbuf.c. monolix2rx ships its own copy of the same buffer routines so it is fixed independently.