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

Gzip support for inflate #33

Merged
merged 49 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
132e34d
Started on gzip header parsing
bramtweedegolf Jan 18, 2024
0945ccc
Head
bramtweedegolf Feb 5, 2024
1ab0732
Merge branch 'main' of github.com:memorysafety/zlib-rs into gzip-func…
bramtweedegolf Feb 5, 2024
f80de1b
WIP gzip in inflate
bramtweedegolf Feb 7, 2024
86d1de5
WIP gzip header parsing
bramtweedegolf Feb 12, 2024
3115734
Merge branch 'main' into gzip-functions
bramtweedegolf Feb 12, 2024
d76ad62
Update
bramtweedegolf Feb 14, 2024
5577607
Merge branch 'main' of github.com:memorysafety/zlib-rs into gzip-func…
bramtweedegolf Feb 14, 2024
93bb3d6
Some refactors
bramtweedegolf Feb 14, 2024
09a1ec8
Inflate gzip header processing WIP
bramtweedegolf Feb 14, 2024
3b2f507
Finished parsing header, needs testing
bramtweedegolf Feb 15, 2024
cd25f39
Finished and tested extra info header parsing
bramtweedegolf Feb 16, 2024
d9c006f
Remove some testing code
bramtweedegolf Feb 19, 2024
3dd25fb
Clippy
bramtweedegolf Feb 19, 2024
aa5b2b7
Updating inflate
bramtweedegolf Feb 19, 2024
326ff1f
Merge branch 'main' of github.com:memorysafety/zlib-rs into gzip-func…
bramtweedegolf Feb 19, 2024
627ef66
Added CRC for Gzip, started on gzip inflate tests
bramtweedegolf Feb 19, 2024
4d82912
Merge branch 'gzip-functions' into gzip-inflate
bramtweedegolf Feb 19, 2024
6c55789
Clippy
bramtweedegolf Feb 19, 2024
5e72cc1
Removed some superfluous comments
bramtweedegolf Feb 19, 2024
ae1da9f
Updated tests
bramtweedegolf Feb 19, 2024
492d30d
Removed debug statement
bramtweedegolf Feb 19, 2024
fb2d06b
Fixed some gzip header crc issues
bramtweedegolf Feb 20, 2024
c5c651e
Small fixes
bramtweedegolf Feb 20, 2024
a7edd5a
Code cleanup
bramtweedegolf Feb 20, 2024
b8ff9e9
Merge branch 'main' of github.com:memorysafety/zlib-rs into gzip-inflate
bramtweedegolf Feb 20, 2024
7450ff9
Fixed small issues and formatting
bramtweedegolf Feb 20, 2024
38a1acc
Merge
bramtweedegolf Feb 20, 2024
f1aeb67
Merge branch 'main' of github.com:memorysafety/zlib-rs into gzip-inflate
bramtweedegolf Feb 20, 2024
36c75e2
Small fixes, merge
bramtweedegolf Feb 20, 2024
c700c6d
copy the state.head field, safely
folkertdev Feb 20, 2024
7315cea
prevent a dangling pointer in tests
folkertdev Feb 20, 2024
1bdc318
fix potential overflow in gzip header code
folkertdev Feb 20, 2024
ee56ea3
cleanup
folkertdev Feb 20, 2024
f84f162
remove unsafety
folkertdev Feb 20, 2024
cd09821
sanity test: crc of no input is the start crc
folkertdev Feb 20, 2024
4aa60dc
fix bug in name/comment decode
folkertdev Feb 20, 2024
5caaf65
fix stored block not updating the crc checksum
folkertdev Feb 20, 2024
4af011e
enable the fuzzer for gzip
folkertdev Feb 20, 2024
1b26048
test basic gzip header inflate
folkertdev Feb 20, 2024
ed9f429
fix bug in inflateGetHeader
folkertdev Feb 20, 2024
0bde1be
more interesting gzip test
folkertdev Feb 20, 2024
5117a6a
fix alignment bug in crc32
folkertdev Feb 20, 2024
5fa94da
self.in_available is out of date
folkertdev Feb 20, 2024
02ca800
Merge remote-tracking branch 'origin/main' into gzip-inflate
folkertdev Feb 21, 2024
3291499
read name/comment even if there is no space for the comment
folkertdev Feb 21, 2024
f530986
always read the name/comment, even if there is no space
folkertdev Feb 21, 2024
fa3d8f2
an attempt to clean up the extra field logic
folkertdev Feb 21, 2024
e8d815d
clippy
folkertdev Feb 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions libz-rs-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::ffi::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void};

use zlib_rs::{
deflate::{DeflateConfig, DeflateStream, Method, Strategy},
inflate::{InflateConfig, InflateStream},
inflate::{GzipHeader, InflateConfig, InflateStream},
Flush, ReturnCode,
};

Expand Down Expand Up @@ -199,9 +199,18 @@ pub unsafe extern "C" fn inflateSetDictionary(
zlib_rs::inflate::set_dictionary(stream, dict) as _
}

// pub unsafe extern "C" fn inflateGetHeader(strm: z_streamp, head: gz_headerp) -> c_int {
// todo!("part of gzip support")
// }
// part of gzib
pub unsafe extern "C" fn inflateGetHeader(strm: z_streamp, head: gz_headerp) -> c_int {
bramtweedegolf marked this conversation as resolved.
Show resolved Hide resolved
if let Some(stream) = InflateStream::from_stream_mut(strm) {
if let Some(header) = GzipHeader::from_header_mut(head) {
zlib_rs::inflate::get_header(stream, header) as i32
} else {
ReturnCode::StreamError as _
}
} else {
ReturnCode::StreamError as _
}
}

// undocumented but exposed function
pub unsafe extern "C" fn inflateUndermine(strm: *mut z_stream, subvert: i32) -> c_int {
Expand Down
33 changes: 33 additions & 0 deletions zlib-rs/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,36 @@ pub const Z_HUFFMAN_ONLY: c_int = 2;
pub const Z_RLE: c_int = 3;
pub const Z_FIXED: c_int = 4;
pub const Z_DEFAULT_STRATEGY: c_int = 0;

#[repr(C)]
#[derive(Copy, Clone)]
pub struct gz_header {
bramtweedegolf marked this conversation as resolved.
Show resolved Hide resolved

/// true if contents is propably text
pub text: c_int,

/// modification time
pub time: z_size,
pub xflags: c_int,
pub os: c_int,

pub extra: *mut Bytef,
pub extra_len: uInt,
pub extra_max: uInt,

/// file name
pub name: *mut Bytef,
pub name_max: uInt,

/// comment
pub comment: *mut Bytef,
pub comment_max: uInt,

/// true for a header CRC16
pub hcrc: c_int,

/// true when done reading header
pub done: c_int,
}

pub type gz_headerp = *mut gz_header;
Loading
Loading