Skip to content

Question compression #821

Closed
Closed
@tmthrgd

Description

@tmthrgd

The following new test case fails:

func TestMsgCompressionMultipleQuestions(t *testing.T) {
	msg := new(Msg)
	msg.Compress = true
	msg.SetQuestion("www.example.org.", TypeA)
	msg.Question = append(msg.Question, Question{"other.example.org.", TypeA, ClassINET})

	predicted := msg.Len()
	buf, err := msg.Pack()
	if err != nil {
		t.Error(err)
	}

	if predicted != len(buf) {
		t.Fatalf("predicted compressed length is wrong: predicted %d, actual %d", predicted, len(buf))
	}
}

with:

--- FAIL: TestMsgCompressionMultipleQuestions (0.00s)
    length_test.go:387: predicted compressed length is wrong: predicted 56, actual 45

This fails because compressedLen doesn't compress any names in dns.Question:

dns/msg.go

Lines 909 to 912 in 1c9c9bf

for _, r := range dns.Question {
compressionLenHelper(compression, r.Name, l)
l += r.len()
}

but the packing code does compress names in Question:

dns/msg.go

Lines 1093 to 1094 in 1c9c9bf

func (q *Question) pack(msg []byte, off int, compression map[string]int, compress bool) (int, error) {
off, err := PackDomainName(q.Name, msg, off, compression, compress)

dns/msg.go

Line 750 in 1c9c9bf

off, err = question[i].pack(msg, off, compression, dns.Compress)

Although I know that multiple questions are very rare and largely unsupported, this is still a bug. It's very easy to fix, but I just don't know what the correct behaviour is here.

Can QNAMEs be compressed and if so, do we actually want to compress them? I can't seem to find an answer in the RFCs, but I suspect we do want to skip compressing them either way.

/cc @miekg

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions