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

[xi-core-lib] Out-of-range crash occurs when using APIs #1351

Open
HeeillWang opened this issue Sep 24, 2023 · 0 comments
Open

[xi-core-lib] Out-of-range crash occurs when using APIs #1351

HeeillWang opened this issue Sep 24, 2023 · 0 comments

Comments

@HeeillWang
Copy link

Details

I found some out-of-range patterns on xi-core-lib public APIs. All of these cases triggered when external crates use API of xi-core-lib.
As this issues looks quite obvious, I just list up the panic location. Please let me know if anyone need reproduce code for other cases.

Case-1

Thread '<unnamed>' panicked at 'slice index starts at 1 but ends at 0', xi-core-lib-0.3.0/src/selection.rs:137
    /// Gets a slice of regions that intersect the given range. Regions that    /// merely touch the range at the edges are also included, so it is the
    /// caller's responsibility to further trim them, in particular to only
    /// display one caret in the upstream/downstream cases.
    ///
    /// Performance note: O(log n).
    pub fn regions_in_range(&self, start: usize, end: usize) -> &[SelRegion] {
        let first = self.search(start);
        let mut last = self.search(end);
        if last < self.regions.len() && self.regions[last].min() <= end {
            last += 1;
        }
        &self.regions[first..last]   // out-of-range!
    }

Case-2

Thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', xi-core-lib-0.3.0/src/selection.rs:73
    /// Collapse all selections into a single caret.
    pub fn collapse(&mut self) {
        self.regions.truncate(1);
        self.regions[0].start = self.regions[0].end;   // out-of-range!
    }

Expected vs Actual

There should be range check via assert statement or should mention panic condition on docs.

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

No branches or pull requests

1 participant