src: fix edge case when deflateInit2() fails with Z_VERSION_ERROR#63476
Open
ndossche wants to merge 1 commit into
Open
src: fix edge case when deflateInit2() fails with Z_VERSION_ERROR#63476ndossche wants to merge 1 commit into
ndossche wants to merge 1 commit into
Conversation
addaleax
reviewed
May 21, 2026
|
|
||
| CompressionError ZlibContext::ErrorForMessage(const char* message) const { | ||
| if (strm_.msg != nullptr) | ||
| if (zlib_init_done_ && strm_.msg != nullptr) |
Member
There was a problem hiding this comment.
That means that no error from InitZlib() would be reported, which doesn't seem particularly desirable.
Can we instead pre-initialize strm_.msg = nullptr; to avoid this issue?
Contributor
Author
There was a problem hiding this comment.
That works too. Did that now. Thanks.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #63476 +/- ##
=======================================
Coverage 90.07% 90.07%
=======================================
Files 714 714
Lines 225935 225953 +18
Branches 42738 42739 +1
=======================================
+ Hits 203503 203529 +26
+ Misses 14206 14204 -2
+ Partials 8226 8220 -6
🚀 New features to boost your workflow:
|
This function call can fail with `Z_VERSION_ERROR` if the compiled
library vs loaded library mismatched in version number or in
stream structure size.
In those cases, zlib doesn't initialize the `strm_.msg` field to
null. Therefore, when a `CompressionError` object is created via
`ErrorForMessage()`, it can read a stale or uninitialized `strm_.msg`
pointer that will cause a crash.
Example ASAN report:
```
AddressSanitizer: SEGV on unknown address
#0 __strlen_avx2
string/../sysdeps/x86_64/multiarch/strlen-avx2.S:76
nodejs#1 strlen (/work/node/out/Debug/node+0x1a42ab7)
nodejs#2 v8::(anonymous namespace)::StringLength(char const*)
/work/node/out/../deps/v8/src/api/api.cc:7581:16
nodejs#3 v8::(anonymous namespace)::StringLength(unsigned char const*)
/work/node/out/../deps/v8/src/api/api.cc:7587:10
nodejs#4 v8::String::NewFromOneByte(v8::Isolate*,
unsigned char const*, v8::NewStringType, int)
/work/node/out/../deps/v8/src/api/api.cc:7677:3
nodejs#5 node::OneByteString(v8::Isolate*,
char const*, int, v8::NewStringType)
/work/node/out/../src/util-inl.h:166:10
nodejs#6 node::(anonymous namespace)::CompressionStream<
node::(anonymous namespace)::ZlibContext>
::EmitError(node::(anonymous namespace)
::CompressionError const&)
/work/node/out/../src/node_zlib.cc:565:7
nodejs#7 node::(anonymous namespace)::CompressionStream<
node::(anonymous namespace)::ZlibContext>
::CheckError()
/work/node/out/../src/node_zlib.cc:519:5
nodejs#8 node::(anonymous namespace)::CompressionStream<
node::(anonymous namespace)::ZlibContext>
::AfterThreadPoolWork(int)
/work/node/out/../src/node_zlib.cc:543:10
nodejs#9 node::ThreadPoolWork::ScheduleWork()
::'lambda'(uv_work_s*, int)
::operator()(uv_work_s*, int) const
/work/node/out/../src/threadpoolwork-inl.h:57:15
nodejs#10 node::ThreadPoolWork::ScheduleWork()
::'lambda'(uv_work_s*, int)
::__invoke(uv_work_s*, int)
/work/node/out/../src/threadpoolwork-inl.h:48:7
nodejs#11 uv__work_done /work/libuv-1.51.0/src/threadpool.c:330:5
nodejs#12 uv__async_io.part.0
/work/libuv-1.51.0/src/unix/async.c:208:5
```
Signed-off-by: ndossche <nora.dossche@ugent.be>
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.
deflateInit2()can fail withZ_VERSION_ERRORif the compiled library vs loaded library mismatched in version number or in stream structure size.In those cases, zlib doesn't initialize the
strm_.msgfield to null. Therefore, when aCompressionErrorobject is created viaErrorForMessage(), it can read a stale or uninitializedstrm_.msgpointer that will cause a crash.Example ASAN report: