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

Make sure inflateCopy() allocates window with the necessary buffer padding #1583

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

Dead2
Copy link
Member

@Dead2 Dead2 commented Sep 25, 2023

Make sure inflateCopy() allocates window with the necessary buffer for chunked operations.

Based on Chromium bugfix https://chromium-review.googlesource.com/c/chromium/src/+/4876445

@Dead2 Dead2 added the bug label Sep 25, 2023
@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (57a2ed9) 83.90% compared to head (a02e407) 83.91%.
Report is 6 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1583   +/-   ##
========================================
  Coverage    83.90%   83.91%           
========================================
  Files          133      133           
  Lines        10880    10873    -7     
  Branches      2805     2807    +2     
========================================
- Hits          9129     9124    -5     
  Misses        1048     1048           
+ Partials       703      701    -2     
Flag Coverage Δ
macos_clang 42.97% <ø> (ø)
macos_gcc 73.61% <33.33%> (-0.01%) ⬇️
ubuntu_clang 82.49% <66.66%> (-0.02%) ⬇️
ubuntu_clang_debug 82.12% <66.66%> (-0.02%) ⬇️
ubuntu_clang_inflate_allow_invalid_dist 82.14% <66.66%> (-0.02%) ⬇️
ubuntu_clang_inflate_strict 82.48% <66.66%> (-0.01%) ⬇️
ubuntu_clang_mmap 82.58% <66.66%> (-0.24%) ⬇️
ubuntu_clang_pigz 13.98% <0.00%> (+0.06%) ⬆️
ubuntu_clang_pigz_no_optim 11.52% <0.00%> (+0.01%) ⬆️
ubuntu_clang_pigz_no_threads 13.80% <0.00%> (+0.06%) ⬆️
ubuntu_clang_reduced_mem 83.92% <66.66%> (+1.01%) ⬆️
ubuntu_clang_toolchain_riscv ∅ <ø> (∅)
ubuntu_gcc 75.29% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_aarch64 77.39% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_aarch64_compat_no_opt 75.63% <33.33%> (-0.03%) ⬇️
ubuntu_gcc_aarch64_no_acle 76.16% <33.33%> (-0.01%) ⬇️
ubuntu_gcc_aarch64_no_neon 76.16% <33.33%> (-0.01%) ⬇️
ubuntu_gcc_armhf 77.16% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_armhf_compat_no_opt 75.61% <33.33%> (-0.01%) ⬇️
ubuntu_gcc_armhf_no_acle 77.11% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_armhf_no_neon 77.23% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_armsf 74.58% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_armsf_compat_no_opt 74.10% <50.00%> (+<0.01%) ⬆️
ubuntu_gcc_benchmark 73.56% <50.00%> (+0.15%) ⬆️
ubuntu_gcc_compat_no_opt 76.83% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_compat_sprefix 73.56% <50.00%> (-0.18%) ⬇️
ubuntu_gcc_m32 73.80% <50.00%> (+0.57%) ⬆️
ubuntu_gcc_mingw_i686 74.06% <50.00%> (+0.40%) ⬆️
ubuntu_gcc_mingw_x86_64 74.07% <50.00%> (+0.39%) ⬆️
ubuntu_gcc_mips 74.95% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_mips64 74.97% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_no_avx2 75.08% <33.33%> (+0.79%) ⬆️
ubuntu_gcc_no_ctz 74.63% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_no_ctzll 74.62% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_no_pclmulqdq 74.27% <33.33%> (+0.05%) ⬆️
ubuntu_gcc_no_sse2 75.22% <33.33%> (+0.67%) ⬆️
ubuntu_gcc_no_sse42 74.93% <33.33%> (+0.76%) ⬆️
ubuntu_gcc_o1 74.17% <33.33%> (-0.01%) ⬇️
ubuntu_gcc_osb ∅ <ø> (∅)
ubuntu_gcc_pigz 38.26% <0.00%> (+0.16%) ⬆️
ubuntu_gcc_pigz_aarch64 39.10% <0.00%> (-0.03%) ⬇️
ubuntu_gcc_ppc 73.90% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_ppc64 74.35% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_ppc64_power9 74.52% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_ppc64le 74.41% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_ppc64le_novsx 74.74% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_ppc64le_power9 74.30% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_ppc_no_power8 74.62% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_s390x 74.78% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_s390x_dfltcc 71.91% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_s390x_dfltcc_compat 73.99% <50.00%> (+<0.01%) ⬆️
ubuntu_gcc_s390x_no_crc32 74.58% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_sparc64 74.77% <50.00%> (-0.02%) ⬇️
ubuntu_gcc_sprefix 73.23% <50.00%> (-0.02%) ⬇️
win64_gcc 73.86% <50.00%> (-0.14%) ⬇️
win64_gcc_compat_no_opt 74.69% <50.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
inflate.c 93.78% <66.66%> (-0.05%) ⬇️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nmoinvaz
Copy link
Member

Looks ok to me. Alternatively, we could also just call:

err = inflate_ensure_window(copy);
if (err != Z_OK) {
   ZFREE_STATE(source, copy);
   return err;
}
ZCOPY_WINDOW(copy->window, state->window, (size_t)1U << state->wbits);

@Dead2
Copy link
Member Author

Dead2 commented Sep 25, 2023

@nmoinvaz I agree, that would be cleaner.
I hope this works correctly though, we don't actually have any good tests for inflatecopy I think, only the basic usage in infcover.

inflate.c Outdated Show resolved Hide resolved
@Dead2 Dead2 marked this pull request as draft September 25, 2023 22:58
@Dead2 Dead2 marked this pull request as ready for review September 25, 2023 23:05
@Dead2
Copy link
Member Author

Dead2 commented Sep 25, 2023

As a bonus, this reduces text size quite a bit.

Before:

   text    data     bss     dec     hex filename
 139932    1384       8  141324   2280c libz-ng.so.2

After:

   text    data     bss     dec     hex filename
 139708    1384       8  141100   2272c libz-ng.so.2

224 bytes less to potentially pollute the cache 😄

Copy link
Member

@nmoinvaz nmoinvaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Good now we just have one code path for inflate window creation.

@nmoinvaz
Copy link
Member

nmoinvaz commented Sep 26, 2023

Hmm, CI is failing.

inflate.c Outdated Show resolved Hide resolved
inflate.c Outdated Show resolved Hide resolved
@Dead2
Copy link
Member Author

Dead2 commented Sep 27, 2023

@iii-i I suspect this also affects DFLTCC systems, as inflateCopy() does not seem to call dfltcc_copy_inflate_state() before this PR. As far as I can tell it really only means it was missing some padding, but thought I ought to nudge you so you can have a look for yourself.
Interestingly I cannot see ZCOPY_WINDOW actually being used before this PR, so perhaps it was misplaced in a merge or something.

Copy link
Member

@nmoinvaz nmoinvaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Dead2 Dead2 merged commit 61e181c into develop Sep 29, 2023
263 of 264 checks passed
@iii-i
Copy link
Member

iii-i commented Oct 9, 2023

Hi, sorry, I somehow missed this. For what it's worth, the change looks good to me. ZCOPY_WINDOW was used here: https://github.com/zlib-ng/zlib-ng/pull/1583/files#diff-a4d1ad62d5ea3dd46bc58016d6a642b364511e75ac9647c4dd33ff9a906777c7L1353

@Dead2 Dead2 mentioned this pull request Oct 13, 2023
@Dead2 Dead2 deleted the inflatecopy-fix branch January 3, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants