miekg/dns — pull request #47 by raybejjani (2013-06-20 23:52:08+00:00)
Title: Compress bug

Hi Miek,
I've been running into an odd bug: Once in a while Msg.Pack will throw an error complaining that there is an overflow. It seems related to the allocation made (Msg.Len() + 10) being too small. This would happen with compression enabled. I managed to find some test cases and I've begun working on a fix of sorts but I wanted to get a feel from you if this was the correct path to take, or if you preferred some other solution. I'll clean up the tests to match the project's style as well before a final review and merge/accept on your part.
The issue seems to be that the len calls account for the possibility of compression, subtracting from the length, but don't account for the second byte of the name pointer (so each possibly compressed name is missing a byte). This could happen anywhere we had a `cdomain-name` tagged struct field. Related, you recently accepted a patch to change the len for TXTs. I could be wrong, but it seemed to not include the length byte for the first TXT element. I had to revert it in getting things to work.
Separately, why was Pack adding 10 to Msg.Len when creating the buffer?

Ray