src: fix crash when writing odd-length hex string via Writev - #63658
Merged
nodejs-github-bot merged 1 commit intoJul 25, 2026
Merged
Conversation
RajeshKumar11
force-pushed
the
fix/stream-hex-odd-length-45150
branch
from
May 30, 2026 07:51
fd3d0ec to
6a0c023
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #63658 +/- ##
==========================================
- Coverage 91.95% 90.34% -1.61%
==========================================
Files 379 732 +353
Lines 166454 236434 +69980
Branches 25427 44532 +19105
==========================================
+ Hits 153058 213614 +60556
- Misses 13104 14522 +1418
- Partials 292 8298 +8006
🚀 New features to boost your workflow:
|
RajeshKumar11
force-pushed
the
fix/stream-hex-odd-length-45150
branch
from
May 30, 2026 11:13
6a0c023 to
84ef8a0
Compare
StringBytes::StorageSize had a CHECK that fatal-asserted when a hex-encoded string with an odd number of characters was written through Writev (e.g. via HTTP requests which are automatically corked). Writing the same string via a single Write did not crash because StringBytes::Write delegates to HexDecode, which silently drops the trailing incomplete nibble. Remove the CHECK and let integer division handle odd lengths, which is consistent with StringBytes::Size and HexDecode. Fixes: nodejs#45150 Signed-off-by: RajeshKumar11 <kakumanurajeshkumar@gmail.com>
RajeshKumar11
force-pushed
the
fix/stream-hex-odd-length-45150
branch
from
May 30, 2026 11:21
84ef8a0 to
0e3192c
Compare
Contributor
|
cc @nodejs/buffer |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Collaborator
Summary
Writing an odd-length hex string to a stream that batches writes via
Writev (e.g.
http.requestwhich auto-corks its socket) wouldfatal-assert:
Reproduction:
Root cause
StringBytes::StorageSizehad aCHECKthat asserted the hex stringlength was even. When writes are batched through Writev, this check
runs before any data is written. A single Write (non-corked path)
did not crash because
StringBytes::WritecallsHexDecode, whichsilently drops the trailing incomplete nibble.
Fix
Remove the CHECK and use integer division for the HEX case, which
naturally rounds down for odd lengths. This is already the behaviour
of
StringBytes::SizeandHexDecode.Test
Added
test/parallel/test-http-odd-hex-write.jswith three cases:Fixes: #45150