Skip to content

Panic on files containing any non-ASCII (e.g. Japanese) identifier: src/node_kind.rs:194:9: index out of bounds: the len is 256 but the index is 65535 #255

Description

@minami110

Tested on gdscript-formatter 0.21.0 (Pre-release 0.21.0-beta, published 2026-07-12), Linux x86_64. Upstream main checked up to 248fa13b (2026-07-12 09:20 UTC) — no fix commit found.

Impact

Formatter panics with exit 1 and produces no output. --reorder-code fails outright; plain format also panics on the same input. Any project that uses non-ASCII identifiers has affected files silently skipped by tooling.

Minimal repro

Entire .gd file, 1 line:

var 変数: int

Command:

gdscript-formatter --stdout --reorder-code bug.gd

Actual output

Formatting 1 file...
thread '<unnamed>' (pid) panicked at src/node_kind.rs:194:9:
index out of bounds: the len is 256 but the index is 65535
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

thread 'main' (pid) panicked at src/main.rs:293:38:
worker thread panicked: Any { .. }

Same panic without --reorder-code.

Expected

Format completes and returns:

var 変数: int

Boundary (verified individually on 0.21.0-beta)

Does NOT panic (non-ASCII is safe in these positions):

  • inside a # comment
  • inside a plain string literal "あいうえお"
  • inside a StringName literal &"あいうえお"
  • inside a res://.../日本語/... path string

DOES panic (non-ASCII in an identifier position is the trigger):

  • variable name: var 変数: int
  • const name: const _状態 := &"..."
  • function / parameter name: func 判定(値: String) -> bool: return 値 == "test"
  • match arm literal referring to Japanese identifiers indirectly

So the necessary and sufficient condition is a non-ASCII character appearing in an identifier position.

Hypothesis

src/node_kind.rs:194:9 doing an indexed lookup with a u16 value that overflows to 65535 (u16::MAX) when the lexer/parser encounters an identifier byte outside the ASCII range. The len is 256 in the error suggests a 256-entry table keyed by a u8/enum discriminant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstreamThe issue (likely) can't be solved in this repository: a library needs a change

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions