Skip to content

Fix 18 correctness and security defects in Rust and C# - #66

Merged
Marc-André Moreau (mamoreau-devolutions) merged 2 commits into
masterfrom
claude/code-defect-analysis-ac5b0b
Nov 6, 2026
Merged

Marc-André Moreau (mamoreau-devolutions) merged 2 commits into
masterfrom
claude/code-defect-analysis-ac5b0b

Conversation

@mamoreau-devolutions

Copy link
Copy Markdown
Contributor

Summary

Fixes 18 defects found during a review of the Rust and C# implementations. Where a bug existed in both, both are fixed. Each fix has a regression test.

Security

  • MSIX path injection (Rust + C#): the installer file name comes from the manifest URL and was pasted into a single-quoted Add-AppxPackage -Path '…' script. A ' in the path broke the install, and a crafted name could run arbitrary PowerShell. The path is now passed through an environment variable.
  • Admin settings not enforced (Rust + C#): --ignore-security-hash and --manifest were always honoured. They are now refused unless InstallerHashOverride / LocalManifestFiles is enabled, matching WinGet. ⚠️ This changes behaviour: callers that rely on these flags must enable the admin setting first.
  • Zip symlink guard (Rust): the pre-scan used mode & S_IFMT == S_IFLNK, but ZipArchive::extract creates a symlink for any mode & S_IFLNK == S_IFLNK. So entries such as 0o160777 passed the check and were still extracted as symlinks pointing outside the install folder. The guard now uses the crate's own is_symlink(), and it also covers the non-portable zip extraction path.

Crashes and broken flows

  • Panic on non-ASCII ARP key names (Rust): winget_package_identity_from_local_id sliced a string at a byte offset that could land inside a character. An installed app such as Äpfel Editor crashed pinget list. Over COM, panic = "abort" killed powershell.exe.
  • Windows PowerShell 5.1 (PS): Find-, Get- and Update-PingetPackage always threw. The Net48 client read snake_case keys, but SearchResponse/ListResponse are serialized in PascalCase.
  • V1 index installs (C#): the manifest hash BLOB was read as a string, and pathparts.pathpart (text) was read as a rowid. Every show and install through a V1 index failed the hash check.
  • --override on MSI/WiX (Rust + C#): the override replaced /i <package> along with the switches, so msiexec was launched with no package.
  • export -o <file> (Rust CLI): clashed with the global --output format flag, so export could never succeed.

Wrong results

  • Version ordering (Rust + C#): pre-release versions ranked above the release (1.0.0-rc1 > 1.0.0), which hid upgrades.
  • V1 latest-version selection (C#): versions were ordered as text, so 9.0.0 beat 10.0.0.
  • Unscoped installers (Rust): installers without a Scope were rejected when a scope was requested or inherited, so upgrades failed with "No applicable installer".
  • Numeric-looking PackageVersion (Rust): 1.10 was parsed as the float 1.1.
  • Failed dependencies (Rust + C#): a failed dependency install no longer lets the main install continue.
  • Exit codes (C# CLI): failed install/uninstall/repair now exit with a non-zero code.
  • upgrade --version (C# CLI + PS): the target version was applied as a filter on the installed version, so nothing matched. Piped Uninstall/Repair used the available version instead of the installed one.
  • export --source (C# CLI): exported only packages whose name or ID contained a space. Packages are now grouped by their real source, and packages with no source are skipped.
  • Named upgrades (Rust CLI): pinget upgrade --id Microsoft.Edge / pinget upgrade git upgraded every installed package whose ID or name contained the text, pinned ones included. A named upgrade now targets one package: it prefers an exact ID or name match and otherwise errors on ambiguity, as WinGet does. --all is unchanged.

Testing

  • Rust: cargo test -p pinget-core passes (262 tests, run single-threaded; see note below). cargo test -p pinget-cli passes (29 tests). cargo clippy --workspace --tests -- -D warnings and cargo +nightly fmt --check are clean.
  • C#: dotnet build -c Release succeeds, and Devolutions.Pinget.Core.Tests passes (340 passed, 1 skipped).
  • Windows PowerShell 5.1: built the module with Build-PowerShellModule.ps1 -NativeComRuntimeIdentifiers win-x64. Get-PingetPackage returns the installed packages (298 on the test machine).
  • Not run: the Pester suite (dotnet/tests/RunTests.ps1), which needs network access to an external source. Find-PingetPackage on PS 5.1 was not exercised for the same reason.
  • Note: one parallel run of the Rust core tests hung and the same suite passed single-threaded. This looks like a concurrency flake that predates this change.

🤖 Generated with Claude Code

Security:
- Rust/C#: pass the MSIX installer path to Add-AppxPackage through an
  environment variable instead of interpolating it into the script.
- Rust/C#: refuse --ignore-security-hash and --manifest unless the
  InstallerHashOverride / LocalManifestFiles admin settings are enabled.
- Rust: reject zip entries the extractor would create as symlinks, using
  the zip crate's own predicate, on both zip extraction paths.

Crashes and broken flows:
- Rust: avoid slicing local ids at a non-character boundary; non-ASCII
  ARP key names crashed `list` (and powershell.exe via COM).
- PS 5.1: read the PascalCase search/list JSON the COM bridge returns, so
  Find/Get/Update-PingetPackage work again.
- C#: read the V1 manifest pathpart rowid and hex-encode the hash BLOB;
  every V1-index show/install failed the hash check.
- Rust/C#: keep `/i <package>` when --override is used for MSI/WiX.
- Rust CLI: `export -o <file>` no longer clashes with global --output.

Wrong results:
- Rust/C#: pre-release versions rank below the release.
- C#: V1 versions sorted with version semantics, not text order.
- Rust: installers without Scope stay applicable when a scope is set.
- Rust: keep the original text of numeric-looking PackageVersion values.
- Rust/C#: a failed dependency install stops the dependent install.
- C# CLI: failed install/uninstall/repair exit with a non-zero code.
- C#/PS: upgrade --version targets the new version, not the installed one;
  piped uninstall/repair use the installed version.
- C# CLI: export --source keeps all packages and groups them by source.
- Rust CLI: a named upgrade targets one package and errors on ambiguity
  instead of upgrading every substring match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r test

- Rust Lint (Linux): `zip_entry_is_symlink` is only called from
  `cfg(any(windows, test))` code, so it was dead code in non-test Linux
  builds. Give it the same cfg as its callers.
- Dotnet Build (Pester): the export test passes -AllowHashMismatch, which
  is now gated by the InstallerHashOverride admin setting. Enable the
  setting in the test's isolated app root first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mamoreau-devolutions
Marc-André Moreau (mamoreau-devolutions) merged commit 3610787 into master Nov 6, 2026
14 checks passed
@mamoreau-devolutions
Marc-André Moreau (mamoreau-devolutions) deleted the claude/code-defect-analysis-ac5b0b branch November 6, 2026 15:40
Marc-André Moreau (mamoreau-devolutions) added a commit that referenced this pull request Nov 6, 2026
…election, version compare (#67)

## Summary

Follow-ups to #66 from an independent post-merge
review. Each finding is fixed in both the Rust and C# implementations,
with tests.

### 1. Rust `export --source` failed; export format incomplete (Rust +
C#)
- **Problem:** Rust `do_export` passed `--source` into `ListQuery`, and
`Repository::list` rejects a source without a query, so `pinget export
-o f.json --source winget` failed. Rust also wrote every package under
one hard-coded `winget` source, so REST and msstore packages could not
be re-imported.
- **Fix (Rust):** port C# `ExportPayloadBuilder.Build` as
`build_export_payload`: list with `ListQuery::default()`, skip rows
without a source, filter `--source` case-insensitively, and group by
`source_name`, taking the argument and type (`Microsoft.Rest` /
`Microsoft.PreIndexed.Package`) from `list_sources()`.
- **Fix (both):** the export now carries `$schema`, `CreationDate`,
`WinGetVersion` and `SourceDetails.Identifier`. C#
`PackagesExportPayload` serialized the schema key as `"Schema"`; it is
now `[JsonPropertyName("$schema")]`, and `CliExportPayloadTests` assert
the right key. Import still reads only `SourceDetails.Name`.
- **Tests:** Rust tests for grouping, the source filter, and an export →
import round trip. A C# test for the header fields and `Identifier`.

### 2. Admin-setting gates had holes (Rust + C#)
- **`--manifest` on uninstall:** the `LocalManifestFiles` check now
lives inside `load_manifest_from_path_with_documents` /
`LoadManifestFromPathWithDocuments`. Every `--manifest` load goes
through it: install, repair, download, and the uninstall paths
(`uninstall_request` / `DescribeUninstallTarget` and
`resolve_uninstall_matches` / `ResolveUninstallMatches`). No
`validate`-style reader uses these loaders.
- **`--ignore-security-hash` checked too late:** `install_request` /
`Install` and `repair` / `Repair` now check `InstallerHashOverride`
first, before the agreement prompt and dependency installs. The check
also covers the already-installed no-op, `--dependencies`, and msstore
paths. The fetch-time check stays, for `download`.
- **Tests (both):** install with an msstore installer and an agreement,
with and without dependencies-only, is refused and never prompts; repair
by id and by manifest is refused; uninstall and repair with `--manifest`
are refused without `LocalManifestFiles`.

### 3. Upgrade selection (Rust + C#)
- **C#:** `pinget upgrade <query>` without `--all` upgraded every
substring match. The new `UpgradeTargetSelector` ports Rust
`select_upgrade_targets`: an exact match wins; otherwise the command
fails with "Multiple installed packages found matching input criteria.
Please refine the input." and lists the candidates.
- **Both:** `--id` is compared only to the id, `--name` only to the
name, and the query / `--query` to either. Before, `upgrade --id Git`
picked `Git.Git` because its *name* is `Git`.
- **`--moniker`:** now counts as a selector in `do_install` /
`doInstall`, so `upgrade --moniker X` upgrades instead of only listing.
`ListMatch` has no moniker, so a single row from the moniker-filtered
list is upgraded, and several rows are an error.
- **Rust `upgrade --version` / `-v`:** added. It goes on the install
`PackageQuery`, not on `ListQuery` (which filters on the *installed*
version).
- **Tests:** in both implementations.

### 4. Version comparison drift (C#, small Rust hardening)
- **Problem:** C# `CompareVersionStrings` split only on `.`/`-` and took
a leading number from each part, so `1.0.0-rc2` vs `1.0.0-rc10` sorted
differently from Rust.
- **Fix:** C# now uses the same tokenizer as Rust `tokenize_version`:
split on `.`, `-`, `_` and `+`, and at digit/letter boundaries. It uses
the same rules too: numbers compare numerically; a number or missing
part (padded `"0"`) ranks above text; text compares ASCII
case-insensitively. The existing expectations still hold, including
`1.0.0 > 1.0.0-rc1` and `"< X"`.
- **Both:** digit runs longer than `u64` now compare by length instead
of falling back to text in Rust or saturating in C#.
- **Tests:** `rc2` < `rc10`, `preview2` < `preview10`, case, separators,
leading zeros and long digit runs, in `VersionCompareTests` and the Rust
`compare_version` test.

## Validation
- **Rust format:** `cargo +nightly fmt --all` is clean.
- **Rust lint:** `cargo clippy --workspace --tests -- -D warnings` is
clean.
- **Rust core tests:** `cargo test -p pinget-core --lib --
--test-threads=1` gives 264 passed.
- **Rust CLI tests:** `cargo test -p pinget-cli` gives 33 + 2 passed.
- **C# format:** `dotnet format` was run, and its unrelated Publisher
rewrites were reverted.
- **C# build:** `dotnet build -c Release` succeeds.
- **C# tests:** `Devolutions.Pinget.Core.Tests` gives 361 passed and 1
skipped (a live network test).
- **Pester:** 13/13 tests passed. The container is still reported as
failed because its `AfterAll` cleanup hit `Access is denied` while
deleting the temp test root, a local file lock that is unrelated to this
change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Marc-André Moreau (mamoreau-devolutions) added a commit that referenced this pull request Nov 8, 2026
## Summary

This PR fixes 120 defects in 12 waves of 10, in both the Rust (`rust/`)
and C# (`dotnet/`) implementations, so they stay aligned. It follows
#66 and #67.

- **How the defects were found:** two rounds of read-only audits, six
areas per round. WinGet behaviour was checked against the upstream
`winget-cli` sources.
- **Where only one side was wrong:** it was changed to match the other,
and a test was added on both sides to pin the shared behaviour.
- **Findings dropped after checking WinGet,** because WinGet does the
same thing: strict `--architecture`, RequireExplicitUpgrade still
skipped with `--include-pinned`, and the portable-upgrade removal order.
- **Tests** live in new per-wave files: `wave{N}_tests.rs`,
`wave{N}_cli_tests.rs`, `wave{N}_com_tests.rs` and
`Wave{N}DefectTests.cs`. Each wave is self-contained to review.

| Wave | Area | Highlights |
|---|---|---|
| 1 | Installer execution |
`InstallerSuccessCodes`/`ExpectedReturnCodes` and 3010 (reboot-required)
handled<br>Uninstall opens the exact ARP hive and view<br>Download file
names taken from the URL are sanitized<br>A missing `InstallerSha256`
needs `--ignore-security-hash`<br>NSIS `/D=` is passed last and
unquoted<br>`--uninstall-previous` removes the installed match |
| 2 | Package sources | REST single-package search moves Id/Name/Moniker
into `Inclusions` (servers AND the `Filters` list)<br>`sources.json`
keys now match between Rust and C#<br>LIKE wildcards in user input are
escaped<br>`source update` continues past failures and saves the
successes |
| 3 | Pins, correlation, settings | Pinning pins block `upgrade
--all`<br>`pin add --version` creates a Gating pin, compared part by
part<br>Settings JSON may contain comments, trailing commas or a
BOM<br>MSIX family names drop the resource id |
| 4 | Manifests and selection | `--manifest <dir>` loads every file of a
multi-file manifest<br>The installer is selected before dependencies are
installed<br>Dependency cycles stop<br>`MinimumOSVersion` pads missing
parts with zeros<br>A leading `v` in a version is ignored |
| 5 | CLI | The `error` command uses WinGet's HRESULT table (from
`AppInstallerErrors.h`)<br>C# YAML output quotes values like `1.10` /
`true`<br>Error paths exit non-zero<br>`hash` streams the file and
prints lowercase<br>`--count` must be 1–1000 |
| 6 | Publisher | Correlation values in the index are lowercased<br>C#
canonical JSON is byte-identical to serde_json<br>BOMs are stripped
before parsing<br>WinGet's PackageIdentifier rule<br>Windows-unsafe
names (trailing dot or space, device names) are rejected |
| 7 | Portable installs and archives | Uninstall removes only tracked
files unless `--purge`<br>Upgrade keeps user files<br>Nested zip
installers actually run<br>System tools are launched from their absolute
System32 path<br>MSI repair uses `msiexec /f` |
| 8 | Manifest model | `download` checks agreements and
`DownloadCommandProhibited`<br>`Markets`, `UnsupportedOSArchitectures`
and `UpgradeBehavior` are applied<br>Dependency `MinimumVersion` and the
`Upgrade` switch are honoured<br>The downloaded manifest keeps every
installer field |
| 9 | Sources and HTTP | **Security:** paths from a source's index can
no longer escape the cache folder<br>**Security:** `source add` requires
`https://`<br>REST 204 and 404 responses are handled<br>Packaged-layout
tombstones and YAML round-trip |
| 10 | Installed packages, round 2 | `pinning.db` uses WinGet's
schema<br>Blocking and Gating pins still apply with
`--include-pinned`<br>ARP version fallbacks<br>ARM architecture
stripping in name normalization<br>Pin source filters are
case-insensitive |
| 11 | CLI, PowerShell, COM | WinGet's common flags are
accepted<br>`-Scope System` works<br>`RebootRequired` is
reported<br>`validate` checks content on both
sides<br>`Update-PingetPackage` continues after a failure |
| 12 | Publisher, round 2 | An expired or rotated signing certificate no
longer blocks publishing<br>An interrupted publish can be recovered
(`pendingCommit` marker)<br>ARP ranges and correlation use effective
installers<br>Overlapping ARP ranges fail the build |

The commit message has one line per fix for each wave.

## Behaviour changes for reviewers

- **Installer hashes:** a non-msstore manifest without `InstallerSha256`
now fails unless `--ignore-security-hash` is given, as in WinGet.
- **`source add`:**
  - `http://`, `ftp://` and local paths are refused.
- With no `--type`, it creates a `Microsoft.PreIndexed.Package` source
(WinGet's default) instead of REST.
- **Pins:**
- A plain pin now hides the package from `upgrade` and `upgrade --all`.
  - `pin add` records the installed version.
- **Exit codes:**
  - A named `upgrade` with no target exits 1.
- Several C# error paths and `source update` with partial failures exit
non-zero.
- **Portable packages:**
- A plain uninstall leaves untracked files in place and warns; `--purge`
removes everything.
- Machine-scope x86 portables use `Program Files (x86)` and WOW6432Node.
- **Installer switches:**
  - Generic `exe` installers no longer get a guessed `/S` or `/SILENT`.
  - 1641 is still a failure, as in WinGet.
- **Rust `sources.json`:** now written in camelCase. It still reads the
old snake_case keys, but older Rust builds cannot read the new files.
- **Publisher:**
  - Builds whose ARP ranges overlap across versions fail.
- A PackageIdentifier casing change is refused for an existing
destination.
  - The ownership marker can carry `pendingCommit`.
  - `contract.md` is updated.
- **Output:** C# `hash` prints lowercase. Tables are no longer truncated
when stdout is piped.

## Validation

- `cargo +nightly fmt --check` and `cargo clippy --workspace --tests -D
warnings`: clean.
- `cargo test --workspace`: all pass.
  - pinget-core 387
  - pinget-cli 63 + 2
  - pinget-publisher 51 + 26 conformance
  - pinget-com 2
- `dotnet build` (Release): succeeds.
- `dotnet test` Core.Tests: 650 passed, 1 skipped (live-network test).
- `dotnet test` Publisher.Tests: 158 passed.
- `RunTests.ps1`: 13 passed, 0 failed, but the run is reported as failed
because its AfterAll cleanup throws "Access is denied" (a module DLL is
still loaded). I did not check whether this also happens on master.
- `dotnet format --verify-no-changes`: reports only IDE0060
unused-parameter warnings, mostly on signatures unchanged from master.
- **Known flaky tests:**
- C# `InstallerCompletion_DoesNotWaitForDetachedChildProcess` failed
once under heavy load and passes when run alone.
- Some Rust tests that use a local HTTP stub hung once while several
builds ran in parallel, and passed on every rerun.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant