pubky / pkarr

Public Key Addressable Resource Records (sovereign TLDs)
https://app.pkarr.org
MIT License
153 stars 17 forks source link

`InsufficientData` round 2 #46

Closed SeverinAlexB closed 6 months ago

SeverinAlexB commented 7 months ago

Bug Report

Since #45, I am not able to parse this cname anymore.

called `Result::unwrap()` on an `Err` value: InsufficientData
stack backtrace:
   0: rust_begin_unwind
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1653:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/result.rs:1077:23
   4: pkdns::pkarr_resolver::tests::pkarr_invalid_packet3
             at ./src/pkarr_resolver.rs:339:9
   5: pkdns::pkarr_resolver::tests::pkarr_invalid_packet3::{{closure}}
             at ./src/pkarr_resolver.rs:319:31
   6: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5

How to reproduce

#[cfg(test)]
mod tests {
    use pkarr::{dns::{rdata::RData, Name, Packet, ResourceRecord}, Keypair, SignedPacket};

    #[test]
    fn pkarr_invalid_packet3() {
        let keypair = Keypair::random();
        let pubkey_z32 = keypair.to_z32();

        // Construct reply with single CNAME record.
        let mut packet = Packet::new_reply(0);

        let name = Name::new("www.pknames.p2p").unwrap();
        let data = format!("pknames.p2p.{pubkey_z32}");
        let data = Name::new(&data).unwrap();
        let answer3 = ResourceRecord::new(
            name.clone(), simple_dns::CLASS::IN, 100, simple_dns::rdata::RData::CNAME(simple_dns::rdata::CNAME(data))
        );
        packet.answers.push(answer3);

        // Sign packet
        let signed_packet = SignedPacket::from_packet(&keypair, &packet).unwrap();

        // Serialize and parse again
        let reply_bytes = signed_packet.packet().build_bytes_vec().unwrap();
        Packet::parse(&reply_bytes).unwrap(); // Fail
    }
}

What to expect

Should parse as usual.

Nuhvi commented 7 months ago

@SeverinAlexB This seems to be a bug in simple-dns but in the meantime, use build_bytes_vec_compressed instead of build_bytes_vec() and it should work.

I will track the bug and maybe open a PR in simple-dns, but it is not urgent, you can make do with the compressed bytes which is better anyways.

SeverinAlexB commented 7 months ago

Thanks! I'll give the compress byes a try.

Nuhvi commented 7 months ago

@SeverinAlexB Issue opened in the upstream dependency https://github.com/balliegojr/simple-dns/issues/29