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

Fix bug in release builds in read::Encoder #21

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading