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

SOA & MINFO compression length mismatch #824

Closed
tmthrgd opened this issue Nov 27, 2018 · 2 comments · Fixed by #833
Closed

SOA & MINFO compression length mismatch #824

tmthrgd opened this issue Nov 27, 2018 · 2 comments · Fixed by #833

Comments

@tmthrgd
Copy link
Collaborator

tmthrgd commented Nov 27, 2018

The following two newly created test cases fail:

func TestMsgCompressMINFO(t *testing.T) {
	msg := new(Msg)
	msg.Compress = true
	msg.SetQuestion("www.example.com.", TypeSRV)
	msg.Answer = append(msg.Answer, &MINFO{
		Hdr:   RR_Header{Name: "www.example.com.", Class: 1, Rrtype: TypeSRV, Ttl: 0x3c},
		Rmail: "mail.example.org.",
		Email: "mail.example.org.",
	})

	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))
	}
}

func TestMsgCompressSOA(t *testing.T) {
	msg := new(Msg)
	msg.Compress = true
	msg.SetQuestion("www.example.com.", TypeSRV)
	msg.Answer = append(msg.Answer, &SOA{
		Hdr:  RR_Header{Name: "www.example.com.", Class: 1, Rrtype: TypeSRV, Ttl: 0x3c},
		Ns:   "ns.example.org.",
		Mbox: "mail.example.org.",
	})

	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: TestMsgCompressMINFO (0.00s)
    length_test.go:402: predicted compressed length is wrong: predicted 81, actual 65
--- FAIL: TestMsgCompressSOA (0.00s)
    length_test.go:422: predicted compressed length is wrong: predicted 99, actual 88

I believe the compressedLen code isn't handling matches between the two compressed domains properly, whereas the PackDomainName code is.

/cc @miekg

@miekg
Copy link
Owner

miekg commented Nov 27, 2018 via email

@tmthrgd
Copy link
Collaborator Author

tmthrgd commented Nov 27, 2018

In the first test, the second "mail.example.org." isn't being compressed into the first. While in the second test, "example.org." from "mail.example.org." isn't being compressed into "ns.example.org.".

I think they're both the same bug and honestly I don't understand what's wrong with the current code. I have managed to fix it in rewriting the compressed length code which I'll upload shortly.

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

Successfully merging a pull request may close this issue.

2 participants