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

[uniset] Crash when testing for non-first range #268

Closed
zbraniecki opened this issue Sep 24, 2020 · 1 comment · Fixed by #269
Closed

[uniset] Crash when testing for non-first range #268

zbraniecki opened this issue Sep 24, 2020 · 1 comment · Fixed by #269
Assignees
Labels
C-unicode Component: Props, sets, tries T-bug Type: Bad behavior, security, privacy

Comments

@zbraniecki
Copy link
Member

use icu_unicodeset::UnicodeSet;
use icu_unicodeset::UnicodeSetBuilder;
use std::char;

fn main() {
    let ranges = vec!['A'..='Z', 'a'..='z'];
    let mut builder = UnicodeSetBuilder::new();

    for range in &ranges {
        builder.add_range(range);
    }

    let set = builder.build();

    assert_eq!(set.contains_range(&('c'..='e')), true);
}

crashes with:

thread 'main' panicked at 'index out of bounds: the len is 4 but the index is 4', /Users/zbraniecki/projects/icu4x/components/uniset/src/uniset.rs:189:36

full stack:

thread 'main' panicked at 'index out of bounds: the len is 4 but the index is 4', /Users/zbraniecki/projects/icu4x/components/uniset/src/uniset.rs:189:36
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: std::panicking::rust_panic_with_hook
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::panicking::panic_bounds_check
   9: <usize as core::slice::SliceIndex<[T]>>::index
  10: core::slice::<impl core::ops::index::Index<I> for [T]>::index
  11: <alloc::vec::Vec<T> as core::ops::index::Index<I>>::index
  12: icu_unicodeset::uniset::UnicodeSet::contains_range
  13: uniset_test::main
  14: std::rt::lang_start::{{closure}}
  15: std::rt::lang_start_internal
  16: std::rt::lang_start
  17: main
@zbraniecki zbraniecki added T-bug Type: Bad behavior, security, privacy C-unicode Component: Props, sets, tries labels Sep 24, 2020
@EvanJP EvanJP self-assigned this Sep 24, 2020
@EvanJP
Copy link
Contributor

EvanJP commented Sep 24, 2020

I apologize for the bug:

Further outlined in fix #269 , there was an off by one error that I failed to account for in my testing. Thanks for pointing it out! Should be merged tomorrow.

EvanJP added a commit that referenced this issue Sep 24, 2020
Resolves #268 with an off-by-one error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-unicode Component: Props, sets, tries T-bug Type: Bad behavior, security, privacy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants