Open alcor93 opened 4 years ago
Can you post some test code that reproduces the problem? Feel free to start with the sample code.
this code will generate the error
const { encode, decode } = require('dns-packet'); console.log(decode(Buffer.from('000e0100000100000000000106676f6f676c6503636f6d0000010001010029100000000000000c000a0008121badeb9ce77e55','hex')));
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:
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.
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.
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?
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
It seems like this is a reasonable error for a malformed packet.
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