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

Crash introduced in 0.26.2 about char boundaries #1058

Closed
bugnano opened this issue Apr 23, 2024 · 1 comment
Closed

Crash introduced in 0.26.2 about char boundaries #1058

bugnano opened this issue Apr 23, 2024 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@bugnano
Copy link

bugnano commented Apr 23, 2024

Description

When upgrading from Ratatui 0.26.1 to 0.26.2 my app started crashing when trying to display the attached file.
lorem.txt

The panic is as follows:

thread 'main' panicked at /home/fri/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ratatui-0.26.2/src/text/line.rs:477:59:
byte index 92 is not a char boundary; it is inside 'σ' (bytes 91..93) of `Μεα θε δισαθ φαλλι οφφισιις. Ναμ δυις ιριυρε αδ. Φασιλις σεθερος αλβυσιυς ατ μει, μελ υθ ρεπυδιαρε ασεντιορ ινσιδεριντ. Σαεπε πρωβατυς ηις αν`[...]

I'm displaying this file in a Table, where each line is a cell in the table.

I'll update this bug report with a minimal project that crashes.

Note that Ratatui 0.26.1 worked fine.

To Reproduce

Expected behavior

Screenshots

Environment

  • OS: Linux
  • Terminal Emulator: Gnome Terminal
  • Font: Liberation Mono
  • Crate version: 0.26.2
  • Backend: Termion

Additional context

The bug was introduced by #987 .
The #987 PR doesn't take into consideration that UTF-8 uses multi-byte characters, so it's wrong to assume that

span.content[offset as usize..span_end]

is at char boundaries.
Moreover, you also must be very carful that some chars have a width of 1, some have a width of 2, and some have a width of 0, so the truncated function introduced in that PR needs to be refactored taking those things into consideration.
cc @TadoTheMiner

@EdJoPaTo
Copy link
Member

Duplicate of #1032

@EdJoPaTo EdJoPaTo marked this as a duplicate of #1032 Apr 23, 2024
@orhun orhun added the duplicate This issue or pull request already exists label Apr 23, 2024
@bugnano bugnano closed this as completed Apr 23, 2024
@bugnano bugnano closed this as not planned Won't fix, can't repro, duplicate, stale Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants