Skip to content

Buffer Overflow

A memory-write failure in which data is written beyond the valid end of its intended buffer.

Version
v1 · 2026-10-03 · History
Domain-specific #
13034
Domain group
Applied Sciences & Engineering
Origin domain
Computer Science & Software Engineering
Subdomains
Memory Safety, Software Security → Computer Science & Software Engineering
Aliases
Buffer Overrun

Core Idea

A buffer overflow is a write beyond the valid end of an intended program-memory buffer. The destination has finite capacity, but the operation's effective write size or target position exceeds it. An unchecked copy is a classic cause, yet an output transformation can also grow beyond a reserved region even after the initial input length was checked.[ref-63364427a440][ref-2a4a054bfa77][^ref-6489fbcce7ff]

The invalid write defines the failure. It may corrupt state, crash the program or create a security risk, but no specific downstream consequence is required. Stack-local and heap-allocated buffers are variants. A larger input that is rejected or safely accommodated before any invalid write is not an overflow event.[ref-31f1c4f6d9ce][ref-6489fbcce7ff]

Scope of Application

MITRE's stack example has a fixed local destination and text whose copied length is not guaranteed to fit. Its heap example involves a reserved output region whose encoded text can expand beyond the allocation. They differ in storage and root cause but share the same failed relation: effective write demand exceeds the actual destination extent.[ref-31f1c4f6d9ce][ref-6489fbcce7ff]

The broader CWE-787 category also includes writes before a buffer's beginning; this entry uses the conventional forward-overrun sense. Out-of-bounds reading, arithmetic integer overflow and a full data queue handled under its stated policy are different conditions.[^ref-63364427a440]

Clarity

Ask what range belongs to the destination object and what range the operation actually writes, including transformations after any initial size check. This detects a failure more reliably than asking only whether external input was unusually long.[ref-2a4a054bfa77][ref-6489fbcce7ff]

Keep failure, detection and impact apart. LLVM's AddressSanitizer documents detection of out-of-bounds heap, stack and global accesses in instrumented runs. Detection in testing is useful, but it does not itself prove the bounds were correctly enforced in every deployed path.[^ref-23c4dea8ff1b]

Manages Complexity

One invariant—write only within the intended buffer's valid extent—unifies many surface forms. It lets a reviewer reason about stack and heap cases without assuming that every overflow uses the same copy operation, memory layout or impact chain.[ref-2a4a054bfa77][ref-31f1c4f6d9ce][^ref-6489fbcce7ff]

The invariant also clarifies defenses. Correct sizing or effective bounds enforcement prevents the invalid write. Detection tools expose exercised failures; deployment hardening may limit some consequences but does not change the underlying write-boundary requirement.[ref-2a4a054bfa77][ref-23c4dea8ff1b]

Abstract Reasoning

Identify the destination and its actual valid range, derive the effective output/write range, and compare them. If the program rejects excess data, truncates it explicitly or safely enlarges storage before writing, there is no buffer overflow on that path. If a write can pass the valid end, examine the upstream reason separately from the storage variant and possible effects.[ref-63364427a440][ref-6489fbcce7ff]

The safe design choice when content exceeds initial capacity may be rejection, explicit truncation or bounded growth. Fixed capacity constrains resource use; preserving all variable-length output may require more storage. Writing beyond the bound is not a valid compromise.[ref-2a4a054bfa77][ref-6489fbcce7ff]

Knowledge Transfer

The structural test transfers between a stack-local copy and a heap output transformation because both have an intended region, finite extent and effective write. It does not transfer literally to every use of “overflow”: an arithmetic wraparound or a full but correctly guarded queue need not write outside memory.[ref-31f1c4f6d9ce][ref-6489fbcce7ff]

Live prime Boundary is a proposed DAG prerequisite—the inside/outside extent makes “past the end” meaningful. The addressable memory object and invalid write keep Buffer Overflow domain-specific. Live Bounds Checking is a safeguard, not the same failure mode.

[^ref-63364427a440]: MITRE, CWE-787, “Out-of-bounds Write,” Description and Relationships. Official weakness definition. [^ref-2a4a054bfa77]: MITRE, CWE-120, “Buffer Copy without Checking Size of Input (‘Classic Buffer Overflow’),” Description and Potential Mitigations. Official weakness definition. [^ref-31f1c4f6d9ce]: MITRE, CWE-121, “Stack-based Buffer Overflow,” Description and Demonstrative Example 1. Official weakness definition. [^ref-6489fbcce7ff]: MITRE, CWE-122, “Heap-based Buffer Overflow,” Description and Demonstrative Example 2. Official weakness definition. [^ref-23c4dea8ff1b]: LLVM/Clang, “AddressSanitizer,” Introduction. Official documentation.

Relationships to Other Abstractions

Local relationship map for Buffer OverflowParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Buffer OverflowDOMAINPrime abstraction: Boundary — presupposesBoundaryPRIME

Current abstraction Buffer Overflow Domain-specific

Parents (1) — more general patterns this builds on

  • Buffer Overflow presupposes Boundary Prime

    A buffer overrun presupposes a valid memory-object boundary that a write crosses.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Buffer Overflow sits in a moderately populated region (58th percentile for distinctiveness): it has near-neighbors but no dense thicket of look-alikes.

Family — Program Execution & Runtime Concepts (27 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-10-08