Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
An integer overflow happens when an arithmetic result exceeds the range its type can hold and wraps around, producing a small value where a large one was expected and undermining the size checks built on it.

What Is an Integer Overflow?
An integer in a program occupies a fixed number of bits and can therefore hold a fixed range of values. When a calculation produces a result outside that range, the value does not grow; it wraps. A 32-bit unsigned addition that should yield 4,294,967,300 yields 4 instead. An integer overflow is that silent wraparound, and it matters because so much security logic is arithmetic: allocate this many bytes, copy that many elements, check that the offset is within the buffer.
if (len > max) passes while the subsequent copy uses a huge size. CWE-190 covers overflow and CWE-191 the underflow case.The dangerous pattern is almost always the same. A program reads a size from untrusted input, performs arithmetic on it, allocates memory based on the result, then copies data using the original size. Multiply a 32-bit element count by an element size and the product wraps, so malloc is asked for a small buffer while the copy loop writes the full amount, and the result is a heap overflow with attacker-controlled data.
SMBGhost, CVE-2020-0796, followed exactly this shape: an integer overflow in the SMBv3 compression handling of Windows 10 allowed remote code execution on an internet-reachable service, and Microsoft issued an out-of-band fix in March 2020. The Stagefright family in Android, including CVE-2015-3864, overflowed integer arithmetic in MPEG-4 metadata parsing and made a multimedia message enough to compromise a handset. The same shape appears constantly in image, video, and font parsers, which is why those components are now routinely sandboxed.
Outside security, the best-known example is the Ariane 5 launch failure of 4 June 1996, where converting a 64-bit floating point value to a 16-bit signed integer overflowed and the guidance system shut down. No attacker, same arithmetic.
Detection is harder than for a plain buffer overflow, because nothing is corrupted at the moment of the overflow itself and the consequence appears later, somewhere else. The tools that work are dynamic rather than inspectional. Build with the undefined behaviour sanitiser, using -fsanitize=integer or at least -fsanitize=signed-integer-overflow, and run the test suite and a fuzzing campaign against it. Fuzzers find these quickly because boundary values are exactly what they generate.
In code, the preventive patterns are well established:
__builtin_add_overflow and __builtin_mul_overflow, or allocation helpers such as calloc and reallocarray that perform the multiplication safely.size_t for sizes and counts, and avoid mixing signed and unsigned types in the same comparison; enable -Wconversion and -Wsign-compare to find where that happens.Memory-safe languages change the picture but do not eliminate it. Rust panics on overflow in debug builds and wraps in release builds unless you use the checked, saturating, or wrapping methods explicitly. Java and C# wrap silently by default. The difference is that the subsequent memory access is bounds-checked, so an overflow becomes an exception rather than a corrupted heap.
At Privia Security, we treat integer handling as a review focus in parsers, protocol implementations, and anything that processes length-prefixed data from a network. Our Penetration Test Services include source-assisted testing where the arithmetic around allocations is examined directly rather than inferred from behaviour.
No. Many overflows are harmless arithmetic bugs that produce a wrong number in a report. It becomes a security issue when the value feeds a memory allocation, a bounds check, an array index, or a financial or access control decision. The common dangerous pattern is size arithmetic on untrusted input, where a wrapped result causes a buffer to be allocated smaller than the data written into it.
Overflow is exceeding the maximum value a type can hold, so the result wraps to the low end of the range. Underflow, tracked as CWE-191, is going below the minimum, typically by subtracting from a small unsigned value, which produces a very large number. Subtracting a header length from a received packet size is the classic source of an exploitable underflow.
Because signed integer overflow is undefined behaviour in C and C++, so the compiler may assume it never occurs. A check written as a comparison that is only true after an overflow is therefore provably false under that assumption, and optimisation removes it. Use the checked arithmetic builtins or perform the comparison before the operation instead of relying on the wrapped result.
They contain the damage rather than preventing the arithmetic. Rust, Java, and C# all wrap or panic rather than corrupting memory, and their bounds-checked collections turn what would be a heap overflow in C into an exception. Logic errors remain possible, so financial calculations and size arithmetic still need checked operations and explicit range validation at the input boundary.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.