Skip to content

fix: add integer overflow protection with minimal performance impact#123

Merged
jgowdy-godaddy merged 2 commits intomainfrom
fix-integer-overflow-issues
Mar 4, 2026
Merged

fix: add integer overflow protection with minimal performance impact#123
jgowdy-godaddy merged 2 commits intomainfrom
fix-integer-overflow-issues

Conversation

@jgowdy-godaddy
Copy link
Collaborator

Summary

  • Fixes 3 critical integer overflow vulnerabilities identified in code review
  • Uses performance-conscious approaches with branch prediction hints

Changes

  1. SetMaxStackAllocItemSize: Clamp values to [0, 1MB] range using std::max/min
  2. EstimateAsherahOutputSize: Add overflow check only for suspiciously large data (>1TB)
  3. AllocationSizeToMaxDataSize: Add buffer underflow check with unlikely branch hint

Performance Impact

  • Minimal overhead by using branch prediction hints (unlikely())
  • Overflow checks only trigger for edge cases
  • No performance impact on common code paths

Test plan

  • All existing tests pass
  • Manually tested with edge case values
  • No performance regression in benchmarks

🤖 Generated with Claude Code

@jgowdy-godaddy jgowdy-godaddy force-pushed the fix-integer-overflow-issues branch 2 times, most recently from 8e29030 to 70c5c05 Compare August 3, 2025 19:57
- SetMaxStackAllocItemSize: Clamp values to [0, 1MB] range using std::max/min
- EstimateAsherahOutputSize: Add overflow check only for suspiciously large data (>1TB)
- AllocationSizeToMaxDataSize: Add buffer underflow check with unlikely branch hint

All fixes use performance-conscious approaches with branch prediction hints
Fix arm64 build failure caused by undefined unlikely() macro.
The scoped_allocate.h file uses unlikely() but didn't include
hints.h where the macro is defined.
@jgowdy-godaddy jgowdy-godaddy force-pushed the fix-integer-overflow-issues branch from ae45b7c to 906f783 Compare March 4, 2026 19:31
@jgowdy-godaddy jgowdy-godaddy merged commit 6dbbc82 into main Mar 4, 2026
2 checks passed
@jgowdy-godaddy jgowdy-godaddy deleted the fix-integer-overflow-issues branch March 4, 2026 19:35
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.

2 participants