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

U16String::pop_char panic with surrogate string #38

Closed
touilleMan opened this issue Mar 13, 2024 · 0 comments
Closed

U16String::pop_char panic with surrogate string #38

touilleMan opened this issue Mar 13, 2024 · 0 comments
Labels

Comments

@touilleMan
Copy link

touilleMan commented Mar 13, 2024

#[test]
fn truncated_with_surrogate() {
    // Character U+24B62, encoded as D852 DF62 in UTF16
    let buf= "𤭢";
    let mut s = widestring::U16String::from_str(buf);
    s.pop_char();
}

output:

thread 'windows::mount::tests::truncated_with_surrogate' panicked at C:\Users\gbleu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\widestring-1.0.2\src\ustring.rs:1286:42:
index out of bounds: the len is 1 but the index is 1
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\std\src\panicking.rs:645
   1: core::panicking::panic_fmt
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\panicking.rs:72
   2: core::panicking::panic_bounds_check
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\panicking.rs:190
   3: core::slice::index::impl$2::index<u16>
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\core\src\slice\index.rs:258
   4: alloc::vec::impl$12::index<u16,usize,alloc::alloc::Global>
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\alloc\src\vec\mod.rs:2732
   5: widestring::ustring::U16String::pop_char
             at C:\Users\gbleu\.cargo\registry\src\index.crates.io-6f17d22bba15001f\widestring-1.0.2\src\ustring.rs:1286
   6: libparsec_platform_mountpoint::windows::mount::tests::truncated_with_surrogate
             at .\tests\unit\windows_volume_label.rs:40
   7: libparsec_platform_mountpoint::windows::mount::tests::truncated_with_surrogate::closure$0
             at .\tests\unit\windows_volume_label.rs:35
   8: core::ops::function::FnOnce::call_once<libparsec_platform_mountpoint::windows::mount::tests::truncated_with_surrogate::closure_env$0,tuple$<> >
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112\library\core\src\ops\function.rs:250
   9: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library\core\src\ops\function.rs:250
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

   Canceling due to test failure: 0 tests still running

I guess this is due to a off-by-one issue here:

let high = self.inner[self.len()];

(should be self.inner[self.len() - 1] )

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

No branches or pull requests

2 participants