fs: fix writev UNKNOWN on large buffers - #65736
Open
themuuln wants to merge 1 commit into
Open
Conversation
Check total byteLength across all buffers before the syscall. A total over kIoMaxLength (2147483647) wraps to -2147483648 inside libuv and surfaces as UNKNOWN. Validate first and throw ERR_OUT_OF_RANGE so the error is actionable. Matches the earlier fix for fs.write in c4e7dca, which validated length against INT32_MAX before uv_fs_write. Fixes: nodejs#40779 Refs: nodejs@c4e7dca8f30 Signed-off-by: Temuulen Undrakhbayar <zerone.offical@gmail.com> Assisted-by: Muse Spark
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65736 +/- ##
==========================================
- Coverage 90.07% 90.01% -0.07%
==========================================
Files 754 755 +1
Lines 256395 257310 +915
Branches 48494 48784 +290
==========================================
+ Hits 230947 231611 +664
- Misses 16563 16793 +230
- Partials 8885 8906 +21
🚀 New features to boost your workflow:
|
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.
Fixes #40779
What changed
fs.writev,fs.writevSync, andFileHandle.writevnow validate totalbyteLengthbefore the syscall. If the sum exceedskIoMaxLength(2147483647), they throwERR_OUT_OF_RANGEwith the received length instead of letting libuv wrap to-2147483648and surface asUNKNOWN.lib/fs.js: added loop +ERR_OUT_OF_RANGE.HideStackFramesErrorinwritevandwritevSynclib/internal/fs/promises.js: same check inFileHandle.writevThis matches the fix for
fs.writein c4e7dca, which validatedlengthagainstkIoMaxLengthbeforeuv_fs_write.Why
Repro from the issue:
Several small buffers that sum past 2 GiB hit the same wrap. The new check catches the sum early and gives an actionable error.
Tests
Added
test/parallel/test-fs-writev-buffer-large.js, modeled ontest-fs-write-buffer-large.js:writevSyncthrowsERR_OUT_OF_RANGEfor[bigBuffer]and[bigBuffer, small]writev(callback) throws synchronously, callback never calledFileHandle.writevrejects withERR_OUT_OF_RANGE;[]still returnsbytesWritten: 0The test skips on 32-bit and when allocation fails (
Array buffer allocation failed).Verification locally:
npx eslint lib/fs.js lib/internal/fs/promises.js test/parallel/test-fs-writev-buffer-large.js— no errorskIoMaxLengthimports andvalidateBufferArrayorderRefs: c4e7dca