Skip to content

Fix C API pointer provenance under Miri#191

Merged
oyvindln merged 5 commits intoFrommi:masterfrom
lopopolo:codex/fix-c-api-provenance
Apr 22, 2026
Merged

Fix C API pointer provenance under Miri#191
oyvindln merged 5 commits intoFrommi:masterfrom
lopopolo:codex/fix-c-api-provenance

Conversation

@lopopolo
Copy link
Copy Markdown
Contributor

@lopopolo lopopolo commented Apr 4, 2026

Summary

Miri rejected several C API entry points in miniz_oxide_c_api as UB.

The bug pattern was the same in each case: take a raw pointer, turn it into a &u8 or &mut u8, and then widen that one-byte reference into a larger slice with slice::from_raw_parts or slice::from_raw_parts_mut.

That is not a sound way to construct the slice. This PR constructs the slices directly from the original raw pointers instead.

Changes

  • add targeted #[test] witnesses for the failing Miri paths
  • fix pointer-to-slice conversion in tdefl_compress
  • fix the tdef callback bridge to pass out.as_ptr() instead of &(out[0])
  • fix input/output slice construction in StreamOxide::try_new
  • fix input slice construction in mz_adler32
  • fix input slice construction in mz_crc32
  • simplify zero-length slice handling in tdef

Testing

Ran:

cargo test -p miniz_oxide_c_api --lib miri_witness -- --nocapture
cargo +nightly miri test -p miniz_oxide_c_api --lib miri_witness -- --nocapture

Both pass.

Attribution

OpenAI Codex implemented the witnesses and fixes.

@lopopolo reviewed and validated the work.

@lopopolo lopopolo changed the title [codex] Fix C API pointer provenance under Miri Fix C API pointer provenance under Miri Apr 4, 2026
@lopopolo lopopolo marked this pull request as ready for review April 4, 2026 19:50
@oyvindln oyvindln merged commit cfe87c1 into Frommi:master Apr 22, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants