Skip to content

Fix segfault on empty input for neumaier and c sum types - #5

Open
billdenney wants to merge 2 commits into
mainfrom
fix-precisesums-empty-sum
Open

billdenney wants to merge 2 commits into
mainfrom
fix-precisesums-empty-sum

Conversation

@billdenney

Copy link
Copy Markdown
Contributor

PreciseSums_NeumaierSum and PreciseSums_DoubleSum read input[0] before their for(i=1;i<len;…) loop with no length guard, so psSum(numeric(0)) with sum type "neumaier" or "c" performs an out-of-bounds read and crashes R.

Reproducer: psSetSum("neumaier"); psSum(numeric(0)) → "An irrecoverable exception occurred".
Validation: valgrind → Invalid read of size 8 at PreciseSums_NeumaierSum (sum.c:124) ← _psSum (sum.c:373).
The other four algorithms already return 0 for empty input; this makes the two consistent. Verified: all six types now return 0 for empty input, unchanged for non-empty.

billdenney and others added 2 commits June 15, 2026 02:23
PreciseSums_NeumaierSum and PreciseSums_DoubleSum read input[0] before
the loop with no length guard, so psSum(numeric(0)) with sum type
'neumaier' or 'c' performed an out-of-bounds read and crashed R.
valgrind: Invalid read of size 8 at PreciseSums_NeumaierSum (sum.c:124)
called from _psSum (sum.c:373). The other sum types already return 0
for empty input; make these two consistent.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…gfault)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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