Fix init/state registration correctness - #67
Merged
Conversation
asonje
force-pushed
the
fix/init-state-registration
branch
from
August 4, 2026 21:37
c7be4d4 to
3816ae6
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes correctness issues in the zlib interposition layer by ensuring per-stream/per-file shim state is only registered/used when zlib has actually accepted/owns that state, preventing stale map entries and incorrect EOF reporting.
Changes:
- Make
deflateInit_/deflateInit2_/inflateInit_/inflateInit2_register stream settings only when the underlying zlib init returnsZ_OK. - Fix
gzeofto defer toorig_gzeof()on the zlib path (or when unregistered), and to avoid reporting EOF while shim buffers still contain unread data. - Add unit tests covering both
gzeoffixes and update an existing test comment to reflect the new init/registration behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| zlib_accel.cpp | Registers per-stream settings only on successful init; fixes gzeof behavior for both zlib and accelerator paths. |
| tests/zlib_accel_test.cpp | Adds GzipFileTest coverage for gzeof on zlib path and buffered-data cases; updates existing test rationale text. |
Suppressed comments (1)
tests/zlib_accel_test.cpp:1531
- Same issue here: the test updates global config and relies on reaching the bottom of the function to restore it. A failing ASSERT in the middle will leave non-default config set for subsequent tests. Add an on-scope-exit restorer right after saving the values.
const uint32_t saved_iaa = GetConfig(USE_IAA_UNCOMPRESS);
const uint32_t saved_qat = GetConfig(USE_QAT_UNCOMPRESS);
const uint32_t saved_zlib = GetConfig(USE_ZLIB_UNCOMPRESS);
const uint32_t saved_iaa_compress = GetConfig(USE_IAA_COMPRESS);
const uint32_t saved_qat_compress = GetConfig(USE_QAT_COMPRESS);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1470
to
+1475
| const uint32_t saved_iaa = GetConfig(USE_IAA_UNCOMPRESS); | ||
| const uint32_t saved_qat = GetConfig(USE_QAT_UNCOMPRESS); | ||
| const uint32_t saved_zlib = GetConfig(USE_ZLIB_UNCOMPRESS); | ||
| const uint32_t saved_iaa_compress = GetConfig(USE_IAA_COMPRESS); | ||
| const uint32_t saved_qat_compress = GetConfig(USE_QAT_COMPRESS); | ||
| const uint32_t saved_zlib_compress = GetConfig(USE_ZLIB_COMPRESS); |
- deflateInit_, deflateInit2_, inflateInit_, inflateInit2_: call the original zlib init function first and only register stream settings in the map on Z_OK. Previously settings were registered unconditionally, so a failed init left a stale entry keyed by a z_streamp the app may free -- it never calls the matching End -- and a rejected re-init overwrote the settings of a stream zlib had left valid and usable. - gzeof: fall through to orig_gzeof() when the file has no map entry or is on the ZLIB path. reached_eof is only maintained by the accelerator read path, so on the zlib path it stayed false forever and gzeof never reported EOF, causing infinite read loops. - gzeof: on the accelerator path, do not report EOF while data_buf or io_buf still hold bytes gzread has not returned. reached_eof only records that a read() of the file came up short, so while (!gzeof(fp)) gzread(...) exited early and silently truncated with a success return: 4096 of 8192 bytes on an 8KB file read in 4KB chunks. gzeof now checks the same buffer state gzread already does. Adds two GzipFileTest cases, one per gzeof fix, each verified to fail with its hunk reverted. Co-authored-by: Mulugeta Mammo <mulugeta.mammo@intel.com> Signed-off-by: Mulugeta Mammo <mulugeta.mammo@intel.com> Signed-off-by: Olasoji <olasoji.denloye@intel.com>
asonje
force-pushed
the
fix/init-state-registration
branch
from
August 4, 2026 22:26
3816ae6 to
3a34c39
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
deflateInit_,deflateInit2_,inflateInit_,inflateInit2_: call the original zlib init function first and only register stream settings onZ_OK. Previously settings were registered unconditionally, so a failed init left a stale entry keyed by az_streampthe app may free (it never calls the matchingEnd), and a rejected re-init overwrote the settings of a stream zlib had left valid and usable.gzeof: two fixes, same root cause —reached_eofwas trusted where the shim does not fully maintain it.orig_gzeof()when the file has no map entry or is on theZLIBpath.reached_eofis only maintained by the accelerator read path, so on the zlib path it stayed false forever andgzeofnever reported EOF, causing infinite read loops.data_buf/io_bufstill hold bytesgzreadhas not returned.reached_eofonly records that aread()of the file came up short, sowhile (!gzeof(fp)) gzread(...)exited early and silently truncated with a success return. Measured: 4096 of 8192 bytes on an 8KB file read in 4KB chunks.gzeofnow checks the same buffer stategzreadalready does.Tests: two
GzipFileTestcases, one pergzeoffix, each verified to fail with its hunk reverted. Full suite with QAT+IAA+IGZIP on real hardware: 28703 tests, 24383 passed, 4320 skipped, 0 failed.Rebased onto
mainafter #65; depends on its null guards, since conditional registration means a failed*Initleaves no map entry.