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

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. #60

Open
alcor93 opened this issue Apr 28, 2020 · 8 comments
Open

Comments

@alcor93
Copy link

alcor93 commented Apr 28, 2020

I have seen specific DNS request for google is failing with this error
RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 49. Received 73
at Object.answer.decode (/home/pi/bin/nodejs/dns/node_modules/dns-packet/index.js:1353:31)

DNS request was : 000e0100000100000000000106676f6f676c6503636f6d0000010001010029100000000000000c000a0008121badeb9ce77e55

@pusateri
Copy link
Contributor

Can you post some test code that reproduces the problem? Feel free to start with the sample code.

@alcor93
Copy link
Author

alcor93 commented Apr 29, 2020 via email

@pusateri
Copy link
Contributor

I don't know if you realize it or not but you're making this extra difficult to help you. To make it easier to help you, you could:

  1. attach sample code that sends out a query to a resolver and returns a response. That way it could also be decoded easily by tcpdump/wireshark or reproduced with dig for quickly isolating the problem.
  2. include a tcpdump/wireshark pcap file that we could dump ourselves (less helpful, but better than you have provided so far).
    I'm not saying we can't debug it with the minimal amount you have given but so far, looking at raw bytes and not knowing any resolver that might generate them, makes it less urgent.

@alcor93
Copy link
Author

alcor93 commented Apr 30, 2020

This code will generate the error.

const dnsPacket = require('dns-packet')
const dgram = require('dgram')

const server = dgram.createSocket('udp4')

server.on('message', (msg, rinfo) => {
  console.log(dnsPacket.decode(msg)) // prints out a response from google dns
})

server.bind(53)

I am not sure this code will help you more than what I provided you before.

I tried to log the received message which lead to the issue
What I can tell you is, that
000e0100000100000000000106676f6f676c6503636f6d0000010001010029100000000000000c000a0008121badeb9ce77e55 => this one will fail
Whereas
000c0100000100000000000106676f6f676c6503636f6d0000010001000029100000000000000c000a0008121badeb9ce77e55 => this one will be well decoded without any issue

The difference is not so big.
It's quite difficult to get information about additional data in DNS protocol, It's why I raised this ticket.

In another approch, Offset which is defined and used in the index.js:1353:31 should be checked according the length of the buffer to avoid such error.

@pusateri
Copy link
Contributor

pusateri commented Apr 30, 2020

yes, this code doesn't help at all because it isn't generating a request. You're still providing a precomputed response to decode. But your follow-on information does describe the problem more which is helpful. But I don't understand why you can't modify udp.js in the examples to exhibit the problem and post that? All I have been asking for is a request to make it easy to troubleshoot.

@pusateri
Copy link
Contributor

I can certainly guess at this based on decoding the response by hand but I am busy and if you already know this, why can't you just make it easy for us?

@pusateri
Copy link
Contributor

I decoded the second one by hand and it looks fine:
000c0100000100000000000106676f6f676c6503636f6d0000010001000029100000000000000c000a0008121badeb9ce77e55
000c ID
0100 query RD bit set
0001 qdcount
0000 ancount
0000 nscount
0001 arcount
06676f6f676c65 google
03636f6d00 com
0001 qtype A
0001 qclass IN
00 root
0029 OPT RR
1000 4096 MTU
00000000 exteded rcode & flags
000c RDLEN 12
000a option code (Cookie)
0008 option length 8
121badeb9ce77e55 (client cookie)

Then I decode the first one and it's not a valid DNS packet:

000e0100000100000000000106676f6f676c6503636f6d0000010001010029100000000000000c000a0008121badeb9ce77e55
000e ID
0100 query recursion-desired (RD bit set)
0001 qdcount
0000 ancount
0000 nscount
0001 arcount
06676f6f676c65 google
03636f6d com
00 label termination
0001 qtype A
0001 qclass IN
01 00 error - not a valid label
29100000000000000c000a0008121badeb9ce77e55 Not 29 hex bytes of label left in packet

@pusateri
Copy link
Contributor

pusateri commented May 1, 2020

It seems like this is a reasonable error for a malformed packet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants