Skip to content

Commit

Permalink
Fix bug in release builds in read::Encoder (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesgranger authored Sep 30, 2024
1 parent 6d8921f commit e02dfd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
run: cargo install cross --git https://github.com/cross-rs/cross --rev 6d097fb

- name: Build
run: cross build --target ${{ matrix.target }} -vv
run: cross build --target ${{ matrix.target }} --release -vv

- name: Test
run: cross test --target ${{ matrix.target }} -vv
run: cross test --target ${{ matrix.target }} --release -vv

test-wasm32-emscripten:
runs-on: ubuntu-latest
Expand All @@ -60,7 +60,7 @@ jobs:
uses: mymindstorm/setup-emsdk@v14

- name: Build
run: cargo build --target wasm32-unknown-emscripten --no-default-features --features ${{ matrix.build }}
run: cargo build --release --target wasm32-unknown-emscripten --no-default-features --features ${{ matrix.build }}

test-native:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -97,9 +97,9 @@ jobs:
run: brew install automake autoconf coreutils libtool nasm

- name: Test (shared)
run: cargo test --no-default-features --features shared --lib -vv
run: cargo test --release --no-default-features --features shared --lib -vv

- name: Test (static)
run: |
cargo clean # ensure we're starting fresh, no funny business
cargo test --no-default-features --features static -vv
cargo test --release --no-default-features --features static -vv
33 changes: 16 additions & 17 deletions src/igzip/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,25 @@ impl<R: io::Read> io::Read for Encoder<R> {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
// Check if there is data left in out_buf, otherwise refill; if end state, return 0
if self.stream.stream.internal_state.state != isal::isal_zstate_state_ZSTATE_END {
if self.stream.stream.avail_in == 0 {
// Read out next buf len worth to compress; filling intermediate out_buf
self.stream.stream.avail_in = self.inner.read(&mut self.in_buf)? as _;
self.stream.stream.next_in = self.in_buf.as_mut_ptr();
self.stream.stream.end_of_stream =
(self.stream.stream.avail_in < self.in_buf.len() as _) as _;
}
if self.stream.stream.internal_state.state != isal::isal_zstate_state_ZSTATE_END
&& (self.stream.stream.avail_in == 0
|| self.stream.stream.internal_state.state
!= isal::isal_zstate_state_ZSTATE_TMP_FLUSH_ICF_BUFFER)
{
// Read out next buf len worth to compress; filling intermediate out_buf
self.stream.stream.avail_in = self.inner.read(&mut self.in_buf)? as _;
self.stream.stream.next_in = self.in_buf.as_mut_ptr();
self.stream.stream.end_of_stream =
(self.stream.stream.avail_in < self.in_buf.len() as _) as _;
}

// compress this chunk into out_buf
self.stream.stream.avail_out = buf.len() as _;
self.stream.stream.next_out = buf.as_mut_ptr();
self.stream.stream.avail_out = buf.len() as _;
self.stream.stream.next_out = buf.as_mut_ptr();

self.stream.deflate()?;
self.stream.deflate()?;

let nbytes = buf.len() - self.stream.stream.avail_out as usize;
Ok(nbytes)
} else {
Ok(0)
}
let nbytes = buf.len() - self.stream.stream.avail_out as usize;
Ok(nbytes)
}
}

Expand Down

0 comments on commit e02dfd0

Please sign in to comment.