Capacity defines the writable range

A buffer provides a bounded storage region. Writing beyond it does not validly enlarge that buffer. The operation may corrupt another object or trigger a failure, depending on language rules and the execution environment.

Reading beyond a buffer is commonly distinguished as an over-read. Both concern bounds, but the performed accesses differ. In C, apparently accessible memory does not make an out-of-range array subscript or invalid pointer arithmetic legitimate.

References: [1] [2]

Validation must cover the actual access

A check must cover the index and length actually used. Testing only whether a signed index is below the array length can still admit negative indices. The existence of a bounds check does not establish that it rejects every invalid access.

SEI CERT also distinguishes the bounds of constituent arrays in multidimensional cases. An address apparently within a larger storage region does not automatically authorize a particular subscript. Correctness depends on the relevant object and access expression.

References: [1]

Detection complements access contracts

AddressSanitizer can report many out-of-bounds accesses in instrumented executions. Container size differs from allocated capacity; detecting some logical container overflows requires cooperation from the library rather than allocation boundaries alone.

Prevention also requires interfaces to express valid ranges and to stop invalid accesses on error paths. Dynamic detection provides evidence about executed behavior, complementing rather than replacing reasoning about object bounds, input constraints, and untested paths.

References: [2] [1]