[GH-ISSUE #1179] Name compression failures on corner cases #623

Closed
opened 2026-03-15 23:30:58 +03:00 by kerem · 10 comments
Owner

Originally created by @jacoblin1994 on GitHub (Aug 3, 2020).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1179

Describe the bug
Name compression seems to fail on some corner cases, in this case, 'frontdoor.nest.com.' followed by several of its answer records 'frontdoor-srt01-production-1909587911.us-east-1.elb.amazonaws.com.' Strangely enough, if you swap the order presented to BinEncoder such that 'frontdoor.nest.com.' is placed at the end, the compression seems to be done correctly as expected.

To Reproduce
trust-dns/crates/proto/src/rr/domain/name.rs

#[test]
fn test_pointer() {
    let mut bytes: Vec<u8> = Vec::with_capacity(512);

    let first = Name::from_str("frontdoor.nest.com.").unwrap();
    let second = Name::from_str("frontdoor-srt01-production-1909587911.us-east-1.elb.amazonaws.com.").unwrap();
    let third = second.clone();

    {
        let mut e = BinEncoder::new(&mut bytes);

        first.emit(&mut e).unwrap();
        assert_eq!(e.len(), 20);

        second.emit(&mut e).unwrap();
        assert_eq!(e.len(), 84);

        third.emit(&mut e).unwrap();
        assert_eq!(e.len(), 86); // Should be 86 but get 148 instead that adds another 64 bytes
    }
}

Expected behavior
Expect Name/labels to be properly compressed but the result does not seem to suggest so.

Version:
Version: [0.7.3]

Originally created by @jacoblin1994 on GitHub (Aug 3, 2020). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/1179 **Describe the bug** Name compression seems to fail on some corner cases, in this case, 'frontdoor.nest.com.' followed by several of its answer records 'frontdoor-srt01-production-1909587911.us-east-1.elb.amazonaws.com.' Strangely enough, if you swap the order presented to BinEncoder such that 'frontdoor.nest.com.' is placed at the end, the compression seems to be done correctly as expected. **To Reproduce** [trust-dns/crates/proto/src/rr/domain/name.rs](https://github.com/bluejekyll/trust-dns/blob/16f4e862ef158972967ab738c86d567d2938d899/crates/proto/src/rr/domain/name.rs) #[test] fn test_pointer() { let mut bytes: Vec<u8> = Vec::with_capacity(512); let first = Name::from_str("frontdoor.nest.com.").unwrap(); let second = Name::from_str("frontdoor-srt01-production-1909587911.us-east-1.elb.amazonaws.com.").unwrap(); let third = second.clone(); { let mut e = BinEncoder::new(&mut bytes); first.emit(&mut e).unwrap(); assert_eq!(e.len(), 20); second.emit(&mut e).unwrap(); assert_eq!(e.len(), 84); third.emit(&mut e).unwrap(); assert_eq!(e.len(), 86); // Should be 86 but get 148 instead that adds another 64 bytes } } **Expected behavior** Expect Name/labels to be properly compressed but the result does not seem to suggest so. **Version:** Version: [0.7.3]
kerem 2026-03-15 23:30:58 +03:00
Author
Owner

@bluejekyll commented on GitHub (Aug 4, 2020):

woh. 0.7? is there a reason you're using such an old version?

There were some label compression issues in earlier releases, but current versions should be working correctly.

<!-- gh-comment-id:668302162 --> @bluejekyll commented on GitHub (Aug 4, 2020): woh. 0.7? is there a reason you're using such an old version? There were some label compression issues in earlier releases, but current versions should be working correctly.
Author
Owner

@jacoblin1994 commented on GitHub (Aug 4, 2020):

Thank you, Benjamin, for the reply.

I also did the testing on the latest version 0.19.5 as well, which is failing as well. This compression method, emit_as_canonical, has been untouched for the past 3 years or so if I understand it correctly. Could you please confirm if you are able to compress appropriately on the above specific queries?

<!-- gh-comment-id:668319986 --> @jacoblin1994 commented on GitHub (Aug 4, 2020): Thank you, Benjamin, for the reply. I also did the testing on the latest version 0.19.5 as well, which is failing as well. This compression method, [emit_as_canonical](https://github.com/bluejekyll/trust-dns/blob/16f4e862ef158972967ab738c86d567d2938d899/crates/proto/src/rr/domain/name.rs#L587), has been untouched for the past 3 years or so if I understand it correctly. Could you please confirm if you are able to compress appropriately on the above specific queries?
Author
Owner

@bluejekyll commented on GitHub (Aug 4, 2020):

It’s been a while since I’ve looked at this. It’s quite possible the logic hasn’t changed in 3 years.

I haven’t spent a ton of time optimizing the label compression, so it wouldn’t surprise me if there are some improvements available in this area.

<!-- gh-comment-id:668396485 --> @bluejekyll commented on GitHub (Aug 4, 2020): It’s been a while since I’ve looked at this. It’s quite possible the logic hasn’t changed in 3 years. I haven’t spent a ton of time optimizing the label compression, so it wouldn’t surprise me if there are some improvements available in this area.
Author
Owner

@bluejekyll commented on GitHub (Aug 4, 2020):

Looking at this a little more, I think the issue here is that we're not picking the best label compression option, only the first found. It feels like we should have two passes here rather than the single one that is happening today. Basically, search through all the labels, and look for the longest matching one.

<!-- gh-comment-id:668771806 --> @bluejekyll commented on GitHub (Aug 4, 2020): Looking at this a little more, I think the issue here is that we're not picking the best label compression option, only the first found. It feels like we should have two passes here rather than the single one that is happening today. Basically, search through all the labels, and look for the longest matching one.
Author
Owner

@jacoblin1994 commented on GitHub (Aug 4, 2020):

It looks like trust-dns-proto does not support labels ending with a pointer compression as in encoder.trim(), the associated name_pointers get removed completely due to the new offset being set.
https://tools.ietf.org/html/rfc1035#section-4.1.4

<!-- gh-comment-id:668803284 --> @jacoblin1994 commented on GitHub (Aug 4, 2020): It looks like trust-dns-proto does not support labels ending with a pointer compression as in encoder.trim(), the associated name_pointers get removed completely due to the new offset being set. https://tools.ietf.org/html/rfc1035#section-4.1.4
Author
Owner

@bluejekyll commented on GitHub (Aug 4, 2020):

That's definitely possible. Again, this needs to be optimized, and that hasn't happened. The code clarity in this area could be improved as well.

If you were interested in working on this, I'd definitely love the help.

<!-- gh-comment-id:668812505 --> @bluejekyll commented on GitHub (Aug 4, 2020): That's definitely possible. Again, this needs to be optimized, and that hasn't happened. The code clarity in this area could be improved as well. If you were interested in working on this, I'd definitely love the help.
Author
Owner

@jacoblin1994 commented on GitHub (Aug 5, 2020):

Thanks Benjamin. Happy to help with this.

I do have a working patch that I still want to take some time polishing.

<!-- gh-comment-id:668950626 --> @jacoblin1994 commented on GitHub (Aug 5, 2020): Thanks Benjamin. Happy to help with this. I do have a working patch that I still want to take some time polishing.
Author
Owner

@jacoblin1994 commented on GitHub (Aug 6, 2020):

Hi Benjamin, could you please add me as a collaborator, so that I can make a pull request? Thanks.

<!-- gh-comment-id:670021200 --> @jacoblin1994 commented on GitHub (Aug 6, 2020): Hi Benjamin, could you please add me as a collaborator, so that I can make a pull request? Thanks.
Author
Owner

@bluejekyll commented on GitHub (Aug 6, 2020):

Usually folks fork the repo in Github, and then submit PRs from their fork in Github, that doesn't require collaborator status: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork

<!-- gh-comment-id:670025781 --> @bluejekyll commented on GitHub (Aug 6, 2020): Usually folks fork the repo in Github, and then submit PRs from their fork in Github, that doesn't require collaborator status: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork
Author
Owner

@jacoblin1994 commented on GitHub (Aug 6, 2020):

Sounds good. I will follow this. Thanks.

<!-- gh-comment-id:670026620 --> @jacoblin1994 commented on GitHub (Aug 6, 2020): Sounds good. I will follow this. Thanks.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#623
No description provided.