Skip to content

Commit 49450bf

Browse files
committed
additionally check for crc
1 parent 021d1bc commit 49450bf

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

test-libz-rs-sys/src/deflate.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,9 @@ fn deflate_bound_gzip_header_help(
672672
}
673673

674674
#[test]
675-
fn gz_header_text_check() {
675+
fn gz_header_text_and_hcrc_check() {
676676
// when constructing the gz header flags, zlib-rs performed a check
677-
// for `text > 0` that should have been `text != 0`.
677+
// for `text > 0` that should have been `text != 0`, similarly for hcrc.
678678
let config = DeflateConfig {
679679
level: 9,
680680
method: Method::Deflated,
@@ -703,14 +703,14 @@ fn gz_header_text_check() {
703703
let strm = strm.assume_init_mut();
704704

705705
let mut header = gz_header {
706-
text: -16777216,
707-
time: 4278223747,
706+
text: -42,
707+
time: 0,
708708
os: 0,
709709
extra: core::ptr::null_mut(),
710710
extra_len: 0,
711711
name: [0u8].as_mut_ptr(),
712712
comment: [0u8].as_mut_ptr(),
713-
hcrc: 0,
713+
hcrc: -42,
714714
//
715715
xflags: 0,
716716
extra_max: 0,

zlib-rs/src/c_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl gz_header {
253253

254254
pub(crate) fn flags(&self) -> u8 {
255255
(if self.text != 0 { 1 } else { 0 })
256-
+ (if self.hcrc > 0 { 2 } else { 0 })
256+
+ (if self.hcrc != 0 { 2 } else { 0 })
257257
+ (if self.extra.is_null() { 0 } else { 4 })
258258
+ (if self.name.is_null() { 0 } else { 8 })
259259
+ (if self.comment.is_null() { 0 } else { 16 })

zlib-rs/src/deflate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2603,7 +2603,7 @@ pub fn deflate(stream: &mut DeflateStream, flush: DeflateFlush) -> ReturnCode {
26032603
stream.state.bit_writer.pending.extend(&bytes);
26042604
}
26052605

2606-
if gzhead.hcrc > 0 {
2606+
if gzhead.hcrc != 0 {
26072607
stream.adler = crc32(
26082608
stream.adler as u32,
26092609
stream.state.bit_writer.pending.pending(),

0 commit comments

Comments
 (0)