Closed inahga closed 4 weeks ago
That sounds good. I don't think that step 5 is needed, at least not right now.
Also set_header()
is just not a great API from a rust perspective, but we need it to implement the C api, so marking it as unsafe looks like the right solution.
It's possible to trigger UB/segfaults from safe Rust when using
set_header()
.Example:
In this case, looks like we trash the heap as libc SIGABRTs us with
corrupted size vs. prev_size
.Similarly UB can be triggered by providing non-null-terminated strings to
name
andcomment
, e.g. by errantly usingString::as_mut_ptr()
. These are particularly nefarious because I've been able to write code that doesn't crash.I'd suggest the following fixes:
set_header()
as unsafe.gz_header
at its definition.set_header()
that the requirements forgz_header
must be fulfilled.libz-rs-sys::deflateSetHeader()
the requirements forgz_header
must be fulfilled (right now it only notes that the pointer should be NULL or dereferencable).gz_header
, but that might not be strictly required for this crate's use cases).(I'm happy to make these fixes myself, just checking with you first).