unicode-rs / unicode-segmentation

Grapheme Cluster and Word boundaries according to UAX#29 rules
https://unicode-rs.github.io/unicode-segmentation
Other
565 stars 57 forks source link

Program crashed #121

Closed xizheyin closed 1 year ago

xizheyin commented 1 year ago

I triggered some bugs.

The version

[dependencies]
unicode-segmentation = "=1.10.1"

bug1

The buggy code is below.

fn main() {
    let offset = 20;
    let len = 8;
    let is_extended = true;
    let chunk = " 2";
    let chunk_start = 3;
    let mut cursor = unicode_segmentation::GraphemeCursor::new(offset, len, is_extended);
    let _ = unicode_segmentation::GraphemeCursor::next_boundary(&mut cursor, chunk, chunk_start);
}

the error message is image

bug2

The buggy code is below.

fn main() {
    let offset = 20;
    let len = 8;
    let is_extended = true;
    let chunk = " 2";
    let chunk_start = 21;
    let mut cursor = unicode_segmentation::GraphemeCursor::new(offset, len, is_extended);
    let _ = unicode_segmentation::GraphemeCursor::next_boundary(&mut cursor, chunk, chunk_start);
}

the error message is image

bug3

The buggy code is below.

fn main() {
    let offset = 5;
    let len = 2;
    let is_extended = true;
    let chunk = " 2";
    let chunk_start = 3;
    let mut cursor = unicode_segmentation::GraphemeCursor::new(offset, len, is_extended);
    let _ = unicode_segmentation::GraphemeCursor::next_boundary(&mut cursor, chunk, chunk_start);
}

the error message is image

bug4

The buggy code is below.

fn main() {
    let offset = 4;
    let len = 2;
    let is_extended = true;
    let chunk = "ݴ";
    let chunk_start = 3;
    let mut cursor = unicode_segmentation::GraphemeCursor::new(offset, len, is_extended);
    let _ = unicode_segmentation::GraphemeCursor::next_boundary(&mut cursor, chunk, chunk_start);
}

the error message is image

bug5

The buggy code is below.

fn main() {
    let offset = 18446744073709551615;
    let len = 18374724962578595839;
    let is_extended = false;
    let chunk = " ";
    let chunk_start = 18446744073709551615;

    let mut cursor = unicode_segmentation::GraphemeCursor::new(offset, len, is_extended);
    let _ = unicode_segmentation::GraphemeCursor::next_boundary(&mut cursor, chunk, chunk_start);
}

the error message is image