Skip to content

fix(mods): skip non-UTF-8 config names and report as unreadable (#669) - #793

Merged
Zaldaryon merged 2 commits into
devfrom
fix/issue-669-non-utf8-mod-config
Nov 10, 2026
Merged

Zaldaryon merged 2 commits into
devfrom
fix/issue-669-non-utf8-mod-config

Conversation

@Zaldaryon

Copy link
Copy Markdown
Collaborator

Problem

Issue #669: On Linux, a mod config file whose name contains invalid UTF-8 bytes (for example f\xFF.json) causes the whole ModConfig export listing walk to fail.

When Node's fse.readdir reads directory entries with default string encoding, invalid UTF-8 bytes are decoded to Unicode replacement characters (\uFFFD). Subsequent fse.lstat(entryPath) calls fail with ENOENT because the literal replacement characters do not match the on-disk filename bytes. walkModConfigs throws, GET_MOD_CONFIGS returns { ok: false, reason: "mod-config-unreadable" }, and the Manage Mods action bar disables mod config exports for the entire installation with "the folder could not be read".

Solution

  1. In walkModConfigs (src/ipc/handlers/modConfigs.ts):
    • Read directory entries using { withFileTypes: true, encoding: "buffer" } to preserve raw filesystem bytes.
    • Inspect rawName: if Buffer.isBuffer(rawName) && !isUtf8(rawName), decode it for display with rawName.toString("utf8").
    • If the unreadable entry is a directory, symbolic link, or .json file candidate, increment visitedEntries against MAX_MOD_CONFIG_LISTING_ENTRIES and record its relative path in unreadable. Non-JSON regular files are ignored.
    • Skip lstat on unreadable entries so invalid byte names never cause ENOENT.
    • Support both Buffer and string for entry.name so existing test mocks continue to function.
  2. In src/global.d.ts:
    • Extend ModConfigsReadResult with unreadable?: string[] to report unreadable filenames to callers.
  3. In ExportModConfigsDialog.tsx:
    • Render listing.unreadable entries as disabled checkboxes with subtitle t("features.mods.exportModConfigsUnreadableName"), mirroring listing.linked.
  4. In en-US.json and fr-FR.json:
    • Added "exportModConfigsUnreadableName" ("This file name could not be read." / "Ce nom de fichier n'a pas pu être lu.").
    • Updated docs/contribute/translation-status.md.
  5. Testing:
    • Added real on-disk Linux regression test in tests/ipc/modConfigs.test.ts creating f\xFF.json alongside fine.json, asserting that GET_MOD_CONFIGS lists fine.json and reports f\uFFFD.json under unreadable, and verifying collectModConfigs exports fine.json without error.
    • Added cross-platform unit test in tests/ipc/modConfigs.test.ts mocking Buffer dirents.
    • Added renderer DOM test in tests/renderer-dom/exportModConfigsDialog.test.tsx verifying disabled unreadable row rendering.

Closes #669

@Zaldaryon
Zaldaryon requested a review from Pixnop October 27, 2026 15:51
@github-actions

Copy link
Copy Markdown

Translation status

en-US is the source and carries 958 keys.

Locale Keys Missing Stale To review on Weblate
be-BY 882 113 0 Needs editing
de-DE 855 103 0 Needs editing
es-ES 882 113 0 Needs editing
fr-FR 995 0 0 Needs editing
hu-HU 855 103 0 Needs editing
it-IT 882 113 0 Needs editing
nl-NL 855 103 0 Needs editing
pl-PL 882 113 0 Needs editing
pt-BR 883 112 0 Needs editing
pt-PT 882 113 0 Needs editing
ru-RU 996 1 2 Needs editing
uk-UA 882 113 0 Needs editing
zh-CN 828 93 0 Needs editing

The links open the strings Weblate marks Needs editing for each language: the machine drafts made before Weblate, plus any string whose English changed since it was translated. See #496.

@Pixnop Pixnop 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.

I reviewed 4fa0693a against dev adab6b96: ran your new tests against dev's code, then listed and exported a real ModConfig folder holding fine.json, two Latin-1 names (caf\xE9.json, caf\xE8.json), a valid UTF-8 caf�.json, and a folder d\xFF/ with two configs inside.

The fix is in the right place. Both callers go through walkModConfigs, the GET_MOD_CONFIGS listing and collectModConfigs for the export, so one bad name no longer turns the whole folder into mod-config-unreadable, and an invalid name never reaches lstat. On dev's code the three #669 tests fail, the on-disk one included. On this head both files pass, 99 tests, and translation-status.md matches what the generator writes.

Approving. Note 1 is worth taking here, since it can untick a config the player chose. The rest can wait.

Not blocking

  1. Unreadable rows share ids with each other and with real configs. The key of an unreadable entry is built from rawName.toString("utf8") (modConfigs.ts:232), which turns every invalid byte into U+FFFD. My folder came back with unreadable: ["caf�.json", "caf�.json", "d�"]. Both Latin-1 names give the same string, so the dialog renders two rows React warns about, and nothing tells the player which file is which. Worse, the unreadable rows reuse the config rows' id prefix (ExportModConfigsDialog.tsx:167-169). With a real caf�.json next to them, the page had three elements with id="export-mod-config-caf�.json", and clicking the greyed-out row's label unticked the real, enabled config, which then drops out of the pack. A separate prefix and an index key (export-mod-config-unreadable-${index}) fix the clash. Escaping invalid bytes as \xE9 instead of U+FFFD would also keep the rows distinct and give the player a name they can find on disk. A test with two names that decode to the same string would pin it.

  2. A folder with an unreadable name hides what is inside it. The branch at modConfigs.ts:233 takes directories too and doesn't descend, which is fine, but the row then says "This file name could not be read." for a folder, and the two configs inside it are simply never offered. The string also points at a read error, when what fails is decoding the name, and unlike "Links cannot travel in a modpack." it doesn't say what happens to the entry. Something like "Names that are not valid text cannot travel in a modpack." would be true for files and folders. If the English changes, fr-FR follows. A test with an invalid folder name would pin the behaviour you pick.

  3. Two docblocks lost something. The new walkModConfigs docblock replaces the old one instead of adding to it, and drops why the folder goes through assertManagedPath and every entry is lstat'ed, why .json matches without case (Windows does), and why links are reported (the apply refuses configs at and below them). In ExportModConfigsDialog.tsx:30-31 the list now has two "or"s: "(a name Windows refuses, a name that is not valid UTF-8, one that carries hidden Unicode characters, or one that collides with another config in letter case)" reads right.

  4. The string arms of rawName only serve the #590 fixtures. With encoding: "buffer" the names are always Buffers at runtime. The string arms at modConfigs.ts:230 (: false) and 241 (: rawName) run only for the two #590 tests that feed string dirents (modConfigs.test.ts:870-881 and 910-915), and the : rawName at 232 never runs, since that branch is only entered for a Buffer. The fs-extra types still say string, so a cast stays, but it can be as unknown as Buffer once those fixtures use Buffer.from(...). Careful when you do it: isUtf8 throws on a string, and the ceiling tests expect mod-config-unreadable, so they would keep passing for the wrong reason.

@Pixnop Pixnop 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.

I reviewed d04cb5de against 4fa0693a: read the new commit, ran both test files at the new head and again with each fix put back, then listed and exported a ModConfig folder holding fine.json, a valid caf�.json, caf\xE9.json, caf\xE8.json, a\x5C\xFF.json, a\xFF.JSON, a link L\xFF, a folder d\xFF/ with a config inside, and sub/x\xFF.json.

Round one

A greyed row can no longer untick a real config. Unreadable rows have their own id prefix and an index key (ExportModConfigsDialog.tsx:167-170), and invalid bytes are written as \xHH (modConfigs.ts:236-239). My folder came back with seven distinct names, each with its folder in front where it has one, and the export still carried caf�.json and fine.json. When I put back export-mod-config-${name}, gives duplicate unreadable names their own disabled checkboxes (exportModConfigsDialog.test.tsx:264) fails. Escaping the backslash as well was the right call: two unreadable names in one folder can never give the same string.

The new string is true for folders too. "Names that are not valid text cannot travel in a modpack." reads well next to the link row, and the dirent test now pins the d\xFF folder (modConfigs.test.ts:829).

The walkModConfigs docblock has its reasons back (modConfigs.ts:193-195).

The string arms of rawName are gone, but one fixture went too far. See the first point below.

Still approved.

Not blocking

  1. The apply entry-ceiling test no longer tests the ceiling. modConfigs.test.ts:1718 now builds its entries with Buffer.from(...). That test sends a request to APPLY_MOD_CONFIGS, not dirents, and those names are strings from the renderer. A Buffer name makes assertModConfigKey throw TypeError on the first entry, so the test passes with or without the guard. I removed || files.length > MAX_MODPACK_ENTRIES from parseApplyRequest (modConfigs.ts:507) and the whole file still passes. With the string names back, the same change fails it. It is the trap from note 4, in a test that was never one of the #590 fixtures. Putting back name: `c${index}.json` on that line is enough. The fixtures at 877, 883 and 917 are right as Buffers.

  2. fr-FR says "pack de mods" once and "modpack" everywhere else. At fr-FR.json:630, "Les noms qui ne sont pas du texte valide ne peuvent pas voyager dans un modpack." would match its neighbour, "Les liens ne peuvent pas voyager dans un modpack."

  3. Two docblocks still describe the old names. global.d.ts:771 says unreadable names entries that are not valid UTF-8, reported by name. They now come escaped: every byte outside printable ASCII, and the backslash, written as \xHH, with the parent folder in front. One sentence would say so. ExportModConfigsDialog.tsx:30 still says "file name" although folders land there too.

The Windows Node 26 leg failed its first run on puts two names for one inode back as two ordinary files (tests/ipc/extraction.test.ts:421), a backup test this pull request does not touch and no open pull request fixes yet. The rerun passed. translation-status.md conflicts with #797 and #803, and whichever of #791 and this one merges second has to regenerate it.

@Zaldaryon
Zaldaryon merged commit f040164 into dev Nov 10, 2026
22 of 24 checks passed
@Zaldaryon
Zaldaryon deleted the fix/issue-669-non-utf8-mod-config branch November 10, 2026 23:13
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.

2 participants