Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade flate2 integration to v0.3.0 #200

Closed
Shnatsel opened this issue Sep 26, 2024 · 4 comments
Closed

Upgrade flate2 integration to v0.3.0 #200

Shnatsel opened this issue Sep 26, 2024 · 4 comments

Comments

@Shnatsel
Copy link

Shnatsel commented Sep 26, 2024

It would be nice to upgrade flate2 to use v0.3.0 of zlib-rs, since it contains important fixes such as #165, #169, #172

I've attempted a naive bump from v0.2.1 to v0.3.0, but after running the flate2 roundtrip fuzzer I found that deflateInit2 now returns Z_VERSION_ERROR when called from flate2.

You can reproduce the issue by running the following command in flate2 repository with the attached file:

cargo +nightly fuzz run fuzz_gz_roundtrip /path/to/roundtrip_failing_input

roundtrip_failing_input.fake_extension_to_make_github_accept_upload.pdf

This will work fine with zlib-rs 0.2.1 but fail with 0.3.0, complaining about an assertion failure on this line:
https://github.com/rust-lang/flate2-rs/blob/6fbd6d21151d0948ed94be8ac99b412d30315109/src/ffi/c.rs#L325

@folkertdev
Copy link
Collaborator

I suspect you've missed

-    const ZLIB_VERSION: &'static str = "0.1.0\0";
+    const ZLIB_VERSION: &'static str = "1.3.0-zlib-rs-0.3.0\0";

in src/ffi/c.rs? You can now (via some macro magic) find the version string in our documentation https://docs.rs/libz-rs-sys/0.3.0/libz_rs_sys/fn.zlibVersion.html, though I don't think changes to the version will be relevant in the future.

With that line added, your example input works

     Running `fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_gz_roundtrip -artifact_prefix=/home/folkertdev/rust/flate2-rs/fuzz/artifacts/fuzz_gz_roundtrip/ /home/folkertdev/Downloads/roundtrip_failing_input.fake_extension_to_make_github_accept_upload.pdf`
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 595841439
INFO: Loaded 1 modules   (25753 inline 8-bit counters): 25753 [0x5d9bece1aaf0, 0x5d9bece20f89), 
INFO: Loaded 1 PC tables (25753 PCs): 25753 [0x5d9bece20f90,0x5d9bece85920), 
fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_gz_roundtrip: Running 1 inputs 1 time(s) each.
Running: /home/folkertdev/Downloads/roundtrip_failing_input.fake_extension_to_make_github_accept_upload.pdf
Executed /home/folkertdev/Downloads/roundtrip_failing_input.fake_extension_to_make_github_accept_upload.pdf in 1 ms
***
*** NOTE: fuzzing was not performed, you have only
***       executed the target code on a fixed set of inputs.
***

where in the fuzzer's Cargo.toml I changed this line

-flate2 = { path = ".." }
+flate2 = { path = "..", default-features=false, features=["zlib-rs"] }

and in the main Cargo.toml I changed

-libz-rs-sys = { version = "0.2.1", optional = true, default-features = false, features = ["std", "rust-allocator"] }
+libz-rs-sys = { version = "0.3.0", optional = true, default-features = false, features = ["std", "rust-allocator"] }

Does that work on your machine?

@Shnatsel
Copy link
Author

Ah, so I did! I did not realize changing that was required, thanks! It does work correctly now.

I'll open a PR to upgrade flate2 to v0.3.0

@Shnatsel
Copy link
Author

PR is up: rust-lang/flate2-rs#428

@folkertdev
Copy link
Collaborator

seems like this is resolved and the updated version will be merged soon, so I'm closing this

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

No branches or pull requests

2 participants