Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change between Node 6.3.1 and 6.4 regarding writing strings of length 0 to a Buffer #8127

Closed
phretaddin opened this issue Aug 16, 2016 · 7 comments
Labels
buffer Issues and PRs related to the buffer subsystem. confirmed-bug Issues with confirmed bugs.

Comments

@phretaddin
Copy link

phretaddin commented Aug 16, 2016

In Node 6.3.1, you could do this:

var buff = Buffer.alloc(1);
buff.write('', 1, 0);
console.log(buff);

That is, writing empty strings out of the buffer bounds would not cause a crash. However, with 6.4, that code above causes a crash with this error message:

buffer.js:761
     return this.utf8Write(string, offset, length);

Range Error: Offset is out of bounds

This change causes my library to break. I'm wondering if this was an intentional change. If so, just let me know, and I'll patch my library to check for empty strings before writing.

@addaleax addaleax added confirmed-bug Issues with confirmed bugs. buffer Issues and PRs related to the buffer subsystem. labels Aug 16, 2016
@addaleax
Copy link
Member

This seems like a real bug introduced by 46f40cf, even if this is an edge case. On a first look, it seems like changing >= to > is the correct fix for this.

@jasnell
Copy link
Member

jasnell commented Aug 16, 2016

Ugh. Yep, confirmed. Need to add a regression test that covers this also.

addaleax added a commit to addaleax/node that referenced this issue Aug 18, 2016
Do not throw if the offset passed to `buf.write()` points
to the end of the buffer.

Fixes: nodejs#8127
@fubar
Copy link

fubar commented Aug 18, 2016

Ran into the same issue with node-mysql2, glad it has been identified already.

@jasnell
Copy link
Member

jasnell commented Aug 18, 2016

The fix should land in the next day or two and will go out in the next patch release. Shouldn't take too long. In the meantime, you can apply the patch in #8154 to work around it.

mathiasbynens added a commit to tibiamaps/tibia-map-data that referenced this issue Aug 22, 2016
In Node.js v6.4.0, writing an empty string out of the buffer bounds throws an exception. This will be fixed in Node.js v6.4.1 but for now we’re going to have to stick to v6.3.1, which doesn’t have this issue.

nodejs/node#8127
@mathiasbynens
Copy link
Contributor

mathiasbynens commented Aug 22, 2016

Got hit by this as well. Hopefully v6.4.1 can be released soon!

@RReverser
Copy link
Member

@mathiasbynens Looks like it's fixed only on master, not backported to v6.x (yet?).

@evanlucas
Copy link
Contributor

I've been working on getting the commits cherry-picked over to v6.x. Hopefully, will be able to get a release proposal up soon

evanlucas pushed a commit that referenced this issue Aug 24, 2016
Do not throw if the offset passed to `buf.write()` points
to the end of the buffer.

Fixes: #8127
PR-URL: #8154
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
mathiasbynens added a commit to tibiamaps/tibia-map-data that referenced this issue Aug 25, 2016
In Node.js v6.4.0, writing an empty string out of the buffer bounds throws an exception. This will be fixed in Node.js v6.4.1 but for now we’re going to have to stick to v6.3.1, which doesn’t have this issue.

nodejs/node#8127
arthurschreiber added a commit to tediousjs/tedious that referenced this issue Aug 26, 2016
Node.js 6.4.0 was shipped with a bug in it's Buffer implementation that causes the tedious test cases to fail. See #431, nodejs/node#8127 and nodejs/node#8154.
mathiasbynens added a commit to tibiamaps/tibia-map-data that referenced this issue Aug 29, 2016
In Node.js v6.4.0, writing an empty string out of the buffer bounds throws an exception. This will be fixed in Node.js v6.5.0 but for now we’re going to have to stick to v6.3.1, which doesn’t have this issue.

nodejs/node#8127
nodejs/node#8253
tvrprasad pushed a commit to tvrprasad/tedious that referenced this issue Sep 11, 2016
Node.js 6.4.0 was shipped with a bug in it's Buffer implementation that causes the tedious test cases to fail. See tediousjs#431, nodejs/node#8127 and nodejs/node#8154.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. confirmed-bug Issues with confirmed bugs.
Projects
None yet
Development

No branches or pull requests

7 participants