Skip to content

Loading…

confusing error for `fs.createReadStream(path, { start: "90", end: "99"})` #2554

Closed
coolaj86 opened this Issue · 1 comment

3 participants

@coolaj86

This concerns the case that a string is passed in to createReadStream start or end, instead of a number.

There are several places in fs.js where this.pos += {{whatever}} will result in string concatenation and throw a confusing error:

  binding.read(fd, buffer, offset, length, position, wrapper);
          ^
Error: Length extends beyond buffer

I propose that this.pos = parseInt(this.start, 10) be used (in the if block around line 1040 in fs.js) instead of this.pos = this.start.

I'll be happy to submit the pull request if you like.

In context:

if (this.start !== undefined) {
  if (this.end === undefined) {
    this.end = Infinity;
  }      

  if (this.start > this.end) {
    throw new Error('start must be <= end');
  }      

  this.pos = parseInt(this.start, 10);
}   

...
@bnoordhuis
Node.js Foundation member

I'll take a patch but don't be accommodating, just throw a TypeError when start or end isn't a number.

@koichik koichik closed this
@isaacs isaacs referenced this issue
Commit has since been removed from the repository and is no longer available.
@isaacs isaacs referenced this issue
Commit has since been removed from the repository and is no longer available.
@isaacs isaacs referenced this issue
Commit has since been removed from the repository and is no longer available.
@isaacs isaacs referenced this issue
Commit has since been removed from the repository and is no longer available.
@isaacs isaacs added a commit to isaacs/node that referenced this issue
@isaacs isaacs 2012.03.02 Version 0.6.12 (stable)
* Upgrade V8 to 3.6.6.24

* dtrace ustack helper improvements (Dave Pacheco)

* API Documentation refactor (isaacs)

* #2827 net: fix race write() before and after connect() (koichik)

* #2554 #2567 throw if fs args for 'start' or 'end' are strings (AJ ONeal)

* punycode: Update to v1.0.0 (Mathias Bynens)

* Make a fat binary for the OS X pkg (isaacs)

* Fix hang on accessing process.stdin (isaacs)

* repl: make tab completion work on non-objects (Nathan Rajlich)

* Fix fs.watch on OS X (Ben Noordhuis)

* Fix #2515 nested setTimeouts cause premature process exit (Ben Noordhuis)

* windows: fix time conversion in stat (Igor Zinkovsky)

* windows: fs: handle EOF in read (Brandon Philips)

* windows: avoid IOCP short-circuit on non-ifs lsps (Igor Zinkovsky)

* Upgrade npm to 1.1.4 (isaacs)
  - windows fixes
  - Bundle nested bundleDependencies properly
  - install: support --save with url install targets
  - shrinkwrap: behave properly with url-installed modules
  - support installing uncompressed tars or single file modules from urls etc.
  - don't run make clean on rebuild
  - support HTTPS-over-HTTP proxy tunneling
48a2d34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.