Skip to content

Commit

Permalink
fs: make ReadStream throw error on NaN
Browse files Browse the repository at this point in the history
This test makes fs.ReadStream throw an error when either start or
end is NaN.

Fixes: nodejs#19715
  • Loading branch information
ryzokuken committed Apr 1, 2018
1 parent 141be92 commit 473dd3d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2008,12 +2008,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);
}

Expand All @@ -2028,7 +2028,7 @@ function ReadStream(path, options) {
// Backwards compatibility: Make sure `end` is a number regardless of `start`.
// TODO(addaleax): Make the above typecheck not depend on `start` instead.
// (That is a semver-major change).
if (typeof this.end !== 'number')
if (typeof this.end !== 'number' || Number.isNaN(this.end))
this.end = Infinity;

if (typeof this.fd !== 'number')
Expand Down

0 comments on commit 473dd3d

Please sign in to comment.