Skip to content

fix(query): prevent Unicode panic in dictionary error messages - #1801

Merged
bplatz merged 2 commits into
mainfrom
fix/unicode-dictionary-error
Sep 10, 2026
Merged

bplatz merged 2 commits into
mainfrom
fix/unicode-dictionary-error

Conversation

@bplatz

@bplatz bplatz commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

When a missing dictionary string has a multibyte UTF-8 character spanning byte 50, resolve_string_v3 panics while formatting its NotFound error. For example, 49 ASCII characters followed by ± trigger the panic; with panic=abort, this terminates the server.

Truncate the error preview to 50 Unicode characters and extract the error construction into a helper for regression coverage. Dictionary lookup behavior is unchanged.

Validation:

  • Reproduced the original panic with the regression test before restoring the fix.
  • Added coverage for two-, three-, and four-byte characters at the truncation boundary, short Unicode strings, empty strings, and ASCII truncation.
  • cargo test -p fluree-db-query --lib --locked: 1,553 passed, 1 ignored.
  • cargo fmt --all --check and git diff --check passed.
  • RUSTC_WRAPPER= cargo clippy -p fluree-db-query --lib --tests --locked --no-deps -- -D warnings passed (the local sccache wrapper failed to start).

@zonotope zonotope left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude found the same panic risk from truncating user input in 3 other paths:

  • Turtle import truncates the prefix block at byte 500 for tracing at fluree-graph-turtle/src/splitter.rs:238 and fluree-db-api/src/import.rs
  • Turtle import truncates the prefix block at byte 200 at fluree-graph-turtle/src/splitter.rs:994
  • Chunk text is truncated at byte 200 at fluree-db-api/src/import.rs:4609

The first two are tracing::info!, so they could panic in production. I'm fine with filing an issue for those if you don't want to take it in this pr.

Other than that, lgtm

@bplatz

bplatz commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in c330798

@bplatz
bplatz merged commit 44bc8bd into main Sep 10, 2026
16 checks passed
@bplatz
bplatz deleted the fix/unicode-dictionary-error branch September 10, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants