CWE-122: Heap-based Buffer Overflow

VariantDraftExploit Likelihood: High

A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().

View on MITRE
Back to CWE Lookup

Technical Details

Structure
Simple
Vulnerability Mapping
ALLOWED

Applicable To

Languages
CC++Memory-Unsafe
Platforms

Source-backed guidance

Additional facts reviewed against primary or authoritative security sources.

Combine review and analysis around the CWE-122 trust boundary

MITRE identifies fuzzing, automated dynamic analysis as applicable detection approaches. Use them to pair each heap allocation with the intended element count and prove all later offsets, copies, and reallocation paths remain within that object. Require a reproducible source-to-sink or policy-to-enforcement trace, record coverage gaps, and confirm suspected findings dynamically where safe; no single scanner can establish complete coverage for this weakness.

CWE-122: detection methods and operational guidanceMITRE CWE

Eliminate heap-buffer overflows through memory-safe allocation and access

Prefer memory-safe languages and libraries for new components and migrate exposed unsafe code where practical. In remaining heap code, validate allocation-size arithmetic, retain the actual capacity with each allocation, and prove every index, copy, and terminator stays within that capacity. Exercise zero-length, resized, maximum-length, and one-past-the-end cases with static analysis and runtime memory-safety detection.

Secure by Design Alert: Eliminating Buffer Overflow VulnerabilitiesCISA

Apply lessons from CVE-2025-24993 in Microsoft Windows NTFS

NVD maps CVE-2025-24993 to CWE-122; a heap-based buffer overflow allowed an unauthorized attacker to execute code locally and was added to CISA’s Known Exploited Vulnerabilities catalog. Use the case to treat filesystem parsers as high-impact boundaries, validate all on-disk lengths before heap access, and fuzz mounted-image and local file inputs under memory instrumentation.

CVE-2025-24993 DetailNIST National Vulnerability Database

Prioritize CWE-122 using its 2025 CWE Top 25 evidence

CWE-122 ranked #16 in the 2025 CWE Top 25 with a score of 5.21. The ranking table recorded 6 mapped vulnerabilities in CISA KEV for this measurement window. Use the rank to prioritize systemic prevention, detection coverage, and recurring-root-cause metrics across the portfolio, while retaining asset exposure and business impact for individual finding severity decisions.

2025 CWE Top 25 Most Dangerous Software WeaknessesMITRE CWE

Stress heap object sizes under AddressSanitizer

Instrument native components with AddressSanitizer and test malformed size fields, integer-boundary values, exact-fit and one-past-the-end writes, reallocation failures, and parser recovery paths. Run both targeted regression cases and coverage-guided fuzzing. Fix the allocation or access invariant rather than suppressing the report, and review unexecuted pointer arithmetic separately.

AddressSanitizerLLVM Project

Frequently Asked Questions

What is CWE-122: Heap-based Buffer Overflow?+

CWE-122: Heap-based Buffer Overflow is a Common Weakness Enumeration (CWE) entry maintained by MITRE. A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().

What are the security consequences of Heap-based Buffer Overflow?+

If exploited, CWE-122 (Heap-based Buffer Overflow) it can compromise Availability, Integrity, Confidentiality, Access Control and Other, leading to outcomes such as DoS: Crash, Exit, or Restart, DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), Execute Unauthorized Code or Commands, Bypass Protection Mechanism and Modify Memory.

How do you prevent or mitigate Heap-based Buffer Overflow?+

Recommended mitigations for CWE-122 include: Pre-design: Use a language or compiler that performs automatic bounds checking. Use an abstraction library to abstract away risky APIs. Not a complete solution. Implement and perform bounds checking on input.

Which programming languages are affected by Heap-based Buffer Overflow?+

CWE-122 commonly affects C, C++ and Memory-Unsafe. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.

What are real-world examples of Heap-based Buffer Overflow?+

MITRE documents real CVEs mapped to CWE-122, including CVE-2025-46687, CVE-2021-43537, CVE-2007-4268, CVE-2009-2523 and CVE-2021-29529. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.

What is the difference between a CWE and a CVE?+

A CWE (Common Weakness Enumeration) like CWE-122 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.

Learn More

Advertisement