FFORGE//RS
← Roadmap

rust / LEVEL 5

The empty C buffer that was still null

EST.50 MIN
01

THEORY / RETRIEVAL

What to restore

  • Separate ABI layout from pointer-validity obligations
  • Handle a foreign null pointer for an empty collection before slice creation
  • Keep unsafe scope local and copy borrowed foreign memory into Rust ownership

An ABI declaration is a promise

Rust 2024 requires external blocks to be declared `unsafe extern` because their signatures cannot be checked against the foreign implementation. Shared structs need an agreed representation such as `#[repr(C)]`; Rust references, String and Vec are not generic C ABI data types.

A zero-length Rust slice still cannot start at null

`slice::from_raw_parts` requires a non-null aligned pointer even when len is zero. Foreign APIs may legally represent an empty collection as null, so the boundary must return an empty Rust value before calling `from_raw_parts`. For non-empty input, the caller still owes validity, alignment and lifetime; a small unsafe block records that proof locally.

CHECKPOINT

Which obligations belong in a Rust wrapper that accepts a borrowed C pointer-length pair?

Select every applicable option. Credit requires an exact set match.

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / CODE REVIEW

Make the code safe

Repair `copy_from_ffi` so `(null, 0)` and every zero-length view return an empty Vec without forming a slice, non-empty null input is rejected, oversized input is rejected before reading, and valid foreign bytes are copied into Rust-owned memory. Preserve the ABI type and safety contract.

Initializing editor…
CLOUD SANDBOXnetwork off · 256 MB · 12 s
1 / 64 KB
OUTPUT
Runner is waiting for a submission.