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

198 results · Feed

  • 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.…

  • Medium 6.5

    A negative-size-param in tsMuxer version nightly-2024-04-05-01-53-02 allows attackers to cause Denial of Service (DoS) …

  • Medium 5.3

    The WBR-6012 is a wireless SOHO router. It is a low-cost device which functions as an internet gateway for homes and sm…

  • Medium 4.6

    Incorrect Calculation of Buffer Size (CWE-131) in the Controller 6000 and Controller 7000 OSDP message handling, allows…

  • Critical 9.1

    Multiple vulnerabilities in libnv

    A malicious value of size in a structure of packed libnv can cause an integer overflow, leading to the allocation of a smaller buffer than required for the parsed data.

  • 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…

  • Medium 5.5

    In wipe_ns_memory of nsmemwipe.c, there is a possible incorrect size calculation due to a logic error in the code. This…

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

  • Critical 9.0

    A vulnerability has been identified in the PostScript interpreter in various Lexmark devices.

    A memory corruption vulnerability has been identified in PostScript interpreter in various Lexmark devices. The vulnerability can be leveraged by an attacker to execute arbitrary code.

  • Critical 9.8

    An out-of-bounds write vulnerability exists in the sopen_FAMOS_read functionality of The Biosig Project libbiosig 2.5.0…

  • 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…

  • Medium 5.3

    Glibc: integer overflow in __vsyslog_internal()

    An integer overflow was found in the __vsyslog_internal function of the glibc library. This function is called by the syslog and vsyslog functions. This issue occurs when these functions are called with a very long message, leading to an incorrect calculation…

  • Critical 10.0

    IBM Merge Healthcare eFilm Workstation License Server CopySLS_Request3 Buffer Overflow

    A stack-based buffer overflow exists in IBM Merge Healthcare eFilm Workstation license server. A remote, unauthenticated attacker can exploit this vulnerability to achieve remote code execution with SYSTEM privileges.

  • Critical 10.0

    IBM Merge Healthcare eFilm Workstation License Server Buffer Overflow

    A buffer overflow exists in IBM Merge Healthcare eFilm Workstation license server. A remote, unauthenticated attacker can exploit this vulnerability to achieve remote code execution.

  • Unscored —

    libc stdio buffer overflow

    In versions of FreeBSD 12.4-RELEASE prior to 12.4-RELEASE-p7 and FreeBSD 13.2-RELEASE prior to 13.2-RELEASE-p5 the __sflush() stdio function in libc does not correctly update FILE objects' write space members for write-buffered streams when the write(2) syste…

  • 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…

  • Medium 6.5

    Apache Guacamole: Incorrect calculation of Guacamole protocol element lengths

    Apache Guacamole 1.5.1 and older may incorrectly calculate the lengths of instruction elements sent during the Guacamole protocol handshake, potentially allowing an attacker to inject Guacamole instructions during the handshake through specially-crafted data.

  • Critical 9.8

    RIOT-OS vulnerable to Buffer Overflow during IPHC receive

    RIOT-OS, an operating system that supports Internet of Things devices, contains a network stack with the ability to process 6LoWPAN frames. Prior to version 2022.10, an attacker can send a crafted frame to the device resulting in an out of bounds write in the…

  • 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

  • Medium 6.7

    In pqframework, there is a possible out of bounds write due to a missing bounds check. This could lead to local escalat…

  • 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 …

  • Medium 6.7

    In mtk-isp, there is a possible use after free due to a logic error. This could lead to local escalation of privilege w…

  • Medium 6.7

    In mtk-aie, there is a possible use after free due to a logic error. This could lead to local escalation of privilege w…

  • Medium 6.7

    In jpeg, there is a possible use after free due to a logic error. This could lead to local escalation of privilege with…

  • Medium 6.7

    In throttling, there is a possible out of bounds write due to an incorrect calculation of buffer size. This could lead …

  • Medium 6.7

    In throttling, there is a possible out of bounds write due to an incorrect calculation of buffer size. This could lead …

  • Medium 4.8

    Overflow in `tf.keras.losses.poisson` in Tensorflow

    TensorFlow is an open source platform for machine learning. `tf.keras.losses.poisson` receives a `y_pred` and `y_true` that are passed through `functor::mul` in `BinaryOp`. If the resulting dimensions overflow an `int32`, TensorFlow will crash due to a size m…

  • Medium 4.8

    Overflow in `FusedResizeAndPadConv2D` in Tensorflow

    TensorFlow is an open source platform for machine learning. When `tf.raw_ops.FusedResizeAndPadConv2D` is given a large tensor shape, it overflows. We have patched the issue in GitHub commit d66e1d568275e6a2947de97dca7a102a211e01ce. The fix will be included in…

  • Medium 4.8

    Overflow in `ImageProjectiveTransformV2` in Tensorflow

    TensorFlow is an open source platform for machine learning. When `tf.raw_ops.ImageProjectiveTransformV2` is given a large output shape, it overflows. We have patched the issue in GitHub commit 8faa6ea692985dbe6ce10e1a3168e0bd60a723ba. The fix will be included…

  • Medium 4.8

    Overflow in `ResizeNearestNeighborGrad` in Tensorflow

    TensorFlow is an open source platform for machine learning. When `tf.raw_ops.ResizeNearestNeighborGrad` is given a large `size` input, it overflows. We have patched the issue in GitHub commit 00c821af032ba9e5f5fa3fe14690c8d28a657624. The fix will be included …

  • Medium 6.5
    CVE-2022-31630 Public exploit

    OOB read due to insufficient input validation in imageloadfont()

    In PHP versions prior to 7.4.33, 8.0.25 and 8.1.12, when using imageloadfont() function in gd extension, it is possible to supply a specially crafted font file, such as if the loaded font is used with imagechar() function, the read outside allocated buffer wi…

  • 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…

  • Medium 6.8

    In typec, there is a possible out of bounds write due to an incorrect calculation of buffer size. This could lead to lo…