Skip to content

API incorrectly assumes a host will always be part of the URL, panics #74

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
mqudsi opened this issue Dec 3, 2024 · 2 comments · Fixed by #75
Closed

API incorrectly assumes a host will always be part of the URL, panics #74

mqudsi opened this issue Dec 3, 2024 · 2 comments · Fixed by #75

Comments

@mqudsi
Copy link

mqudsi commented Dec 3, 2024

Parsing a valid URL without a hostname causes ada-url to panic when calling Url.host(). Reproduced with v3.0.0 from crates.io.

e.g. Url::parse("file:///C:/Users/User/Documents/example.pdf", None).unwrap() then call .host() on the result:

Backtrace:

thread 'main' panicked at core/src/panicking.rs:223:5:
unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a47555110cf09b3ed59811d9b02235443e76a595/library/std/src/panicking.rs:665:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/a47555110cf09b3ed59811d9b02235443e76a595/library/core/src/panicking.rs:119:22
   2: core::panicking::panic_nounwind_fmt
             at /rustc/a47555110cf09b3ed59811d9b02235443e76a595/library/core/src/intrinsics/mod.rs:3535:9
   3: core::panicking::panic_nounwind
             at /rustc/a47555110cf09b3ed59811d9b02235443e76a595/library/core/src/panicking.rs:223:5
   4: core::slice::raw::from_raw_parts::precondition_check
             at /home/mqudsi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ub_checks.rs:69:21
   5: core::slice::raw::from_raw_parts
             at /home/mqudsi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ub_checks.rs:76:17
   6: ada_url::ffi::ada_string::as_str
             at /home/mqudsi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ada-url-3.0.0/src/ffi.rs:23:25
   7: ada_url::Url::host
             at /home/mqudsi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ada-url-3.0.0/src/lib.rs:463:9
   8: ada_rust::url_to_debug
             at ./src/main.rs:51:23
   9: ada_rust::<impl core::convert::Into<ada_rust::DebugUrl> for &ada_url::Url>::into
             at ./src/main.rs:74:9
  10: ada_rust::main
             at ./src/main.rs:22:39
  11: core::ops::function::FnOnce::call_once
             at /home/mqudsi/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
@anonrig
Copy link
Member

anonrig commented Dec 3, 2024

Thank you for the bug report. I've opened a PR to address this issue. #75

@anonrig
Copy link
Member

anonrig commented Dec 3, 2024

I released v3.1.0 which addresses this bug.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants