Skip to content

fix(ui): handle invalid UTF-8 and NaN in layout JSON serialization#168

Open
Selene29 wants to merge 1 commit intoDeusData:mainfrom
Selene29:fix/layout-utf8-nan-json
Open

fix(ui): handle invalid UTF-8 and NaN in layout JSON serialization#168
Selene29 wants to merge 1 commit intoDeusData:mainfrom
Selene29:fix/layout-utf8-nan-json

Conversation

@Selene29
Copy link
Copy Markdown

Summary

A single non-UTF-8 symbol in any node name or file path causes the entire /api/layout endpoint to fail with "JSON serialization failed", returning HTTP 500 for the whole project. yyjson's default write mode rejects invalid UTF-8 (error code 7), so one bad byte wrecks the entire graph visualization.

  • Use YYJSON_WRITE_ALLOW_INVALID_UNICODE for layout JSON serialization, matching the flag already used by the MCP JSON-RPC serializer
  • Sanitize NaN/Inf float values in node positions and sizes before serialization (force layout can produce these edge cases)
  • Use yyjson_mut_write_opts with error reporting so future serialization failures log the actual yyjson error code and message

Test plan

  • scripts/test.sh SANITIZE= passes (2507 passed, 61 skipped — skips are network-dependent integration tests)
  • Verified manually: layout endpoint now renders a full large repo that previously failed with "JSON serialization failed"

The layout endpoint failed with "JSON serialization failed" for projects
containing non-UTF-8 strings in node names or file paths. yyjson's
default write mode rejects invalid UTF-8 (error code 7), causing the
entire layout response to fail.

- Use YYJSON_WRITE_ALLOW_INVALID_UNICODE for layout JSON serialization,
  matching the flag already used by the MCP JSON-RPC serializer
- Sanitize NaN/Inf float values in node positions and sizes before
  serialization (force layout can produce these edge cases)
- Use yyjson_mut_write_opts with error reporting so future failures
  log the actual yyjson error code and message
@DeusData DeusData added bug Something isn't working ux/behavior Display bugs, docs, adoption UX labels Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ux/behavior Display bugs, docs, adoption UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants