Skip to content

Instantly share code, notes, and snippets.

@rootslab
Created September 23, 2011 14:26
Show Gist options
  • Save rootslab/1237478 to your computer and use it in GitHub Desktop.
Save rootslab/1237478 to your computer and use it in GitHub Desktop.
(NodeJs) Buffer Size bug
// https://github.com/joyent/node/blob/master/lib/buffer.js R#~208
...
// Are we slicing?
if (typeof offset === 'number') {
this.length = Math.floor( encoding ); // <-- probably also here
this.parent = subject;
this.offset = offset;
} else {
// Find the length
switch (type = typeof subject) {
case 'number':
this.length = Math.floor( subject ); // <-- here
break;
switch (type = typeof subject) {
case 'number':
this.length =
break;
...
@rootslab
Copy link
Author

Try this code :

var log = console.log,
    n = 3;

/**/

var buff1 = new Buffer( n / 2 );
log( buff1, buff1.length );

/** /
var buff2 = new Buffer( n / 2 );
log( buff2, buff2.length );
/**/

buff1 : the buffer was instantiated and its length is a fraction

buff2 : If you uncomment this buffer related code, it throws error..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment