Skip to content
OpenAdvisories

Weakness (CWE)

CWE-131: Incorrect Calculation of Buffer Size

Base Draft

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

How to prevent it (8 mitigations)
  1. 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.

  2. 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. [REF-7]

    Also be careful to account for 32-bit, 64-bit, and other potential differences that may affect the numeric representation.

  3. Implementation

    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.

  4. 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.

  5. 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).

  6. 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.

  7. Implementation

    Replace unbounded copy functions with analogous functions that support length arguments, such as strcpy with strncpy. Create these if they are not available.

  8. Implementation

    Use sizeof() on the appropriate data type to avoid CWE-467.

Source: MITRE CWE-131

81 results · Clear filters · Feed

  • High 7.5

    NEMU (OpenXiangShan/NEMU) before v2025.12.r2 contains an improper instruction-validation flaw in its RISC-V Vector (RVV…

  • High 7.8

    GIMP JP2 File Parsing Heap-based Buffer Overflow Remote Code Execution Vulnerability

    GIMP JP2 File Parsing Heap-based Buffer Overflow Remote Code Execution Vulnerability. This vulnerability allows remote attackers to execute arbitrary code on affected installations of GIMP. User interaction is required to exploit this vulnerability in that th…

  • High 7.5

    Go JOSE affect by a panic in JWE decryption

    Go JOSE provides an implementation of the Javascript Object Signing and Encryption set of standards in Go, including support for JSON Web Encryption (JWE), JSON Web Signature (JWS), and JSON Web Token (JWT) standards. Prior to 4.1.4 and 3.0.5, decrypting a JS…

  • High 7.1

    FreeRDP: Persistent Cache bmpSize Desync - Heap OOB Write

    FreeRDP is a free implementation of the Remote Desktop Protocol. Prior to version 3.24.2, in persistent_cache_read_entry_v3() in libfreerdp/cache/persistent.c, persistent->bmpSize is updated before winpr_aligned_recalloc(). If realloc fails, bmpSize is inflat…

  • High 7.5

    FreeRDP: H.264 YUV Buffer Dimension Desync - Heap OOB Write

    FreeRDP is a free implementation of the Remote Desktop Protocol. Prior to version 3.24.2, in yuv_ensure_buffer() in libfreerdp/codec/h264.c, h264->width and h264->height are updated before the reallocation loop. If any winpr_aligned_recalloc() call fails, the…

  • High 7.5

    FreeRDP: ClearCodec resize_vbar_entry() Heap OOB Write

    FreeRDP is a free implementation of the Remote Desktop Protocol. Prior to version 3.24.2, in resize_vbar_entry() in libfreerdp/codec/clear.c, vBarEntry->size is updated to vBarEntry->count before the winpr_aligned_recalloc() call. If realloc fails, size is in…

  • High 7.5

    Incorrect boundary conditions in the Audio/Video: Web Codecs component

    Incorrect boundary conditions in the Audio/Video: Web Codecs component. This vulnerability was fixed in Firefox 149, Firefox ESR 140.9, Thunderbird 149, and Thunderbird 140.9.

  • High 7.1

    HTSlib BGZF index file reader has a heap buffer overflow

    HTSlib is a library for reading and writing bioinformatics file formats. GZI files are used to index block-compressed GZIP [BGZF] files. In the GZI loading function, `bgzf_index_load_hfile()`, it was possible to trigger an integer overflow, leading to an unde…

  • High 7.7

    A vulnerability in the processing of Galois/Counter Mode (GCM)-encrypted Internet Key Exchange version 2 (IKEv2) IPsec …

  • High 7.8

    GIMP ICNS File Parsing Heap-based Buffer Overflow Remote Code Execution Vulnerability

    GIMP ICNS File Parsing Heap-based Buffer Overflow Remote Code Execution Vulnerability. This vulnerability allows remote attackers to execute arbitrary code on affected installations of GIMP. User interaction is required to exploit this vulnerability in that t…

  • High 7.8

    HDF5 Affected by H5T__conv_struct_opt Heap Buffer Overflow

    HDF5 is software for managing data. Prior to version 1.14.4-2, an attacker who can control an `h5` file parsed by HDF5 can trigger a write-based heap buffer overflow condition. This can lead to a denial-of-service condition, and potentially further issues suc…

  • High 8.8

    Azure Monitor Agent Remote Code Execution Vulnerability

    Out-of-bounds write in Azure Monitor Agent allows an authorized attacker to execute code over a network.

  • High 8.8

    Incorrect Calculation of Buffer Size in SCE-Mink

    Memory corruption while processing a GP command response.

  • High 7.8

    Incorrect Calculation of Buffer Size in HLOS

    Memory corruption during PlayReady APP usecase while processing TA commands.

  • High 7.8

    Incorrect Calculation of Buffer Size in Video

    Memory corruption while processing video packets received from video firmware.

  • High 7.8

    OpenVM byte decomposition of pc in AUIPC chip can overflow

    OpenVM is a performant and modular zkVM framework built for customization and extensibility. In version 1.0.0, OpenVM is vulnerable to overflow through byte decomposition of pc in AUIPC chip. A typo results in the highest limb of pc being range checked to 8-b…

  • High 7.5

    CWE-131: Incorrect Calculation of Buffer Size vulnerability exists that could cause Denial-of-Service of the product wh…

  • High 7.5

    DoS caused due to wrong hash length returned for SHA2/224 algorithm

    In SiWx91x devices, the SHA2/224 algorithm returns a hash of 256 bits instead of 224 bits. This incorrect hash length triggers a software assertion, which subsequently causes a Denial of Service (DoS). If a watchdog is implemented, device will restart after w…

  • High 7.8

    In writeToParcel and createFromParcel of DcParamObject.java, there is a permission bypass due to a write size mismatch.…

  • High 7.5

    CODESYS: Incorrect calculation of buffer size can cause DoS on CODESYS OPC UA products

    An unauthenticated remote attacker can use a malicious OPC UA client to send a crafted request to affected CODESYS products which can cause a DoS due to incorrect calculation of buffer size.

  • High 7.5

    Junos OS: SRX 5000 Series with SPC2: Processing of specific crafted packets when ALG is enabled causes a transit traffic Denial of Service

    An Incorrect Calculation of Buffer Size vulnerability in Juniper Networks Junos OS SRX 5000 Series devices using SPC2 line cards while ALGs are enabled allows an attacker sending specific crafted packets to cause a transit traffic Denial of Service (DoS). Con…

  • High 7.5

    OpenBSD 7.4 and 7.3 m_split() network buffer kernel crash

    In OpenBSD 7.4 before errata 002 and OpenBSD 7.3 before errata 019, a network buffer that had to be split at certain length that could crash the kernel after receiving specially crafted escape sequences.

  • High 7.5

    OpenBSD 7.3 invalid l2tp message npppd crash

    In OpenBSD 7.3 before errata 016, npppd(8) could crash by a l2tp message which has an AVP (Attribute-Value Pair) with wrong length.

  • High 7.5

    F5 Application Visibility and Reporting module and BIG-IP Advanced WAF/ASM vulnerability

    Undisclosed requests can cause the Traffic Management Microkernel (TMM) to terminate. For the Application Visibility and Reporting module, this may occur when the HTTP Analytics profile with URLs enabled under Collected Entities is configured on a virtual ser…

  • High 7.6

    Unchecked user input length in the Zephyr WiFi shell module

    Unchecked user input length in /subsys/net/l2/wifi/wifi_shell.c can cause buffer overflows.

  • High 7.4
    CVE-2023-36824 EPSS 77%

    Heap overflow in COMMAND GETKEYS and ACL evaluation in Redis

    Redis is an in-memory database that persists on disk. In Redit 7.0 prior to 7.0.12, extracting key names from a command and a list of arguments may, in some cases, trigger a heap overflow and result in reading random heap memory, heap corruption and potential…

  • High 7.5

    Incorrect Calculation of Buffer Size in MODEM

    Information disclosure in modem due to buffer over-read while processing packets from DNS server

  • High 7.3

    Incorrect Calculation of Buffer Size in vim/vim

    Incorrect Calculation of Buffer Size in GitHub repository vim/vim prior to 9.0.1378.

  • High 7.5

    Array overrun in common path resolve code

    In PHP 8.0.X before 8.0.28, 8.1.X before 8.1.16 and 8.2.X before 8.2.3, core path resolution function allocate buffer one byte too small. When resolving paths with lengths close to system MAXPATHLEN setting, this may lead to the byte after the allocated buffe…

  • High 7.8

    A stack overflow flaw was found in the Linux kernel's SYSCTL subsystem in how a user changes certain kernel parameters …

  • High 7.0

    sysstat Incorrect Buffer Size calculation on 32-bit systems results in RCE via buffer overflow

    sysstat is a set of system performance tools for the Linux operating system. On 32 bit systems, in versions 9.1.16 and newer but prior to 12.7.1, allocate_structures contains a size_t overflow in sa_common.c. The allocate_structures function insufficiently ch…

  • High 7.5

    The Linux kernel NFSD implementation prior to versions 5.19.17 and 6.0.2 are vulnerable to buffer overflow. NFSD tracks…

  • High 8.1

    An out-of-bounds write vulnerability exists in the JPG Handle_JPEG420 functionality of Accusoft ImageGear 19.9. A speci…

  • High 7.8

    Linux kernel io_uring PROVIDE_BUFFERS MAX_RW_COUNT bypass

    The io_uring subsystem in the Linux kernel allowed the MAX_RW_COUNT limit to be bypassed in the PROVIDE_BUFFERS operation, which led to negative values being usedin mem_rw when reading /proc/<PID>/mem. This could be used to create a heap overflow leading to a…

  • High 8.1

    An out-of-bounds write vulnerability exists in the TIFF header count-processing functionality of Accusoft ImageGear 19.…

  • High 7.8
    CVE-2020-17087 Exploited Public exploit

    Windows Kernel Local Elevation of Privilege Vulnerability

    Windows Kernel Local Elevation of Privilege Vulnerability

    KEV Nov 3, 2021
  • High 8.1

    Undefined Behavior in bounded Crossbeam channel

    Crossbeam is a set of tools for concurrent programming. In crossbeam-channel before version 0.4.4, the bounded channel incorrectly assumes that `Vec::from_iter` has allocated capacity that same as the number of iterator elements. `Vec::from_iter` does not act…

  • High 8.2

    An exploitable code execution vulnerability exists in the fsck_chk_orphan_node functionality of F2fs-Tools F2fs.Fsck 1.…

  • High 7.5

    A vulnerability has been identified in OpenPCS 7 V8.1 (All versions), OpenPCS 7 V8.2 (All versions), OpenPCS 7 V9.0 (Al…

  • High 7.5
    CVE-2018-14618 EPSS 11%

    curl before version 7.61.1 is vulnerable to a buffer overrun in the NTLM authentication code. The internal function Cur…