fix: guard vector byte-count multiplications against size overflow#38
Conversation
Automated security fix generated by Orbis Security AI
|
While the claim of no overflow check being there is correct, I fail to see why this is a CRITICAL vulnerability. An attached ASAN report + a POC would've been helpful to support your claims. |
|
Thanks, that’s fair feedback. I agree that “CRITICAL” is too strong without a concrete reproducer. The issue I was trying to address is narrower: several vector operations compute byte counts for I should have framed this as defensive integer-overflow hardening rather than a demonstrated critical vulnerability. I'll update the PR title/description accordingly, remove the “critical” wording, and keep the PR scoped as a robustness/MISRA-style bounds check. Would you be open to reviewing it under that framing? |
|
Your first few checks have checks placed on |
|
You’re right, I’ll remove the redundant zero-count checks where the function contract or earlier validation already guarantees that. I only need a non-zero denominator for the overflow expression, but if |
Both insert_range_into_vec and insert_range_fast_into_vec already return early when count == 0, so the division-by-zero guard in the overflow check is unnecessary. Addresses review feedback on PR brightprogrammer#38. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| } | ||
| } | ||
|
|
||
| if ((vec->length - start - count) != 0 && vec_aligned_size(vec, item_size) > SIZE_MAX / (vec->length - start - count)) { |
There was a problem hiding this comment.
the (vec->length - start - count) != 0 check is also redundant, MemMove returns early if provided length to move is 0.
Summary
This PR adds overflow checks before computing byte counts for vector memory operations.
Several vector insert/remove paths compute sizes, such as:
aligned_size * countcount * vec_aligned_size(vec)(vec->length - start - count) * vec_aligned_size(vec)These values are then passed to
MemMove/MemSet. If the multiplication overflowssize, the resulting byte count may no longer match the intended logical element count.This change adds explicit guards before those multiplications, so the operation fails early rather than proceeding with a wrapped size value.
This is intended as defensive robustness / integer-overflow hardening. It is not claiming a demonstrated exploitable vulnerability without a concrete reproducer.
Changes
Source/Misra/Std/Container/Vec.cVerification
Automated security fix by OrbisAI Security