If we're using the minimum compression level of 0 (i.e. copy without compression), we'll get sent down the zlib_rs::deflate::algorithm::deflate_stored() and zlib_rs::deflate::algorithm::stored::read_buf_direct_copy() functions, which copy directly between user provided pointers.
We copy with std::ptr::copy_nonoverlapping() which invokes UB if the pointers are overlapping. Therefore the user's pointers need to be non-overlapping and it should be a documented invariant of libz_rs_sys::deflate().
Or perhaps we can just use std::ptr::copy() for any situations where we're copying between the user pointers. It is a very narrow case for a user to have to care about.
n.b. I identified this problem with LLM assistance (Claude Code+Opus 4.6) but made my own evaluation and description of the problem.
If we're using the minimum compression level of 0 (i.e. copy without compression), we'll get sent down the
zlib_rs::deflate::algorithm::deflate_stored()andzlib_rs::deflate::algorithm::stored::read_buf_direct_copy()functions, which copy directly between user provided pointers.We copy with
std::ptr::copy_nonoverlapping()which invokes UB if the pointers are overlapping. Therefore the user's pointers need to be non-overlapping and it should be a documented invariant oflibz_rs_sys::deflate().Or perhaps we can just use
std::ptr::copy()for any situations where we're copying between the user pointers. It is a very narrow case for a user to have to care about.n.b. I identified this problem with LLM assistance (Claude Code+Opus 4.6) but made my own evaluation and description of the problem.