# GHSA-qwgh-2vcv-g2f7: block_buffer: panic corrupts inline buffer position

> A caught panic in block_buffer can corrupt internal cursor positions, leading to out-of-bounds memory access and potential code execution.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Not stated
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 19 Aug 2026

## What is GHSA-qwgh-2vcv-g2f7?

GHSA-qwgh-2vcv-g2f7 is a memory corruption vulnerability in block_buffer, published on 19 Aug 2026. 

### Official description

### Summary

A caught panic may leave the cursor position of `EagerBuffer` or `ReadBuffer` in a corrupted state; this in turn allows out-of-bounds reads/writes.

### Details & PoC

The following two tests fail miri:

```rust
#[cfg(miri)]
#[test]
fn eager_digest_blocks_panic_corrupts_inline_position() {
    // `EagerBuffer` stores its cursor in the last byte of the internal block.
    // When `digest_blocks` completes a previously partial block, it overwrites
    // that byte with input data before invoking the caller-provided `compress`
    // callback. If the callback panics, safe code can catch the panic and keep
    // using the buffer while its cursor byte no longer satisfies the internal
    // `pos < block_size` invariant. Under Miri this `get_pos` call reaches the
    // `unreachable_unchecked` used for the assumed-valid cursor.
    let mut buf = EagerBuffer::<U4>::new(&[1, 2]);

    let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
        buf.digest_blocks(&[3, 0xff], |_| panic!("simulated compression failure"));
    }));

    let _ = buf.get_pos();
}

#[cfg(miri)]
#[test]
fn read_buffer_generator_panic_corrupts_inline_position() {
    // `ReadBuffer` stores its cursor in `buffer[0]`, but `write_block` gives
    // `gen_block` mutable access to the whole internal block before restoring
    // `buffer[0]` to a valid cursor. If `gen_block` writes an arbitrary first
    // byte and panics, safe code can catch the panic and later observe an
    // invalid cursor. Under Miri this `get_pos` call reaches the
    // `unreachable_unchecked` used for the assumed-valid cursor.
    let mut buf = ReadBuffer::<U4>::default();

    let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
        buf.write_block(
            1,
            |block| {
                block[0] = 0xff;
                panic!("simulated block generation failure");
            },
            |_| {},
        );
    }));

    let _ = buf.get_pos();
}
```

They fail on an `unreachable_unchecked!()` under the invariant for the `pos` to always be within bounds of the block.

### Impact

While the byte that overwrites `pos` may come from untrusted input and is therefore attacker-controlled, this still relies on the surrounding code catching the panic and carrying on, which should be uncommon in practice.

For this to be exploitable, the attacker also needs a way to trigger a panic here; I have not investigated how feasible that is.

### Credits

The issue was discovered by GPT-5.5

## Which versions are affected by GHSA-qwgh-2vcv-g2f7?

2 open source packages ship an affected version, including block_buffer.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `block_buffer` | crates.io | All versions | 0.12.1 |
| `block_buffer` | crates.io | All versions | 0.12.1 |

## How do I fix GHSA-qwgh-2vcv-g2f7?

Upgrade block_buffer to 0.12.1 or later.

## Is GHSA-qwgh-2vcv-g2f7 being exploited?

There is no known exploitation of GHSA-qwgh-2vcv-g2f7 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-qwgh-2vcv-g2f7 and fix it if it is affected.

What it is: GHSA-qwgh-2vcv-g2f7 is a memory corruption vulnerability in block_buffer, published on 19 Aug 2026. 
Exploitation: There is no known exploitation of GHSA-qwgh-2vcv-g2f7 in the wild and no public exploit code.

Affected packages and fixed versions:
- block_buffer (crates.io): affected all versions; fixed in 0.12.1
- block_buffer (crates.io): affected all versions; fixed in 0.12.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-qwgh-2vcv-g2f7/ (Markdown: https://insights.sbomify.com/GHSA-qwgh-2vcv-g2f7/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-qwgh-2vcv-g2f7

---
From sbomify Insights: https://insights.sbomify.com/GHSA-qwgh-2vcv-g2f7/
Summaries are generated and may contain mistakes; the official description above is the record.
