Skip to content

Fix 120 correctness and security defects in Rust and C# (12 waves) - #68

Merged
Marc-André Moreau (mamoreau-devolutions) merged 5 commits into
masterfrom
claude/csharp-rust-defect-fixes-f36765
Nov 8, 2026
Merged

Marc-André Moreau (mamoreau-devolutions) merged 5 commits into
masterfrom
claude/csharp-rust-defect-fixes-f36765

Conversation

@mamoreau-devolutions

Copy link
Copy Markdown
Contributor

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

Two rounds of audits across six areas each found defects in the Rust and
C# implementations; each wave fixed 10 of them on both sides so the two
stay aligned, with tests in per-wave test files (wave{N}_tests.rs,
wave{N}_cli_tests.rs, Wave{N}DefectTests.cs). WinGet behavior was
checked against the upstream winget-cli sources.

Wave 1 - installer execution: InstallerSuccessCodes/ExpectedReturnCodes
and 3010 reboot codes; exact ARP hive/view on uninstall; safe download
file names; C# cmd /S /C quoting; --all-versions keeps first failure;
--uninstall-previous targets the installed match; NSIS /D= last and
unquoted; portable --preserve unregisters; missing hash requires
--ignore-security-hash; case-insensitive switch templates.

Wave 2 - sources: REST single search uses Inclusions; direct-mode refresh
does not save; Cache-Control max-age clamped; sources.json camelCase in
Rust; C# exact single REST lookup; source update continues and saves;
LIKE wildcards escaped; C# case-insensitive source remove; Rust updates
explicit sources; C# case-insensitive version/channel selection.

Wave 3 - pins, correlation, settings: Pinning blocks upgrade --all;
pin add --version creates Gating; gating checks on named upgrade with
part-wise version compare; settings JSON with comments/BOM; --source is
not a filter; registry string trimming; all pins loaded; MSIX family
name without resource id; loose correlation rules; per-key MSIX scan.

Wave 4 - manifests/selection: multi-file --manifest directories;
installer-level dependencies in C#; installer selected before
dependencies; dependency cycles stopped; singleton structured output;
MinimumOSVersion padding; --locale filters; leading 'v' versions;
full upgrade compatibility check; Windows.Universal on desktop.

Wave 5 - CLI: C# YAML quotes non-string scalars; shared WinGet HRESULT
table; error input parsing; non-zero exits on error paths and named
upgrade with no target; streamed lowercase hash and Rust --msix;
--count 1..1000; C# import parsing and dry-run search; PowerShell NoOp
status; C# pin list structured output.

Wave 6 - publisher: lowercase correlation values; serde_json-compatible
canonical JSON in C#; BOM stripping; serde_yaml scalar typing in C#;
WinGet identifier rule; Windows-unsafe names rejected; Rust MSIX
version normalization; stale publish temporaries cleaned; mixed
ManifestVersion rejected; Rust requires Publisher.

Wave 7 - portable/archives: tracked-file uninstall unless --purge;
upgrade keeps user files; nested zip installers dispatched; absolute
System32 tool paths; MSI repair via msiexec /f; single manifest
resolution per install; links for every nested file; standalone alias
rules; x86 machine portables in WOW6432Node; no guessed exe switches.

Wave 8 - manifest model: download honors agreements and
DownloadCommandProhibited; Markets and UnsupportedOSArchitectures;
UpgradeBehavior; dependency MinimumVersion; full download manifest;
Upgrade switch; preferred-language locale ranking; C# show parity;
YAML parse parity; AppsAndFeaturesEntries correlation codes.

Wave 9 - sources/HTTP: index path traversal guard; https-only source
add; REST 204/404 as empty; case-insensitive single REST lookups; Rust
REST manifest cache removed and caches cleared on remove/reset;
packaged tombstones; V1 limit on packages; C# REST update refresh and
contract negotiation; packaged YAML round-trip; Rust URL encoding.

Wave 10 - installed/pins round 2: WinGet pinning.db schema; REST
installed.db correlation versions; Blocking/Gating with
--include-pinned; ARP version fallbacks; flags from the target version
entry; ARM architecture stripping; C# SOFTWARE suffix removed; C# keeps
ARP entries under Windows; real Windows directory; case-insensitive pin
source filters.

Wave 11 - CLI/PowerShell/COM: PowerShell scope mapping; WinGet common
flags; no truncation when redirected; C# UTF-8 output; PreIndexed
default source type; -MatchOption honored; RebootRequired surfaced;
real validate on both sides; Update-PingetPackage continues on failure;
Rust import BOM/UTF-16.

