-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: fix error when writing buffers > INT32_MAX
This reverts c380ee6. uv_fs_write returns an int, so it is not possible to ask it to write more than INT32_MAX. Instead, validate 'length' is an int32 in JS to avoid the assertion failure. PR-URL: #38546 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
- Loading branch information
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
// fs.write with length > INT32_MAX | ||
|
||
common.skipIf32Bits(); | ||
|
||
let buf; | ||
try { | ||
buf = Buffer.allocUnsafe(0x7FFFFFFF + 1); | ||
} catch (e) { | ||
// If the exception is not due to memory confinement then rethrow it. | ||
if (e.message !== 'Array buffer allocation failed') throw (e); | ||
common.skip('skipped due to memory requirements'); | ||
} | ||
|
||
const filename = path.join(tmpdir.path, 'write9.txt'); | ||
fs.open(filename, 'w', 0o644, common.mustSucceed((fd) => { | ||
assert.throws(() => { | ||
fs.write(fd, | ||
buf, | ||
0, | ||
0x7FFFFFFF + 1, | ||
0, | ||
common.mustNotCall()); | ||
}, { | ||
code: 'ERR_OUT_OF_RANGE', | ||
name: 'RangeError', | ||
message: 'The value of "length" is out of range. ' + | ||
'It must be >= 0 && <= 2147483647. Received 2147483648' | ||
}); | ||
|
||
fs.closeSync(fd); | ||
})); |