Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc0b361

Browse filesBrowse files
cjihrigcodebytere
authored andcommitted
fs: don't limit ftruncate() length to 32 bits
The length used by ftruncate() is 64 bits in the binding layer. This commit removes the 32 bit restriction in the JS layer. Backport-PR-URL: #21171 PR-URL: #20851 Fixes: #20844 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Backport-PR-URL: #21171 Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
1 parent 469baa0 commit fc0b361
Copy full SHA for fc0b361

File tree

Expand file treeCollapse file tree

3 files changed

+5
-13
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+5
-13
lines changed
Open diff view settings
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ const {
8686
const {
8787
isUint32,
8888
validateInteger,
89-
validateInt32,
9089
validateUint32
9190
} = require('internal/validators');
9291

@@ -788,11 +787,7 @@ fs.ftruncate = function(fd, len = 0, callback) {
788787
len = 0;
789788
}
790789
validateUint32(fd, 'fd');
791-
// TODO(BridgeAR): This does not seem right.
792-
// There does not seem to be any validation before and if there is any, it
793-
// should work similar to validateUint32 or not have a upper cap at all.
794-
// This applies to all usage of `validateInt32(len, 'len')`.
795-
validateInt32(len, 'len');
790+
validateInteger(len, 'len');
796791
len = Math.max(0, len);
797792
const req = new FSReqWrap();
798793
req.oncomplete = makeCallback(callback);
@@ -801,7 +796,7 @@ fs.ftruncate = function(fd, len = 0, callback) {
801796

802797
fs.ftruncateSync = function(fd, len = 0) {
803798
validateUint32(fd, 'fd');
804-
validateInt32(len, 'len');
799+
validateInteger(len, 'len');
805800
len = Math.max(0, len);
806801
const ctx = {};
807802
binding.ftruncate(fd, len, undefined, ctx);
Collapse file

‎lib/internal/fs/promises.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/promises.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const {
3333
validatePath
3434
} = require('internal/fs/utils');
3535
const {
36-
validateInt32,
36+
validateInteger,
3737
validateUint32
3838
} = require('internal/validators');
3939
const pathModule = require('path');
@@ -264,7 +264,7 @@ async function truncate(path, len = 0) {
264264

265265
async function ftruncate(handle, len = 0) {
266266
validateFileHandle(handle);
267-
validateInt32(len, 'len');
267+
validateInteger(len, 'len');
268268
len = Math.max(0, len);
269269
return binding.ftruncate(handle.fd, len, kUsePromises);
270270
}
Collapse file

‎test/parallel/test-fs-truncate.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-truncate.js
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,14 @@ function testFtruncate(cb) {
220220
`an integer. Received ${input}`
221221
}
222222
);
223-
});
224223

225-
// 2 ** 31 = 2147483648
226-
[2147483648, -2147483649].forEach((input) => {
227224
assert.throws(
228225
() => fs.ftruncate(fd, input),
229226
{
230227
code: 'ERR_OUT_OF_RANGE',
231228
name: 'RangeError [ERR_OUT_OF_RANGE]',
232229
message: 'The value of "len" is out of range. It must be ' +
233-
`> -2147483649 && < 2147483648. Received ${input}`
230+
`an integer. Received ${input}`
234231
}
235232
);
236233
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.