diff options
author | Ujjwal Sharma <usharma1998@gmail.com> | 2018-04-03 23:04:20 +0530 |
---|---|---|
committer | Luigi Pinca <luigipinca@gmail.com> | 2018-04-06 10:51:35 +0200 |
commit | 38a692963f000e3bd0f8413617d3b5774039dff8 (patch) | |
tree | 58cd6a782ae60504beaafc0b614fa06767d8c44b /lib/fs.js | |
parent | 496d6023e0c372c76746c35fdba800fa943cbffc (diff) | |
download | node-new-38a692963f000e3bd0f8413617d3b5774039dff8.tar.gz |
fs: make ReadStream throw TypeError on NaN
Make ReadStream (and thus createReadStream) throw a TypeError signalling
towards an invalid argument type when either options.start or
options.end (or obviously, both) are set to NaN.
Also add regression tests for the same.
PR-URL: https://github.com/nodejs/node/pull/19775
Fixes: https://github.com/nodejs/node/issues/19715
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/fs.js')
-rw-r--r-- | lib/fs.js | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -2009,12 +2009,12 @@ function ReadStream(path, options) { this.closed = false; if (this.start !== undefined) { - if (typeof this.start !== 'number') { + if (typeof this.start !== 'number' || Number.isNaN(this.start)) { throw new ERR_INVALID_ARG_TYPE('start', 'number', this.start); } if (this.end === undefined) { this.end = Infinity; - } else if (typeof this.end !== 'number') { + } else if (typeof this.end !== 'number' || Number.isNaN(this.end)) { throw new ERR_INVALID_ARG_TYPE('end', 'number', this.end); } @@ -2031,6 +2031,8 @@ function ReadStream(path, options) { // (That is a semver-major change). if (typeof this.end !== 'number') this.end = Infinity; + else if (Number.isNaN(this.end)) + throw new ERR_INVALID_ARG_TYPE('end', 'number', this.end); if (typeof this.fd !== 'number') this.open(); |