Navigation Menu

Skip to content

Commit

Permalink
src: allow Buffers returned from reinterpretUntilZeros() up to `kMa…
Browse files Browse the repository at this point in the history
…xLength` bytes

Fixes a bug where the returned Buffer could have truncated data.

Reported via email by Adam Mansour (@intelligo).
  • Loading branch information
TooTallNate committed Jun 10, 2014
1 parent c38ce77 commit dcf24dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/binding.cc
Expand Up @@ -546,7 +546,7 @@ NAN_METHOD(ReinterpretBufferUntilZeros) {
size_t size = 0;
bool end = false;

while (!end && size < 10000) {
while (!end && size < node::Buffer::kMaxLength) {
end = true;
for (i = 0; i < numZeros; i++) {
if (ptr[size + i] != 0) {
Expand Down
9 changes: 9 additions & 0 deletions test/reinterpretUntilZeros.js
@@ -1,4 +1,5 @@

var fs = require('fs')
var assert = require('assert')
var weak = require('weak')
var ref = require('../')
Expand All @@ -25,4 +26,12 @@ describe('reinterpretUntilZeros()', function () {
assert.equal(buf2.toString('ucs2'), str)
})

it('should return a large Buffer instance > 10,000 bytes with UTF16-LE char bytes', function () {
var data = fs.readFileSync(__dirname + '/utf16le.bin');
var strBuf = ref.reinterpretUntilZeros(data, 2);
assert(strBuf.length > 10000);
// the data in `utf16le.bin` should be a JSON parsable string
JSON.parse(strBuf.toString('utf16le'));
})

})
Binary file added test/utf16le.bin
Binary file not shown.

0 comments on commit dcf24dd

Please sign in to comment.