Skip to content

Fix Malformed Preset Filenames#6615

Open
unreference wants to merge 2 commits into
HarbourMasters:develop-ackbarfrom
unreference:fix/preset-name-sanitization
Open

Fix Malformed Preset Filenames#6615
unreference wants to merge 2 commits into
HarbourMasters:develop-ackbarfrom
unreference:fix/preset-name-sanitization

Conversation

@unreference
Copy link
Copy Markdown

This fixes #6586.

Preset names are used directly as filenames without sanitization. Characters like : are illegal in Windows filenames -- on NTFS, : creates an Alternate Data Stream instead of a regular file. A preset called "test :)" bricks the app. The save produces a malformed file, LoadPresets calls nlohmann::json::parse on it with no error handling, and the resulting exception crashes the app on every subsequent launch.

  • New SanitizeFilename function replaces < > : " / \ | ? * and control characters with _, stripping trailing dots and spaces. Applied in both SavePreset and FormatPresetPath (used by delete). The preset's display name in JSON is unchanged -- the user still sees their original name in the UI.
  • std::ofstream doesn't throw on failure -- it fails silently. An is_open() check after opening lets the app log an error and returns instead of writing to a failed stream.
  • Wrapped nlohmann::json::parse in a try-catch so a malformed preset file logs an error and is skipped instead of crashing the app. This also serves to recover any existing installations stuck in a crash loop from previously created bad presets.

@unreference unreference changed the title Preset Name Filename Sanitization Fix Malformed Preset Filenames May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant