Skip to content

Do not classify an adjacent allocation as an internal buffer_append source #676

Closed

Description

@LunaStev

Problem

buffer_append detects sources inside its destination allocation so it can preserve their offset if buffer_reserve moves the allocation. The current membership check uses offset_value <= buf.cap, including the address immediately after the allocation.

A separate live allocation can begin at that address. Its first initialized byte is then misclassified as an internal source and rejected by the initialized-range check, even though the append is valid and the destination has enough capacity.

Code references:

Regression scenario

Arrange two separate, simultaneously live 16-byte allocations with no gap:

A.data = p,      A.len = 0, A.cap = 16
B.data = p + 16, B.len = 1, B.cap = 16
B.data[0] = 0x41

buffer_append(&A, B.data, 1)

Here B.data is obtained from B's own allocation, not by dereferencing a one-past pointer derived from A. Expected: BUFFER_OK, A.len == 1, and A.data[0] == 0x41, with B unchanged.

Tracing the current source gives offset_value == 16. The <= A.cap condition selects the internal-source branch, and offset > A.len returns BUFFER_ERR_INVALID. This case needs no destination growth and isolates the allocation-boundary classification.

This is a false rejection of valid input; it does not establish a memory-corruption result.

Scope

Use the half-open allocation interval [data, data + cap) for internal-source classification. Retain the subtraction-based address comparison so the check does not require potentially overflowing end-address arithmetic.

Keep initialized-source bounds checks and offset recovery across growth for actual internal sources. External pointers remain subject to the caller's existing obligation to provide size readable initialized bytes.

Completion criteria

  • A source from a separate live allocation beginning exactly at data + cap is accepted when the append otherwise satisfies the API contract.
  • Add an executable regression with deterministic adjacent allocations, such as a controlled allocator fixture or the existing WebAssembly allocation path after verifying the layout. Do not rely on host allocator luck or fabricated integer addresses.
  • Check the returned status, destination length and bytes, and unchanged source contents.
  • Preserve self-append and interior-slice append both with and without destination growth.
  • Preserve rejection of internal sources that extend beyond initialized bytes, plus existing zero-length, invalid-buffer, overflow, and allocation-failure behavior.
  • Keep the public API and allocator ownership rules unchanged; no libc binding or new external dependency is needed.

The adjacent-allocation scenario above describes the source-level failure path and the required runtime regression, not an already executed Wave test.

Activity

  1. added
    bug
    help wanted
    needs testing
    on Sep 21, 2026
  2. self-assigned this
    on Sep 24, 2026
  3. added a commit that references this issue on Sep 24, 2026
    01955d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bughelp wantedneeds testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions