Skip to content

Multi glyph runs in text input could crash #36449

Closed

Description

@wusyong

Describe the bug:
Not sure why search bar from google.com and textarea doesn't have this bug.
But I found text input might crash in a subtle manner.
The caret is missing even after pressing a few times of right arrow.

To Reproduce:

  • Create a html file with following code and run with servoshell:
<input id="input_element" value="xxxxxxxxxxxxxxxxxxxx">
  • Focus text input and the press right arrow 1 time
  • type Bopomo "ㄎ"
  • It will crash with following log:
iter_glyphs_for_range: range.end beyond length! (thread Script(1,1), at \servo\components\fonts\glyph.rs:614)
[2025-04-10T16:16:25Z ERROR servoshell::panic_hook] iter_glyphs_for_range: range.end beyond length!

Platform:
Windows 11

Activity

  1. added
    C-untriaged
    on Apr 10, 2025
  2. added
    C-has-manual-testcase
    I-panic
    and removed
    C-untriaged
    on Apr 10, 2025
  3. dklassic commented on Apr 10, 2025

    @dklassic
    Contributor

    Did some initial digging, a lot of things are in play here:

    • In this example, the xxxxxxxxxxxxxxxxxxxx is a two glyph run text fragment which isn't properly covered by current implementation. (Where is it when I needed it the most)
    • This text is composed by a glyph run with length of 3 and another with a length of 20.
    • This text has the range of 0..23, apparently something other the 20 x are counted, I kind of suspect something similar to Selecting text in a text input deletes text instead #22345
    • The above range offset throw the rest of the calculations off track as upon testing the Selection Range is still reported within range of 0..20.

    I'll have to dig deeper later and see if I can come up with a fix.

    Edit:

    Image

    okay so apparently a ZERO WIDTH SPACE unicode character is what causes the 3 byte shift in this case..... I have no idea where it came from.

  4. dklassic commented on Apr 11, 2025

    @dklassic
    Contributor

    if is_text_input_element || is_textarea_element {
    let info = NodeAndStyleInfo::new(parent_element, parent_element.style(context));
    if is_text_input_element {
    // The addition of zero-width space here forces the text input to have an inline formatting
    // context that might otherwise be trimmed if there's no text. This is important to ensure
    // that the input element is at least as tall as the line gap of the caret:
    // <https://drafts.csswg.org/css-ui/#element-with-default-preferred-size>.
    //
    // TODO: Is there a less hacky way to do this?
    handler.handle_text(&info, "\u{200B}".into());
    }
    handler.handle_text(&info, parent_element.to_threadsafe().node_text_content());
    }

    So seems like the zero width space is introduced to to "forces the text input to have an inline formatting context that might otherwise be trimmed if there's no text", I guess if we're to fix this issue we'll have to deal with this.

    And therefore this issue actually has nothing to do with CJK character.

  5. changed the title [-]Type CJK character in text input could crash[/-] [+]Multi glyph runs in text input could crash[/+] on Apr 11, 2025
  6. dklassic commented on Apr 11, 2025

    @dklassic
    Contributor

    Not sure why search bar from google.com and textarea doesn't have this bug.

    Also to add to this, turns out search bar from google.com is actually a text area, I've been using it to test for <input> for so long turns out my whole life is a lie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-platform/fontsC-has-manual-testcaseI-panic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions