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

Created on 16 Aug 2016  路  7Comments  路  Source: nodejs/node

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.

buffer confirmed-bug

Most helpful comment

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.

All 7 comments

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

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

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

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.

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

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yury-s picture yury-s  路  89Comments

egoroof picture egoroof  路  90Comments

VanCoding picture VanCoding  路  204Comments

thecodingdude picture thecodingdude  路  158Comments

addaleax picture addaleax  路  146Comments