Skip to content

fix: release zlib state when a gzip upload body is destroyed early - #180

Merged
jpnurmi merged 2 commits into
getsentry:getsentryfrom
bionicbeagle:fix/gzip-body-early-destroy
Nov 19, 2026
Merged

jpnurmi merged 2 commits into
getsentry:getsentryfrom
bionicbeagle:fix/gzip-body-early-destroy

Conversation

@bionicbeagle

@bionicbeagle bionicbeagle commented Nov 18, 2026 •

Copy link
Copy Markdown

For getsentry/sentry-native#2323. Upstream report: https://issues.chromium.org/issues/587029408

When a network write fails partway through an upload, the transport stops reading the body. GzipHTTPBodyStream is then destroyed while it is still kOperating or kInputEOF. Its destructor only DCHECKed that the stream had finished, so a debug crashpad_handler crashed (0x80000003 on Windows), and a release handler leaked the deflate state of every failed upload.

The destructor now calls deflateEnd() in those two states. deflateEnd() frees the state even for an unfinished stream. It returns Z_DATA_ERROR to say unfinished output was discarded, which is expected here, so only other results are logged.

Why this can't free twice. kFinished and kError are reached only through Done(), which has already called deflateEnd(), or through a failed deflateInit2(), which leaves nothing to free. kUninitialized never initialized zlib.

Testing. The same destructor change, built through sentry-native 0.17.5, passed 100 iterations each of an unread, partially read, unfinished-trailer, completed and input-error stream in a Windows x64 debug build, with no CRT leak reports. We also build it as a patch on sentry-native 0.17.5 in our CI on Windows, Linux and macOS.

The sentry-native submodule bump that runs this through its test suite: getsentry/sentry-native#2326

A transport stops reading the request body when a network write fails:
WinHttpWriteData() fails on Windows, or curl_easy_perform() fails before
the read callback has drained the body. GzipHTTPBodyStream is then
destroyed while still operating or flushing its trailer. Its destructor
only DCHECKed that the stream had finished, so a debug crashpad_handler
crashed, and a release handler leaked the deflate state of every failed
upload.

The destructor now calls deflateEnd() in those states. deflateEnd()
frees the state even for an unfinished stream and returns Z_DATA_ERROR
to say output was discarded, which is expected here and not logged.

Upstream: https://issues.chromium.org/issues/587029408

@jpnurmi jpnurmi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR!

I'll open the sentry-native submodule bump once this is merged.

We could actually already create the submodule bump PR to run these changes through sentry-native's test suite. It's fine to bump the submodule to a sha1 in your fork because the ref is also known by the getsentry repo now that the PR is open. 👍

Comment thread util/net/http_body_gzip_test.cc Resolved
@jpnurmi
jpnurmi merged commit 722d1c7 into getsentry:getsentry Nov 19, 2026
24 checks passed
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.

2 participants