Skip to content

Prevent undersized bundled zlib allocations - #1565

Open
bmehta001 wants to merge 2 commits into
mainfrom
bhamehta/guard-zlib-allocation
Open

bmehta001 wants to merge 2 commits into
mainfrom
bhamehta/guard-zlib-allocation

Conversation

@bmehta001

@bmehta001 bmehta001 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Security hardening

Fix the bundled zlib allocation-size calculation identified by the cpp/integer-multiplication-cast-to-long CodeQL alert. The normal allocator now rejects products that its allocation argument cannot represent and multiplies at the appropriate width; the existing 16-bit calloc path is unchanged. Exploitability through supported SDK APIs has not been established.

Add a mocked-allocator regression test for normal, zero, failed and boundary allocations. Run it in the existing CTest suite and explicitly on Win32 in CI, where overflow rejection can be exercised. Keep the existing vendored-zlib warning suppression: removing it breaks builds that enable additional consumer warning flags such as -Wconversion -Werror.

Validation

  • Full repository misspell workflow and git diff --check.
  • Regression test with GCC and Clang on WSL; Visual Studio 2026 x86 and x64; targeted CTest on Linux and Windows.
  • The new Win32 regression step passed on both Visual Studio 2026 and the GitHub-hosted Windows 2022 runner, without disabling warnings.
  • Compression round trips using the bundled library passed on Linux and Windows.

The CTest runs above selected only the new allocation test; they are not claims of a complete test-suite run. This branch is based on current main, whose unrelated public-header and runner-fixture failures are being fixed independently in #1566; merge that PR and update this branch from main before final validation.

Reject allocation-size overflow and preserve full-width multiplication so the bundled allocator cannot silently allocate less than requested. Exercise the boundary in native CTest and 32-bit Windows CI.

Files: zlib/zutil.c, tests/zlib-allocation-test.c, tests/unittests/CMakeLists.txt, .github/workflows/test-win-latest.yml

Co-authored-by: Copilot <[email protected]>
Copilot-Session: e5009227-6b49-4803-8153-63d8d94037e3
@bmehta001
bmehta001 requested a review from a team as a code owner November 19, 2026 19:18
Express the same allocation checks without constant if conditions so the Windows 2022 compiler can enforce warnings as errors.

Files: zlib/zutil.c, tests/zlib-allocation-test.c

Co-authored-by: Copilot <[email protected]>
Copilot-Session: e5009227-6b49-4803-8153-63d8d94037e3

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant