# GHSA-3832-PRH6-8CPM: inout 0.2.3: PaddedInOutBuf writes the padded tail block past a too-small output buffer (safe API)

- Database: GitHub
- Severity: medium (stated by ghsa, no CVSS score)
- Published: 2026-10-23
- Modified: 2026-10-23

## Affected versions

- inout (crates.io): 0.2.3

## Description

### Summary

inout 0.2.3 (released 2026-10-14, #1558) dropped the output-buffer size check for the padded tail block in `InOutBufReserved::into_padded_blocks`. In 0.2.2 that function returned `PadError` when the reserved output space was smaller than the tail block. In 0.2.3 the check is gone, but `PaddedInOutBuf::get_tail_block` still writes through `out_ptr.add(blocks_len)` under a SAFETY comment that assumes the space exists. A caller whose output buffer is too small for the padded tail gets an out-of-bounds write through a safe API. cipher 0.5's `encrypt_padded_b2b` reaches exactly this path (`InOutBufReserved::from_slices`, then `into_padded_blocks`, then `get_tail_block`) and documents that it returns `PadError` if the output buffer is not sufficient.

### Details

- 0.2.2 `src/reserved.rs`, `into_padded_blocks`: `let reserve_len = out_len - blocks_byte_len; if reserve_len < tail_block.len() { return Err(PadError); }`
- 0.2.3 `src/reserved.rs`, `into_padded_blocks`: this check is removed; `PaddedInOutBuf` now stores `out_ptr`, `blocks_len` and `tail_block`, and nothing compares against `out_len`.
- 0.2.3 `get_tail_block`: `let tail_out_ptr = self.out_ptr.add(self.blocks_len); InOut::from_raw(in_block, tail_out_ptr)`.
- `InOutBufReserved::from_slices` only checks `in.len() <= out.len()`, so a buffer with no room for the padding passes it.

## Suggested fix
Restore the `reserve_len < tail_block.len()` → `PadError` check in `into_padded_blocks` before building `PaddedInOutBuf`, and add a regression test with an output buffer one byte short of the padded length.

### Proof of concept

Cargo.toml dependencies: `inout = { version = "=0.2.3", features = ["block-padding"] }`, `block-padding = "=0.4.2"`, `hybrid-array = "0.4"`.

```rust
use block_padding::Pkcs7;
use hybrid_array::sizes::U16;

// 15 message bytes pad to one 16-byte block. The output slice is the first 15
// bytes of a 32-byte buffer: one byte short. backing[15] lies outside the slice.
fn main() {
    let msg = [0x11u8; 15];
    let mut backing = [0u8; 32];
    let reserved = inout::InOutBufReserved::from_slices(&msg, &mut backing[..15]).unwrap();
    match reserved.into_padded_blocks::<Pkcs7, U16>() {
        Err(_) => println!("PadError, refused"),
        Ok(mut padded) => {
            if let Some(mut tail) = padded.get_tail_block() {
                *tail.get_out() = [0xAA; 16].into();
            }
            println!("Ok, tail written; backing[15] (outside the slice) = {:#04x}", backing[15]);
        }
    }
}
```

Output (x86_64 Linux):
- inout 0.2.2: `PadError, refused`
- inout 0.2.3: `Ok, tail written; backing[15] (outside the slice) = 0xaa`

### Impact

 users of inout 0.2.3 with the `block-padding` feature, which includes every user of cipher 0.5's padded block-mode helpers. `BlockModeEncrypt::encrypt_padded` (via `InOutBufReserved::from_mut_slice`) and `encrypt_padded_b2b` (via `InOutBufReserved::from_slices`) both call `into_padded_blocks` and then write the tail block through `get_tail_block`. Both constructors only check that the output buffer is at least as long as the message, not that it has room for the padding.

## References

- https://github.com/RustCrypto/utils/security/advisories/GHSA-3832-prh6-8cpm

Page: https://cve.now/GHSA-3832-PRH6-8CPM

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
