Skip to content

Fix Linux amd64 test23 SIGSEGV from an ambiguous buffer source assertion #708

Closed

Description

@LunaStev

Problem

PR #707 fails Cases Linux amd64 in tests/cases/linux/amd64/test23.wave: the program terminates with SIGSEGV (runner exit -11) instead of its expected success exit 42. The other 168 cases in that job passed, including all new shared cases.

The existing native regression assumes that buffer_append can always reject a source at exactly data + cap. That assumption conflicts with the #676 fix, which permits a separate, valid allocation to start at that address.

Evidence

The job reports:

RUN linux/amd64/test23.wave
FAIL (exit=-11, expected 42)

At test23.wave line 121, buf.len == buf.cap == 4 after the preceding self-append:

if (buffer_append(&buf, buf.data + buf.len, 1) != BUFFER_ERR_INVALID) {
    return 19;
}

No adjacent source allocation exists in this test. The supplied source is one past the buffer's logical allocation. The new half-open alias check classifies it as external. Growing the destination frees its old backing mapping; the subsequent mem_move reads through the now-unmapped source address.

A local debugger confirmed the crashing call chain:

mem_move -> buffer_append -> main

Focused reproduction and isolation

Use a compiler built from the PR head and a staged copy of the matching standard library, not an older installed wavec or std:

cargo build --locked --release --jobs 2
case_root="$(mktemp -d)"
mkdir -p "$case_root/home/.wave/lib/wave"
cp -R std "$case_root/home/.wave/lib/wave/std"
for opt in O0 O2; do
    HOME="$case_root/home" target/release/wavec build \
        tests/cases/linux/amd64/test23.wave "-$opt" \
        --emit=ir,obj,bin --out-dir "$case_root/$opt"
    "$case_root/$opt/test23"
done

The compiler requires the repository's usual LLVM 21 setup. A shell may report the signal as exit 139; the Python runner records it as -11.

Local isolated results, using the same current release compiler:

Standard library / test variant O0 O2
PR head, original test23 SIGSEGV (-11) SIGSEGV (-11)
Temporary std copy with only the old offset_value <= cap check restored 42 42
Current std, temporary test using buffer_append(&buf, buf.data + buf.len - 1, 2) for the invalid-range assertion 42 42

Restoring <= was an isolation experiment, not a proposed fix: it would reintroduce #676 by rejecting valid adjacent allocations. All experimental edits were confined to temporary copies; no follow-up code change has been submitted.

Scope

  • Update the native regression to reject an unambiguously internal source whose requested range exceeds initialized bytes, rather than assuming an address at data + cap identifies an invalid internal source. Starting at the last initialized byte and requesting two bytes is one verified candidate.
  • Preserve the invalid-range assertion and verify that rejection leaves buffer metadata and contents unchanged.
  • Clarify the source-range precondition in buffer_append API comments if needed: an external source must identify valid initialized bytes. Address comparisons alone cannot distinguish an invalid one-past pointer from the start of a valid adjacent allocation.
  • Retain the Do not classify an adjacent allocation as an internal buffer_append source #676 controlled-allocator coverage for adjacent allocations and self-appends across moving growth.

Do not skip test23, change its expected success exit, weaken self-append checks, or revert the half-open allocation test merely to make CI pass. No allocator redesign, case-manifest work, or broad CI changes are required.

Completion criteria

  • The complete Linux amd64 test23.wave exits 42 at both O0 and O2 with the revised assertion.
  • The invalid internal range is rejected before growth or copying, with buffer state preserved.
  • The controlled adjacent-allocation regression still passes at O0 and O2, including moving self-appends.
  • The Linux amd64 case job passes this case while preserving its explicit nonzero-success contract.

Related: #676, #707. The library boundary fix already exists in #707; this issue tracks the missing native regression update and associated contract clarification, not a duplicate implementation of #676.

Activity

  1. added
    bug
    needs testing
    ci
    on Sep 24, 2026
  2. self-assigned this
    on Sep 25, 2026
  3. added a commit that references this issue on Sep 25, 2026
    23d73e5
  4. added a commit that references this issue on Sep 25, 2026
    5002a93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcineeds testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions