mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
fix(ws): fix zlib version mismatch on Windows (segfault) (#25538)
## Summary Fixes #24593 - WebSocket segfault on Windows when publishing large messages with `perMessageDeflate: true`. Also fixes #21028 (duplicate issue). Also closes #25457 (alternative PR). **Root cause:** On Windows, the C++ code was compiled against system zlib headers (1.3.1) but linked against Bun's vendored Cloudflare zlib (1.2.8). This version mismatch caused `deflateInit2()` to return `Z_VERSION_ERROR` (-6), leaving the deflate stream in an invalid state. All subsequent `deflate()` calls returned `Z_STREAM_ERROR` (-2), producing zero output, which then caused an integer underflow when subtracting the 4-byte trailer → segfault in memcpy. **Fix:** Add `${VENDOR_PATH}/zlib` to the C++ include paths in `cmake/targets/BuildBun.cmake`. This ensures the vendored zlib headers are found before system headers, maintaining header/library version consistency. This is a simpler alternative to #25457 which worked around the issue by using libdeflate exclusively. ## Test plan - [x] Added regression test `test/regression/issue/24593.test.ts` with 4 test cases: - Large ~109KB JSON message publish (core reproduction) - Multiple rapid publishes (buffer corruption) - Broadcast to multiple subscribers - Messages at CORK_BUFFER_SIZE boundary (16KB) - [x] Tests pass on Windows (was crashing before fix) - [x] Tests pass on macOS 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -872,6 +872,7 @@ target_include_directories(${bun} PRIVATE
|
||||
${CODEGEN_PATH}
|
||||
${VENDOR_PATH}
|
||||
${VENDOR_PATH}/picohttpparser
|
||||
${VENDOR_PATH}/zlib
|
||||
${NODEJS_HEADERS_PATH}/include
|
||||
${NODEJS_HEADERS_PATH}/include/node
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user