Wave 12 - publisher round 2: superseded-signature policy; interrupted
publish recovery with pendingCommit; casing-change refusal; effective
installers for ARP ranges and correlation; overlapping ARP ranges fail;
latest-version package ARP range; Unicode case collisions in Rust;
AppX name rule; empty PFX password in C#.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…to be unused

clippy -D warnings on ubuntu-latest flagged build_msi_repair_arguments,
determine_portable_alias, wave4's DEPENDENCY_MANIFEST_HEADER and wave7's
std::io::Write import, which are only reached from Windows-gated code.
Use the existing cfg_attr(not(windows), allow(...)) pattern.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…raries (Rust + C#)

#2 verify/publish after a kill mid package-swap: Rust stages the package under --state and writes .source2.*.new only after the pendingCommit marker; verify ignores root swap temporaries (.source2.*.new, source2.msix.<guid>.tmp, legacy .publish-<build>.staging) only while pendingCommit is set and marker write temporaries always (both sides); next publish removes them; real-interruption tests via commit-step hooks (review_b_tests.rs, ReviewFixesBTests.cs); contract.md updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ty, portable registry/directories (Rust + C#)

#4 Pins: null/None = no source filter and "" = the source-less pin in C# PinStore.List/Remove/Reset (as in Rust); pin remove --installed uses the same source key as pin add --installed on both sides; Add/add_pin replace a case-variant id/source row in one transaction (WinGet's pin_index kept).
#6 Source cache paths: validated_source_relative_segments/ValidatedSourceRelativeSegments require Windows-safe segments (is_safe_file_name/IsSafeFileName) and reject '#'; sanitize_path_segment/SanitizePathSegment replace control chars, trim trailing dots/spaces after replacement, and prefix unsafe names with '_' (falling back to '_').
#7 Portable: PingetPortableDirectories drops obsolete directories that the upgrade removed; portable registry read/remove use arp_uninstall_key_candidates/GetArpUninstallKeyCandidates; C# ARP scan no longer reads HKCU WOW6432Node (WinGet's ARPHelper treats HKCU as the shared x64 view, like Rust).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mamoreau-devolutions
Marc-André Moreau (mamoreau-devolutions) merged commit 7b756a3 into master Nov 8, 2026
14 checks passed
@mamoreau-devolutions
Marc-André Moreau (mamoreau-devolutions) deleted the claude/csharp-rust-defect-fixes-f36765 branch November 8, 2026 15:24
Marc-André Moreau (mamoreau-devolutions) added a commit that referenced this pull request Nov 15, 2026
## Summary

This PR fixes 100 defects in 10 waves of 10 (waves 13–22). It follows
the 12 waves in #68. Each fix covers both Rust
(`rust/`) and C# (`dotnet/`) wherever the feature exists in both, so the
two implementations stay aligned.

- **How the defects were found:** one area audit per wave. Behaviour was
checked against the upstream `winget-cli` sources. Findings were dropped
when WinGet behaves the same way.
- **Tests:** each wave adds its own test files: `wave{N}_tests.rs`,
`wave20_cli_tests.rs`, `wave22_com_tests.rs` and
`Wave{N}DefectTests.cs`. Each wave can be reviewed on its own, and every
defect test was checked to fail before its fix.
- **History:** each wave is its own commit, merged into this branch, so
`git log --first-parent` lists the waves.

| Wave | Area | Highlights |
|---|---|---|
| 13 | Installer execution | Interactive ARP uninstall falls back to
`QuietUninstallString`<br>A blank uninstall string is no longer reported
as success<br>Per-mode switch merging now matches
WinGet<br>`--uninstall-previous` applies only to updates<br>Downloaded
installers are deleted after a successful install<br>An MSIX uninstall
can no longer run a same-named ARP uninstaller |
| 14 | Pre-indexed sources and settings | An empty `winget source
export` no longer breaks loading<br>The mirror cache keys on identifier
+ URL and repairs itself when corrupt<br>`source update <identifier>`
passes the source name to winget<br>A looping V1 `pathparts` chain no
longer hangs<br>Packaged sources write `Identifier` and sort by Priority
|
| 15 | REST sources | `ContinuationToken` paging<br>Unsupported
inclusions are dropped and unsupported filters fail the search<br>Null
arrays in `/information` are tolerated<br>Ids and versions are
trimmed<br>Empty switches are ignored<br>`no-store`/`no-cache` responses
are not cached |
| 16 | Search, versions, selection | `Latest` and `> x` versions sort
correctly<br>Pre-indexed filters are combined with AND<br>Tag and
command filters use the request's match type<br>WinGet's `IsFirstBetter`
installer ranking (locale, scope, architecture, type)<br>Neutral
architecture ranks last<br>REST truncation flag fixed |
| 17 | Installed packages, correlation | Name normalization: NFKC, case
folding (`ß`→`ss`), SAP lowercase, `@@` cut-off
position<br>Architecture-qualified normalized names are looked up
first<br>An older `installed.db` no longer breaks `list`<br>`list`
matches PackageFamilyName, ProductCode, UpgradeCode and the catalog
name<br>ARP entries with `ParentKeyName` are listed |
| 18 | Manifests | A null installer key no longer wipes the root
value<br>Root `ProductCode`, `PackageFamilyName` and `Nested*` are
inherited only by matching installer types<br>Dependencies are trimmed
and de-duplicated<br>`Localization` is preserved<br>The C# legacy MSZIP
path has a size limit |
| 19 | Portable installs and archives | Uninstall data is written under
WinGet's registry value names (`TargetFullPath`, `SymlinkFullPath`,
`SHA256`); the old pinget names are still
read<br>`InstallDirectoryAddedToPath` is removed from PATH on
uninstall<br>A failed install is rolled back<br>`COM¹`–`LPT³` device
names are rejected<br>Archives with no or several nested installers are
rejected |
| 20 | CLI | The C# CLI now reports parse errors and handles
`--help`<br>CJK and other wide characters are measured in display
columns, and truncation uses `…`<br>`export` sorts and
de-duplicates<br>`import` reads schema 1.0 `Id`<br>WinGet's exclusive
and dependent argument rules are enforced<br>`hash` prints
`InstallerSha256:`<br>Positional import/export file |
| 21 | Publisher | `Agreement` and `AgreementLabel` are kept as
strings<br>Per-installer `Commands` follow WinGet's
rule<br>`norm_names2` includes the architecture variant<br>Index terms,
names and monikers are trimmed<br>A relative `--psign-tool` path
resolves correctly<br>A build recovers when a snapshot was removed<br>C#
PackageLocale length limit |
| 22 | PowerShell and COM | COM errors are reported, not a bare E_FAIL
or a stale message<br>A named `ResetSource` no longer resets every
source<br>Piped packages are targeted by id and source<br>`-MatchOption`
is honoured<br>WinGet version comparison<br>Channel and identity
properties are carried through<br>`RunTests.ps1` runs again |

