detecting-integer-overflow
Detects integer overflow and underflow vulnerabilities in arithmetic operations used for buffer sizing or allocation. Use when analyzing calculations, size computations, or investigating integer wraparound issues.
When & Why to Use This Skill
This Claude skill is a specialized security analysis tool designed to detect integer overflow and underflow vulnerabilities in source code. It focuses on identifying risky arithmetic operations—such as addition, multiplication, and subtraction—particularly when they are used for buffer sizing, memory allocation, or loop boundaries. By automating the detection of integer wraparound issues, it helps developers and security auditors prevent critical memory corruption bugs and logic errors before they reach production.
Use Cases
- Memory Allocation Audit: Identifying potential heap overflows by checking if size calculations for functions like malloc() are protected against integer overflows.
- Input Validation Review: Analyzing user-controlled variables used in arithmetic to ensure they cannot trigger unexpected wraparounds in array indexing or loop counters.
- Security Vulnerability Research: Assisting researchers in tracing the impact of arithmetic flaws to determine exploitability and assess the severity of potential security breaches.
- Automated Secure Coding Checks: Integrating into the code review process to flag unsafe bit shifts or subtractions that could lead to underflows in critical logic.
| name | detecting-integer-overflow |
|---|---|
| description | Detects integer overflow and underflow vulnerabilities in arithmetic operations used for buffer sizing or allocation. Use when analyzing calculations, size computations, or investigating integer wraparound issues. |
Integer Overflow Detection
Detection Workflow
- Identify arithmetic operations: Find addition, multiplication, subtraction, bit shifts on user-controlled values
- Check for overflow protection: Look for overflow checks before arithmetic, safe arithmetic functions, type conversions
- Trace to critical uses: Follow results to memory allocation sizes, buffer copy lengths, loop bounds, array indices
- Assess impact: Can overflow cause buffer overflow? Bypass security checks? Cause logic errors?
Key Patterns
- Addition/multiplication without overflow checks
- Subtraction that could underflow
- Integer overflow affecting malloc size
- Loop counter overflow
Output Format
Report with: id, type (addition/multiplication/underflow), severity, confidence, location, operation, operands, result used for, overflow check status, exploitability, impact, mitigation.
Severity Guidelines
- HIGH: Overflow affects memory allocation size
- MEDIUM: Overflow affects loop bounds or array indices
- LOW: Overflow with limited security impact
See Also
patterns.md- Detailed detection patterns and exploitation scenariosexamples.md- Example analysis cases and code samplesreferences.md- CWE references and mitigation strategies