Repository navigation
fix(mods): skip non-UTF-8 config names and report as unreadable (#669) - #793
Conversation
Translation statusen-US is the source and carries 958 keys.
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
left a comment
There was a problem hiding this comment.
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
-
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 withunreadable: ["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 realcaf�.jsonnext to them, the page had three elements withid="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\xE9instead 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. -
A folder with an unreadable name hides what is inside it. The branch at
modConfigs.ts:233takes 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. -
Two docblocks lost something. The new
walkModConfigsdocblock replaces the old one instead of adding to it, and drops why the folder goes throughassertManagedPathand every entry islstat'ed, why.jsonmatches without case (Windows does), and why links are reported (the apply refuses configs at and below them). InExportModConfigsDialog.tsx:30-31the 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. -
The string arms of
rawNameonly serve the #590 fixtures. Withencoding: "buffer"the names are always Buffers at runtime. The string arms atmodConfigs.ts:230(: false) and241(: rawName) run only for the two #590 tests that feed string dirents (modConfigs.test.ts:870-881and910-915), and the: rawNameat 232 never runs, since that branch is only entered for a Buffer. The fs-extra types still saystring, so a cast stays, but it can beas unknown as Bufferonce those fixtures useBuffer.from(...). Careful when you do it:isUtf8throws on a string, and the ceiling tests expectmod-config-unreadable, so they would keep passing for the wrong reason.
Pixnop
left a comment
There was a problem hiding this comment.
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
-
The apply entry-ceiling test no longer tests the ceiling.
modConfigs.test.ts:1718now builds its entries withBuffer.from(...). That test sends a request toAPPLY_MOD_CONFIGS, not dirents, and those names are strings from the renderer. A Buffer name makesassertModConfigKeythrowTypeErroron the first entry, so the test passes with or without the guard. I removed|| files.length > MAX_MODPACK_ENTRIESfromparseApplyRequest(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 backname: `c${index}.json`on that line is enough. The fixtures at 877, 883 and 917 are right as Buffers. -
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." -
Two docblocks still describe the old names.
global.d.ts:771saysunreadablenames 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:30still 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.
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.readdirreads directory entries with default string encoding, invalid UTF-8 bytes are decoded to Unicode replacement characters (\uFFFD). Subsequentfse.lstat(entryPath)calls fail withENOENTbecause the literal replacement characters do not match the on-disk filename bytes.walkModConfigsthrows,GET_MOD_CONFIGSreturns{ 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
walkModConfigs(src/ipc/handlers/modConfigs.ts):{ withFileTypes: true, encoding: "buffer" }to preserve raw filesystem bytes.rawName: ifBuffer.isBuffer(rawName) && !isUtf8(rawName), decode it for display withrawName.toString("utf8")..jsonfile candidate, incrementvisitedEntriesagainstMAX_MOD_CONFIG_LISTING_ENTRIESand record its relative path inunreadable. Non-JSON regular files are ignored.lstaton unreadable entries so invalid byte names never causeENOENT.Bufferandstringforentry.nameso existing test mocks continue to function.src/global.d.ts:ModConfigsReadResultwithunreadable?: string[]to report unreadable filenames to callers.ExportModConfigsDialog.tsx:listing.unreadableentries as disabled checkboxes with subtitlet("features.mods.exportModConfigsUnreadableName"), mirroringlisting.linked.en-US.jsonandfr-FR.json:"exportModConfigsUnreadableName"("This file name could not be read." / "Ce nom de fichier n'a pas pu être lu.").docs/contribute/translation-status.md.tests/ipc/modConfigs.test.tscreatingf\xFF.jsonalongsidefine.json, asserting thatGET_MOD_CONFIGSlistsfine.jsonand reportsf\uFFFD.jsonunderunreadable, and verifyingcollectModConfigsexportsfine.jsonwithout error.tests/ipc/modConfigs.test.tsmocking Buffer dirents.tests/renderer-dom/exportModConfigsDialog.test.tsxverifying disabled unreadable row rendering.Closes #669