pubky / pkarr

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

`&str.try_into::<Result<PublicKey>>()` panics #43

Closed SeverinAlexB closed 7 months ago

SeverinAlexB commented 7 months ago

Bug report

&str.try_into::<Result<PublicKey>>(), more specifically thez32 lib panics with the wrong input. try_into should explicitly not panic though.

How to reproduce

    #[test]
    fn pkarr_parse() {
        let invalid_pubkey = "com";
        let trying: Result<PublicKey, _> = invalid_pubkey.try_into();
        assert!(trying.is_err());
    }

Stacktrace

thread 'pkarr_resolver::tests::pkarr_parse' panicked at /Users/severinbuhler/.cargo/registry/src/index.crates.io-6f17d22bba15001f/z32-1.0.2/src/lib.rs:151:13:
index out of bounds: the len is 3 but the index is 3
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::panicking::panic_bounds_check
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/panicking.rs:190:5
   3: z32::quintet
             at /Users/severinbuhler/.cargo/registry/src/index.crates.io-6f17d22bba15001f/z32-1.0.2/src/lib.rs:151:13
   4: z32::decode
             at /Users/severinbuhler/.cargo/registry/src/index.crates.io-6f17d22bba15001f/z32-1.0.2/src/lib.rs:122:13
   5: <pkarr::keys::PublicKey as core::convert::TryFrom<&str>>::try_from
             at /Users/severinbuhler/.cargo/registry/src/index.crates.io-6f17d22bba15001f/pkarr-1.0.1/src/keys.rs:103:13
   6: <T as core::convert::TryInto<U>>::try_into
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/convert/mod.rs:796:9
   7: dns_server::pkarr_resolver::tests::pkarr_parse
             at ./src/pkarr_resolver.rs:156:44
   8: dns_server::pkarr_resolver::tests::pkarr_parse::{{closure}}
             at ./src/pkarr_resolver.rs:154:21
   9: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
  10: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5