Skip to content

Undocumented safety invariant in deflate #495

@inahga

Description

@inahga

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions