Skip to content

feat(archives): open Windows Installer packages (.msi) with their real names - #1994

Open
YusufMntm wants to merge 1 commit into
KnifeLemon:mainfrom
YusufMntm:feat/msi-extract-1960
Open

YusufMntm wants to merge 1 commit into
KnifeLemon:mainfrom
YusufMntm:feat/msi-extract-1960

Conversation

@YusufMntm

Copy link
Copy Markdown
Contributor

Fixes #1960 (the MSI part of #1369)

What and why

An .msi is a Windows Installer package: an OLE compound file with the installer's database, and the files usually
packed 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 a FileStream (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 _Columns and only the Directory, Component, File and Media
    tables (stored column by column).
  • MsiPackage (new): every File row gets its long name (short|long) and its folder from Component →
    Directory → parents, using the source part of DefaultDir. 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 through ArchiveSafety.ResolveEntryPath, and all of them are checked before
    anything is written.
    • Bytes come per Media row by sequence. #name is 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 and
      checked like any archive (CheckListing), unpacked with the bundled 7-Zip, and its entries are moved to the paths
      of their File keys.
    • Media without a cabinet (uncompressed packages) take the loose files at the same paths beside the .msi. A file
      meant to come from a cabinet is never taken from beside the package.
    • Nothing to take out (no File table, or none of its files found) refuses with the new error.msi_no_files, in
      all 23 languages. If only some files are missing, the rest are extracted and the log says how many were left out.
  • Wiring: msi joins ArchiveExtractor.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 archives
    donut .msi (LearnExtensions; if another PR takes 112 first I'll renumber). SharedPresetVersions: a 2.6.0
    format. msi stays blocked for browser drops (WebFileNames); local files are unaffected.
  • Docs: README archives row, docs/ENGINES.md. CHANGELOG.md is 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 no
    binary fixtures.
  • MsiTests:
    • a mini-stream and a regular stream are read back; a FAT loop or an out-of-range sector is refused;
    • nested folders with short|long, target:source and ., to a folder and to ZIP;
    • a neighbouring cabinet is used and a ..\ cabinet is ignored;
    • two media map files by sequence; 3-byte string references are read;
    • .. in a file or folder name can't escape the output;
    • no File table refuses with error.msi_no_files;
    • loose files of an uncompressed package are copied, and a file that should come from a cabinet isn't taken from
      beside the package.
  • MsiFormatTests: detection, grade and field, donut, v111 → v112 migration. ArchiveTests: msi in the
    one-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-changes on the changed files.

Also tried by hand with filee-cli convert <x>.msi --to zip on installer packages cached on this PC. Two 8 MB vendor
packages came out with their real folders and names (e.g. ASUS/AacAmbientHal/AacAmbientHal_x64.dll). Three cached
copies 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

…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>
@YusufMntm
YusufMntm requested a review from KnifeLemon as a code owner December 2, 2026 15:57
@YusufMntm

Copy link
Copy Markdown
Contributor Author

The CHANGELOG.md lines for this one, for the CHANGELOG PR:

ko: Windows Installer 패키지(.msi)를 실행하지 않고 안의 파일을 원래 이름과 폴더 그대로 풀거나 ZIP, 7Z 같은 압축 파일로 바꿀 수 있어요
en: Windows Installer packages (.msi) unpack, or convert to ZIP, 7Z and other archives, with their real file names and folders, without running the installer
- **Windows Installer packages** (#1960). `.msi` files extract to a folder or convert to ZIP, 7Z, TAR and the other
  archive formats with their real names and folders: Filee reads the package's tables itself and unpacks its embedded
  or neighbouring cabinets with 7-Zip. Nothing is run.

@github-actions github-actions Bot added the feature New features label Dec 2, 2026

@KnifeLemon KnifeLemon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this, @YusufMntm! The design is clean:

  • every output path goes through ResolveEntryPath before 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:

  1. 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's msi_load_string_table keeps 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.
  2. 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. Sorting planned by Sequence and walking it once with an index fixes it.
  3. The directory chain is walked again for every file (CollectDirectorySegments). . names don't count toward IsTooDeep, so a long chain of . directories times many files is quadratic too. Caching each directory's resolved path, or capping the walk at MaxPathDepth hops, fixes it.
  4. 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 at ArchiveSafety.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.Parse accepts repeated FAT sector numbers up to maxSectors, so the FAT array can grow as large as the file. A cap of about maxSectors / (sectorSize / 4) + 1 FAT sectors would bound it.
  • ReadBytes allocates the declared size and then copies it again with ToArray(). One byte[], 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Format]: .msi

2 participants