Integer Overflow to Buffer Overflow

Draft Compound
Structure: Chain
Description

This vulnerability occurs when a program calculates the size of memory to allocate, but an integer overflow in that calculation results in a much smaller buffer being created than intended. This undersized buffer can then be overflowed by subsequent operations, corrupting adjacent memory.

Extended Description

At its core, this is a two-stage flaw. First, during a size calculation—like multiplying length by element size—an integer overflow wraps the result to a deceptively small number. The program then allocates a buffer based on this incorrect size, believing it's sufficient. The real danger follows when the application, operating on the original, larger data size, writes more data into this tiny buffer than it can hold, leading to a classic buffer overflow. Developers can prevent this by using strict input validation on all size calculations and employing safe integer operations or libraries that check for overflow before allocation. Always assume that arithmetic involving user-influenced values can overflow, and design memory allocation logic to fail safely rather than proceeding with a corrupted size.

Common Consequences 1
Scope: IntegrityAvailabilityConfidentiality

Impact: Modify MemoryDoS: Crash, Exit, or RestartExecute Unauthorized Code or Commands

Demonstrative Examples 1

ID : DX-33

The following image processing code allocates a table for images.

Code Example:

Bad
C
c
This code intends to allocate a table of size num_imgs, however as num_imgs grows large, the calculation determining the size of the list will eventually overflow (Integer Overflow or Wraparound). This will result in a very small list to be allocated instead. If the subsequent code operates on the list as if it were num_imgs long, it may result in many types of out-of-bounds problems (Improper Restriction of Operations within the Bounds of a Memory Buffer).
Observed Examples 2
CVE-2021-43537Chain: in a web browser, an unsigned 64-bit integer is forcibly cast to a 32-bit integer (Incorrect Conversion between Numeric Types) and potentially leading to an integer overflow (Integer Overflow or Wraparound). If an integer overflow occurs, this can cause heap memory corruption (Heap-based Buffer Overflow)
CVE-2017-1000121chain: unchecked message size metadata allows integer overflow (Integer Overflow or Wraparound) leading to buffer overflow (Improper Restriction of Operations within the Bounds of a Memory Buffer).