Repository navigation
Conversation
…l names An .msi is an OLE compound file holding the installer's database and, usually, the files packed in CAB archives named by internal keys, so 7-Zip alone shows streams and keys instead of the files (KnifeLemon#1960). Filee now reads the package itself: a small streaming compound-file reader, the MSI string pool and the Directory, Component, File and Media tables. Each file gets its long name and the folder layout of an administrative image (the source part of DefaultDir), checked by ArchiveSafety like any archive entry. Embedded cabinets (#name) and bare-named cabinets beside the package are unpacked through 7-Zip; media without a cabinet take the loose files of an uncompressed image. Nothing is run. A package with no files to take out says so (error.msi_no_files, in all 23 languages). msi is a read-only Specialist archive in the developer field, learned by the archives donut in schema 112. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
The |
KnifeLemon
requested changes
Dec 2, 2026
KnifeLemon
left a comment
Owner
There was a problem hiding this comment.
Thanks a lot for this, @YusufMntm! The design is clean:
- every output path goes through
ResolveEntryPathbefore anything is written; - the chain walks are all bounded;
- cabinets get the same listing checks as other archives;
- the tests build everything in code.
The wiring, schema 112, the fields and the 23 translations all look right.
A few things before merging:
- String IDs after a long string (
MsiDatabase.ReadStringPool). The ID is taken from the slot number (var stringId = slot;), but a string of 64 KB or more uses two slots and only one ID. Wine'smsi_load_string_tablekeeps a separate counter (n) for this. As it is, every string after the first long one is shifted by one, so names and folders come out wrong. The length decode itself is right. A test with a ~70 KB string followed by a few normal ones would cover it. - The media loop is quadratic (
MsiPackage,foreach (var media in mediaList)). Each Media row rescans all planned files with.Where(...). A crafted package with about a million Media rows and a million File rows (under the entry cap, a few dozen MB) would keep a core busy for hours. SortingplannedbySequenceand walking it once with an index fixes it. - The directory chain is walked again for every file (
CollectDirectorySegments)..names don't count towardIsTooDeep, so a long chain of.directories times many files is quadratic too. Caching each directory's resolved path, or capping the walk atMaxPathDepthhops, fixes it. - The string pool size (
ReadStringPool). The slot count is only bounded by the 256 MB stream cap, so a crafted pool can create tens of millions of dictionary entries, which is gigabytes of memory. IDs past 65,535 (2-byte refs) or 16,777,215 (3-byte refs) can't be referenced anyway, so please cap the count there (or atArchiveSafety.MaxEntries).
Optional, if you're in there anyway:
- When several Media rows name the same cabinet, it's copied and unpacked once per row. Grouping by cabinet would avoid that.
CompoundFile.Parseaccepts repeated FAT sector numbers up tomaxSectors, so the FAT array can grow as large as the file. A cap of aboutmaxSectors / (sectorSize / 4) + 1FAT sectors would bound it.ReadBytesallocates the declared size and then copies it again withToArray(). Onebyte[], sized after checking the size against the file length, is enough.- For loose files beside the package, only the last part of the path is checked for a link. Checking each folder on the way would match the "no links" note in the description.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1960 (the MSI part of #1369)
What and why
An
.msiis a Windows Installer package: an OLE compound file with the installer's database, and the files usuallypacked in CAB archives whose entries are named by internal keys. As you wrote, 7-Zip shows the package's streams, so
the names it gives aren't the real ones. Filee now reads the database itself and lays the files out under their real
names and folders (to a folder, or into ZIP, 7Z, TAR and the other archive targets). Nothing is run; no msiexec.
Design
CompoundFile(new,Archives/): a small read-only compound-file reader over aFileStream(v3 and v4 sectors,DIFAT, FAT, mini stream). It never loads the whole package, since installers can be large. Chain walks are bounded,
so a FAT loop or an out-of-range sector is refused instead of hanging.
MsiDatabase(new): decodes MSI stream names, reads_StringPool/_StringData(2- and 3-byte string references,long strings, the package's codepage), then
_Columnsand only theDirectory,Component,FileandMediatables (stored column by column).
MsiPackage(new): everyFilerow gets its long name (short|long) and its folder fromComponent→Directory→ parents, using the source part ofDefaultDir. That is the layout of an administrative image(
msiexec /a), the tool you pointed to in the issue. The root (TARGETDIR/SourceDir) is the output folder, and.adds no folder. Every path goes throughArchiveSafety.ResolveEntryPath, and all of them are checked beforeanything is written.
Mediarow by sequence.#nameis an embedded cabinet stream, copied to the job's scratch folder.A bare file name is a cabinet beside the
.msi(no separators or.., no links). Each cabinet is listed andchecked like any archive (
CheckListing), unpacked with the bundled 7-Zip, and its entries are moved to the pathsof their
Filekeys..msi. A filemeant to come from a cabinet is never taken from beside the package.
Filetable, or none of its files found) refuses with the newerror.msi_no_files, inall 23 languages. If only some files are missing, the rest are extracted and the log says how many were left out.
msijoinsArchiveExtractor.BuiltInFormats(like BSP), so every archive target works.FormatRegistry:read-only archive.
FormatFields: Specialist in the developer field, like MSIX/CAB. Schema 112 teaches the archivesdonut
.msi(LearnExtensions; if another PR takes 112 first I'll renumber).SharedPresetVersions: a 2.6.0format.
msistays blocked for browser drops (WebFileNames); local files are unaffected.docs/ENGINES.md.CHANGELOG.mdis left alone; the lines are in a comment below.Tests
MsiBuilder(test helper): writes compound files, MSI tables and string pools, and stored CABs in code, so nobinary fixtures.
MsiTests:short|long,target:sourceand., to a folder and to ZIP;..\cabinet is ignored;..in a file or folder name can't escape the output;Filetable refuses witherror.msi_no_files;beside the package.
MsiFormatTests: detection, grade and field, donut, v111 → v112 migration.ArchiveTests:msiin theone-step and read-only loops.
FormatFieldsTests: Specialist count 146 → 147.Ran locally (Windows):
Filee.Engines.Tests(Msi, ArchiveTests: 110 pass),Filee.Core.Tests(FormatFields, Msi,SharedPreset, PresetGallery, UserDataStore: 404 pass, 1 skip),
Filee.App.Tests(Localization: 239 pass),dotnet format --verify-no-changeson the changed files.Also tried by hand with
filee-cli convert <x>.msi --to zipon installer packages cached on this PC. Two 8 MB vendorpackages came out with their real folders and names (e.g.
ASUS/AacAmbientHal/AacAmbientHal_x64.dll). Three cachedcopies whose cabinets Windows had stripped refused with the new message.
Not tried: multi-disc packages whose files span two cabinets (7-Zip unpacks each cabinet alone), and
.msm/.msp(merge modules and patches), which this PR doesn't register.
🤖 Generated with Claude Code