1. CVE archive
  2. Vulnerability types
  3. CWE-131
CWE-131 · #139 most frequent type in the archive

Incorrect Calculation of Buffer Size

The product does not correctly calculate the size to be used when allocating a buffer.

Part of: CWE-682 · Incorrect Calculation

183CVEs of this type in the archive
22critical (CVSS ≥ 9)
94high severity (7–8.9)
Dec 2, 2026latest published

What it is

The product does not correctly calculate the size to be used when allocating a buffer.

Impact on systems

ScopeImpact
Integrity, Availability, Confidentiality DoS: Crash, Exit, or Restart, Execute Unauthorized Code or Commands, Read Memory, Modify Memory
If the incorrect calculation is used in the context of memory allocation, then the software may create a buffer that is smaller or larger than expected. If the allocated buffer is smaller than expected, this could lead to an out-of-bounds read or write (CWE-119), possibly causing a crash, allowing arbitrary code execution, or exposing sensitive data.

How to prevent it

Implementation When allocating a buffer for the purpose of transforming, converting, or encoding an input, allocate enough memory to handle the largest possible encoding. For example, in a routine that converts & characters to & for HTML entity encoding, the output buffer needs to be at least 5 times as large as the input buffer.
Implementation Understand the programming language's underlying representation and how it interacts with numeric calculation (CWE-681). Pay close attention to byte size discrepancies, precision, signed/unsigned distinctions, truncation, conversion and casting between types, not-a-number calculations, and how the language handles numbers that are too large or too small for its underlying representation. Also be careful to account for 32-bit, 64-bit, and other potential differences that may affect the numeric representation.
Implementation · Input Validation Perform input validation on any numeric input by ensuring that it is within the expected range. Enforce that the input meets both the minimum and maximum requirements for the expected range.
Architecture and Design For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
Implementation When processing structured incoming data containing a size field followed by raw data, identify and resolve any inconsistencies between the size field and the actual size of the data (CWE-130).
Implementation When allocating memory that uses sentinels to mark the end of a data structure - such as NUL bytes in strings - make sure you also include the sentinel in your calculation of the total amount of memory that must be allocated.
Implementation Replace unbounded copy functions with analogous functions that support length arguments, such as strcpy with strncpy. Create these if they are not available.
Implementation Use sizeof() on the appropriate data type to avoid CWE-467.

Source: MITRE CWE catalog · Official entry on the MITRE website

CWE-131 CVEs published per year

2026: year in progress, updated every hour

Show the data as a table
YearCVE
20013
20021
20032
20043
20054
20081
20141
20173
20183
20194
202011
202114
202220
202311
202421
202515
202666

All CWE-131 CVEs

183 results

Dottor Marc

Is this type of vulnerability in your systems?

An archive tells you what exists; a Vulnerability Assessment tells you what is exposed on your side. Dottor Marc tests your web applications and network with automated and manual checks.