The product writes data past the end, or before the beginning, of the intended buffer.
View on MITREWrite operations could cause memory corruption. In some cases, an adversary can modify control data such as return addresses in order to execute unexpected code.
Attempting to access out-of-range, invalid, or unauthorized memory could cause the product to crash.
Subsequent write operations can produce undefined or unexpected results.
No mitigation information available for this CWE.
No detection method information available for this CWE.
In the following code, it is possible to request that memcpy move a much larger segment of memory than assumed:
If returnChunkSize() happens to encounter an error it will return -1. Notice that the return value is not checked before the memcpy operation (CWE-252), so -1 can be passed as the size argument to memcpy() (CWE-805). Because memcpy() assumes that the value is unsigned, it will be interpreted as MAXINT-1 (CWE-195), and therefore will copy far more memory than is likely available to the destination buffer (CWE-787, CWE-788).
This code takes an IP address from the user and verifies that it is well formed. It then looks up the hostname and copies it into a buffer.
This function allocates a buffer of 64 bytes to store the hostname. However, there is no guarantee that the hostname will not be larger than 64 bytes. If an attacker specifies an address which resolves to a very large hostname, then the function may overwrite sensitive data or even relinquish control flow to the attacker.
This code applies an encoding procedure to an input string and stores it into a buffer.
The programmer attempts to encode the ampersand character in the user-controlled string. However, the length of the string is validated before the encoding procedure is applied. Furthermore, the programmer assumes encoding expansion will only expand a given character by a factor of 4, while the encoding of the ampersand expands by 5. As a result, when the encoding procedure expands the string it is possible to overflow the destination buffer if the attacker provides a string of many ampersands.
In the following C/C++ code, a utility function is used to trim trailing whitespace from a character string. The function copies the input string to a local character string and uses a while statement to remove the trailing whitespace by moving backward through the string and overwriting whitespace with a NUL character.
However, this function can cause a buffer underwrite if the input character string contains all whitespace. On some systems the while statement will move backwards past the beginning of a character string and will call the isspace() function on an address outside of the bounds of the local buffer.
The following code allocates memory for a maximum number of widgets. It then gets a user-specified number of widgets, making sure that the user does not request too many. It then initializes the elements of the array using InitializeWidget(). Because the number of widgets can vary for each request, the code inserts a NULL pointer to signify the location of the last widget.
However, this code contains an off-by-one calculation error (CWE-193). It allocates exactly enough space to contain the specified number of widgets, but it does not include the space for the NULL pointer. As a result, the allocated buffer is smaller than it is supposed to be (CWE-131). So if the user ever requests MAX_NUM_WIDGETS, there is an out-of-bounds write (CWE-787) when the NULL is assigned. Depending on the environment and compilation settings, this could cause memory corruption.
The following is an example of code that may result in a buffer underwrite. This code is attempting to replace the substring "Replace Me" in destBuf with the string stored in srcBuf. It does so by using the function strstr(), which returns a pointer to the found substring in destBuf. Using pointer arithmetic, the starting index of the substring is found.
In the case where the substring is not found in destBuf, strstr() will return NULL, causing the pointer arithmetic to be undefined, potentially setting the value of idx to a negative number. If idx is negative, this will result in a buffer underwrite of destBuf.
Font rendering library does not properly handle assigning a signed short value to an unsigned long (CWE-195), leading to an integer wraparound (CWE-190), causing too small of a buffer (CWE-131), leading to an out-of-bounds write (CWE-787).
View DetailsThe reference implementation code for a Trusted Platform Module does not implement length checks on data, allowing for an attacker to write 2 bytes past the end of a buffer.
View DetailsChain: insufficient input validation (CWE-20) in browser allows heap corruption (CWE-787), as exploited in the wild per CISA KEV.
View DetailsGPU kernel driver allows memory corruption because a user can obtain read/write access to read-only pages, as exploited in the wild per CISA KEV.
View DetailsChain: integer truncation (CWE-197) causes small buffer allocation (CWE-131) leading to out-of-bounds write (CWE-787) in kernel pool, as exploited in the wild per CISA KEV.
View DetailsOut-of-bounds write in kernel-mode driver, as exploited in the wild per CISA KEV.
View DetailsEscape from browser sandbox using out-of-bounds write due to incorrect bounds check, as exploited in the wild per CISA KEV.
View DetailsMemory corruption in web browser scripting engine, as exploited in the wild per CISA KEV.
View Detailschain: mobile phone Bluetooth implementation does not include offset when calculating packet length (CWE-682), leading to out-of-bounds write (CWE-787)
View DetailsChain: compiler optimization (CWE-733) removes or modifies code used to detect integer overflow (CWE-190), allowing out-of-bounds write (CWE-787).
View Detailsmalformed inputs cause accesses of uninitialized or previously-deleted objects, leading to memory corruption
View Detailschain: -1 value from a function call was intended to indicate an error, but is used as an array index instead.
View DetailsBuffer underflow from a small size value with a large buffer (length parameter inconsistency, CWE-130)
View DetailsChain: integer signedness error (CWE-195) passes signed comparison, leading to heap overflow (CWE-122)
View DetailsClassic stack-based buffer overflow in media player using a long entry in a playlist
View DetailsHeap-based buffer overflow in media player using a long entry in a playlist
View DetailsNo relationship information available for this CWE.
CWE-787: Out-of-bounds Write is a Common Weakness Enumeration (CWE) entry maintained by MITRE. The product writes data past the end, or before the beginning, of the intended buffer.
Yes. CWE-787 ranked #2 in the CWE Top 25 for 2024, associated with 3,842 CVEs that year. The CWE Top 25 highlights the most common and impactful software weaknesses based on real-world vulnerability data.
If exploited, CWE-787 (Out-of-bounds Write) it can compromise Integrity, Availability and Other, leading to outcomes such as Modify Memory, Execute Unauthorized Code or Commands, DoS: Crash, Exit, or Restart and Unexpected State.
CWE-787 commonly affects C, C++ and Assembly. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.
MITRE documents real CVEs mapped to CWE-787, including CVE-2025-27363, CVE-2023-1017, CVE-2021-21220, CVE-2021-28664 and CVE-2020-17087. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.
A CWE (Common Weakness Enumeration) like CWE-787 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.
Search for vulnerabilities that exploit CWE-787
See how this weakness ranks against others
Understanding vulnerabilities vs weaknesses
How vulnerability severity is measured
Complete technical details and references