diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 75efbf5c8a5186..a4c92eee97379b 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -61,7 +61,7 @@ function parseFileMode(value, name, def) { } if (isUint32(value)) { - return value; + return 0xFFFFFFFF & value; } if (typeof value === 'number') { diff --git a/test/parallel/test-fs-read-stream-throw-type-error.js b/test/parallel/test-fs-read-stream-throw-type-error.js index 83b9387cc38da9..bb5903cc6222ec 100644 --- a/test/parallel/test-fs-read-stream-throw-type-error.js +++ b/test/parallel/test-fs-read-stream-throw-type-error.js @@ -75,3 +75,6 @@ const NOT_SAFE_INTEGER = 2 ** 53; ].forEach((opts) => createReadStreamErr(example, opts, rangeError) ); + +// Case 8: Should not throw any error even if mode is a huge unsigned int32 +fs.createReadStream(example, { mode: 2176057344 }); diff --git a/test/parallel/test-fs-write-stream-huge-unsigned-int-mode.js b/test/parallel/test-fs-write-stream-huge-unsigned-int-mode.js new file mode 100644 index 00000000000000..143df0157cb8b3 --- /dev/null +++ b/test/parallel/test-fs-write-stream-huge-unsigned-int-mode.js @@ -0,0 +1,16 @@ +'use strict'; +require('../common'); + +// This test ensures that createWriteStream does not crash when the +// passed mode is a huge unsigned int32, as reported here: +// https://github.com/nodejs/node/issues/37430 + +const fs = require('fs'); +const path = require('path'); + +const tmpdir = require('../common/tmpdir'); +tmpdir.refresh(); + +const example = path.join(tmpdir.path, 'dummy'); + +fs.createWriteStream(example, { mode: 2176057344 });