## Reviewer notes: behaviour changes

- **PowerShell agreements:** `Install-`, `Update-` and
`Export-PingetPackage` now accept package agreements automatically, as
WinGet's cmdlets do.
- **Tag and command match type:** in a many-search, `--tag` and
`--command` are now substring matches unless `--exact` is given
(WinGet's `SearchSourceApplyFilters`). This reverses one assertion that
wave 9 kept, in `wave9_tests.rs` and `Wave9DefectTests.cs`.
- **ARP `ParentKeyName`:** `list` now shows these entries. WinGet's
`ARPHelper` only skips `SystemComponent` entries.
- **C# CLI argument parsing:** the C# CLI now rejects unknown options
and invalid values it used to ignore.
- **Installer cleanup:** downloaded installers are deleted after a
successful install (WinGet's `RemoveInstaller`), and kept when the
install fails.
- **Merge note:** waves 15 and 16 both changed the REST search code. The
merge keeps wave 15's `ContinuationToken` paging loop and wave 16's
truncation rule: more than `MaximumResults` results, or a non-blank
token.

## Validation

- `cargo +nightly fmt` and `cargo clippy --workspace --tests -- -D
warnings`: clean.
- `cargo test --workspace`: all passed (core 471, cli 81 + 2, com 7,
publisher 64 + 26 conformance).
- `dotnet build dotnet/Devolutions.Pinget.slnx -c Release`: 0 errors.
`dotnet format --verify-no-changes`: no changes.
- Core.Tests: 814 passed, 1 skipped (an existing live test).
- Publisher.Tests: 181/181 on 4 of 5 runs. The failing run hit an
intermittent `IOException` ("file is being used by another process") in
`Publish_And_VerifyDestination_RejectSignedMsixInUnsignedDevelopmentMode`;
that test and the code it covers are unchanged.
- `dotnet/tests/RunTests.ps1` under PowerShell 7: 13/13 passed. On the
dev machine, Pester reported the container as failed because deleting
its temp folder was denied (sandbox restriction).

🤖 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