murarth / resolve

DNS communication protocol
Apache License 2.0
25 stars 8 forks source link

"short message" error with larger SRV response #16

Closed bnewbold closed 6 years ago

bnewbold commented 6 years ago

Resolving a SRV record that has multiple entries using resolve gives me a "ShortMessage" error:

Error: failed to resolve record: error decoding message: short message

An example SRV lookup with 6 responses that results in an error:


;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 25682
;; Flags: qr; QUERY: 1; ANSWER: 6; AUTHORITY: 0; ADDITIONAL: 0

;; QUESTION SECTION:
;; 795655663df60fab8f793ff4fb11de321a71c5ea.dat.local.  IN      SRV

;; ANSWER SECTION:
795655663df60fab8f793ff4fb11de321a71c5ea.dat.local. 120 IN      SRV     0 0 1024 70.50.214.32.
795655663df60fab8f793ff4fb11de321a71c5ea.dat.local. 120 IN      SRV     0 0 3282 94.19.245.14.
795655663df60fab8f793ff4fb11de321a71c5ea.dat.local. 120 IN      SRV     0 0 48628 35.193.163.202.
795655663df60fab8f793ff4fb11de321a71c5ea.dat.local. 120 IN      SRV     0 0 3282 180.157.225.236.
795655663df60fab8f793ff4fb11de321a71c5ea.dat.local. 120 IN      SRV     0 0 3282 132.239.132.167.
795655663df60fab8f793ff4fb11de321a71c5ea.dat.local. 120 IN      SRV     0 0 61360 72.182.35.118.

;; Received 569 B
;; Time 2018-02-15 20:24:36 PST
;; From 188.166.107.197@53(UDP) in 174.4 ms```

And one with a single answer that `resolve` handles fine:

```$ dig @discovery2.publicbits.org 892e5ef0875a89ac7e0b2c0184db9b09fccbcf36.dat.local SRV
;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 51313
;; Flags: qr; QUERY: 1; ANSWER: 1; AUTHORITY: 0; ADDITIONAL: 0

;; QUESTION SECTION:
;; 892e5ef0875a89ac7e0b2c0184db9b09fccbcf36.dat.local.  IN      SRV

;; ANSWER SECTION:
892e5ef0875a89ac7e0b2c0184db9b09fccbcf36.dat.local. 120 IN      SRV     0 0 48628 35.193.163.202.

;; Received 152 B
;; Time 2018-02-15 20:24:48 PST
;; From 188.166.107.197@53(UDP) in 207.9 ms```

This is some non-standard DNS usage (eg, not `_protocol.` style in a SRV lookup), but the single-response message works fine.
murarth commented 6 years ago

Non-standard usage should not affect the validity of messages being sent and received. This is a bug. I'll look into it right away.

bnewbold commented 6 years ago

In case it helps, here's my (straightforward) rust code using resolve: https://github.com/bnewbold/geniza/blob/master/src/discovery.rs#L19

murarth commented 6 years ago

Ugh. The bug was embarassingly silly:

Internal UDP read buffers were using a maximum size of 512 bytes, which was silently cutting off the end of long UDP packets. I knew 512 was the wrong value for that and I should have fixed it sooner, but never ran into a bug because of it. Of course, it was inevitably going to cause a bug like this.

I've pushed a commit that raises the internal buffer size to 65535 (0xffff), which is enough to contain any UDP packet. Tests confirm that this resolves the bug.

Thank you for this issue.