Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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.

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>
  • Loading branch information
cjihrig authored and codebytere committed Jun 6, 2018
commit f2f8375a728f51da0126e92fec3d52bacd2262aa
9 changes: 2 additions & 7 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ const {
const {
isUint32,
validateInteger,
validateInt32,
validateUint32
} = require('internal/validators');

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

fs.ftruncateSync = function(fd, len = 0) {
validateUint32(fd, 'fd');
validateInt32(len, 'len');
validateInteger(len, 'len');
len = Math.max(0, len);
const ctx = {};
binding.ftruncate(fd, len, undefined, ctx);
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const {
} = require('internal/fs/utils');
const {
isUint32,
validateInt32,
validateInteger,
validateUint32
} = require('internal/validators');
const pathModule = require('path');
Expand Down Expand Up @@ -265,7 +265,7 @@ async function truncate(path, len = 0) {

async function ftruncate(handle, len = 0) {
validateFileHandle(handle);
validateInt32(len, 'len');
validateInteger(len, 'len');
len = Math.max(0, len);
return binding.ftruncate(handle.fd, len, kUsePromises);
}
Expand Down
5 changes: 1 addition & 4 deletions test/parallel/test-fs-truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,14 @@ function testFtruncate(cb) {
`an integer. Received ${input}`
}
);
});

// 2 ** 31 = 2147483648
[2147483648, -2147483649].forEach((input) => {
assert.throws(
() => fs.ftruncate(fd, input),
{
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError [ERR_OUT_OF_RANGE]',
message: 'The value of "len" is out of range. It must be ' +
`> -2147483649 && < 2147483648. Received ${input}`
`an integer. Received ${input}`
}
);
});
Expand Down