Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

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

Closed
coolaj86 opened this issue Jan 17, 2012 · 1 comment
Closed
Labels

Comments

@coolaj86
Copy link

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
Copy link
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 as completed Jan 27, 2012
coolaj86 pushed a commit to coolaj86/node that referenced this issue Feb 18, 2012
isaacs added a commit to isaacs/node-v0.x-archive that referenced this issue Mar 2, 2012
* Upgrade V8 to 3.6.6.24

* dtrace ustack helper improvements (Dave Pacheco)

* API Documentation refactor (isaacs)

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

* nodejs#2554 nodejs#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 nodejs#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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants