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

0.4/0.5 to 0.6.1, Very weird TypeError: Object ??? --> 2/3/4 unknown characters #2138

Closed
kokizzu opened this issue Nov 17, 2011 · 14 comments
Closed
Labels

Comments

@kokizzu
Copy link

kokizzu commented Nov 17, 2011

/// first trial
$ sudo node dnsServer.js
request < 127.0.0.1:63152 > google.com.

/home/***/Documents/S2.iSTTS/thesis/NDNS/dnsServer.js:291
  rr.TTL = buff.readInt32BE(start)  // TODO: error at 0.6.1
                ^
TypeError: Object ���



/// second trial
$ sudo node dnsServer.js 
request < 127.0.0.1:24286 > yahoo.com.

/home/***/Documents/S2.iSTTS/thesis/NDNS/dnsServer.js:291
  rr.TTL = buff.readInt32BE(start)  // TODO: error at 0.6.1
                ^
TypeError: Object p���



/// third trial
$ sudo node dnsServer.js 
request < 127.0.0.1:10521 > yahoo.com.

/home/***/Documents/S2.iSTTS/thesis/NDNS/dnsServer.js:291
  rr.TTL = buff.readInt32BE(start)  // TODO: error at 0.6.1
                ^
TypeError: Object ���



the source:
function parseRR(start,buff,compression,rr) {
  d.beginFunction(arguments.callee.name);
  var end = buff.length;
  var name = {};
  start = parseNAME(start,buff,compression,name);
  if(!start) return d.abortFunction(arguments.callee.name,'invalid labels');
  rr.NAME = name;
  if(start+6>end) return d.abortFunction(arguments.callee.name,'index out of range');
  /* TTL (32-bit signed integer) durasi cache.*/
  rr.TTL = buff.readInt32BE(start)  // TODO: error at 0.6.1

buff is SlowBuffer object

i'm using chris-lea PPA on Ubuntu 11.10 64-bit
this does not happened when i use 0.4.x (PPA) or 0.5.x (git, manual compile)

@bnoordhuis
Copy link
Member

What does the buffer object contain at the time of the .readInt32BE() call?

@kokizzu
Copy link
Author

kokizzu commented Nov 17, 2011

  /* TTL (32-bit signed integer) durasi cache.*/
  console.log(buff);
  console.log(buff.length);
  console.log(start);
  rr.TTL = buff.readInt32BE(start)  // TODO: error at 0.6.1
<SlowBuffer aa 8d 81 80 00 01 00 05 00 00 00 00 06 67 6f 6f 67 6c 65 03 63 6f 6d 00 00 01 00 01 c0 0c 00 01 00 01 00 00 00 eb 00 04 ad c2 21 34 c0 0c 00 01 00 01 00 ...>
108
34

/home/***/Documents/S2.iSTTS/thesis/NDNS/dnsServer.js:294
  rr.TTL = buff.readInt32BE(start)  // TODO: error at 0.6.1
                ^
TypeError: Object ����

@kokizzu
Copy link
Author

kokizzu commented Nov 17, 2011

/* TTL (32-bit signed integer) durasi cache.*/
  config.debugMode = true;
  d.logBin(buff);
  console.log(buff.length);
  console.log(start);
  rr.TTL = buff.readInt32BE(start)  // TODO: error at 0.6.1
       00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 000 > ed bd 81 80 00 01 00 05 00 00 00 00 06 67 6f 6f 67 6c 65 03 63 6f 6d 00 00 01 00 01 c0 0c 00 01 
 032 > 00 01 00 00 00 08 00 04 ad c2 21 30 c0 0c 00 01 00 01 00 00 00 08 00 04 ad c2 21 31 c0 0c 00 01 
 064 > 00 01 00 00 00 08 00 04 ad c2 21 32 c0 0c 00 01 00 01 00 00 00 08 00 04 ad c2 21 33 c0 0c 00 01 
 096 > 00 01 00 00 00 08 00 04 ad c2 21 34 
108
34

/home/***/Documents/S2.iSTTS/thesis/NDNS/dnsServer.js:295
  rr.TTL = buff.readInt32BE(start)  // TODO: error at 0.6.1
                ^
TypeError: Object ��

@bnoordhuis
Copy link
Member

Confirmed, SlowBuffer doesn't have the .read*() functions. Test case:

var SlowBuffer = process.binding('buffer').SlowBuffer;
var b = new SlowBuffer(4);
b.write('1234', 0, 4, 'binary');
b.readInt32BE(0); // throws

bnoordhuis added a commit to bnoordhuis/node that referenced this issue Nov 17, 2011
@bnoordhuis
Copy link
Member

Can someone review bnoordhuis/node@771243f?

@koichik
Copy link

koichik commented Nov 17, 2011

Is SlowBuffer a public API? Who creates the instance and passes parseRR() it?
I think that user should not use SlowBuffer directly...

@bnoordhuis
Copy link
Member

The C++ Buffer::New() methods return SlowBuffers so if you use native add-ons there may be no way to avoid them.

@TooTallNate
Copy link

There's also this "technique" for returning regular Buffers from C++ modules:
http://sambro.is-super-awesome.com/2011/03/03/creating-a-proper-buffer-in-a-node-c-addon

@bnoordhuis
Copy link
Member

IIRC I'm the one that originally explained to the guy how to create FastBuffers like that. :-)

Okay, I hope that we have established that SlowBuffers are sometimes unavoidable. Can someone look at bnoordhuis/node@771243f and say if it's any good?

@defunctzombie
Copy link

I took a quick look. Seems reasonable. Test pass I assume?

@koichik
Copy link

koichik commented Nov 18, 2011

@bnoordhuis - Thanks, the patch LGTM (except the last line of buffer.js is duplication).

But I do not know why parseRR() gets SlowBuffer with Node v0.6.1?
With Node v0.5.x, it got Buffer, did not it?

@kokizzu
Copy link
Author

kokizzu commented Nov 18, 2011

if i was not mistaken..
yes it got Buffer not SlowBuffer..

On Fri 18 Nov 2011 02:39:12 PM WIT, Koichi Kobayashi wrote:

@bnoordhuis - Thanks, the patch LGTM (except the last line of buffer.js is duplication).

But I do not know why parseRR() gets SlowBuffer with Node v0.6.1?
With Node v0.5.x, it got Buffer, did not it?


Reply to this email directly or view it on GitHub:
#2138 (comment)

@bnoordhuis
Copy link
Member

Fixed in 59a9a9b.

@koichik: Removed the stray line.

@kiswono-prayogo: What creates the buffer? If it's a core function then it's kind of odd that 0.5.x returned Buffers while 0.6.x returns SlowBuffers.

@kokizzu
Copy link
Author

kokizzu commented Nov 18, 2011

var dgram = require('dgram');
var server = dgram.createSocket('udp4');
var requests = {};
server
  .on("message", function (msg, rinfo) {

it's created by dgram.createSocket('udp4');
"msg" is passed as "buff" on parseRR

this is the result when using node 0.5.5pre (git)

<Buffer 30 61 81 80 00 01 00 05 00 00 00 00 06 67 6f 6f 67 6c 65 03 63 
6f 6d 00 00 01 00 01 c0 0c 00 01 00 01 00 00 00 40 00 04 ad c2 21 32 c0 
0c 00 01 00 01 00 ...>
108

On Fri 18 Nov 2011 05:17:12 PM WIT, Ben Noordhuis wrote:

Fixed in 59a9a9b.

@koichik: Removed the stray line.

@kiswono-prayogo: What creates the buffer? If it's a core function then it's kind of odd that 0.5.x returned Buffers while 0.6.x returns SlowBuffers.


Reply to this email directly or view it on GitHub:
#2138 (comment)

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

5 participants