Files
kz-tob 9e3fd2f9e8 constant-time-analysis: pair ilspycmd's TFM with a matching runtime (#283)
* constant-time-analysis: pair ilspycmd's TFM with a matching runtime

The tool-store fallback in _get_il_output globbed for
`*/ilspycmd/*/tools/net8.0/any/ilspycmd.dll`. ilspycmd 9.x installs
under `tools/net9.0/`, so on any newer install the glob matched
nothing, the loop body never ran, and C# IL analysis fell through to
monodis and then to "IL disassembly tools not available" — while
`dotnet tool install -g ilspycmd`, the command that error recommends,
produces exactly the layout the glob could not see.

Widening the glob to net* alone would have been wrong. The next lines
run the assembly under a Homebrew dotnet@8 runtime, and that pairing is
deliberate: ilspycmd installs framework-dependent and .NET does not
roll forward across a major version by default, so a net9.0 assembly
will not start on an 8.0 runtime. A wide glob with a pinned runtime
turns a silent no-match into a silent failed exec.

So the TFM found on disk now selects the runtime. Candidates are tried
newest-first, sorting the parsed (major, minor) tuple rather than the
moniker string, since lexically "net10.0" sorts below "net8.0"; a TFM
whose runtime is absent falls back to an older one that has one. Store
entries that do not name a .NET runtime major (netstandard2.0, net48)
are skipped rather than producing a dotnet@netstandard2 path. The
arbitrary `break` after the first matching dll is gone.

Extracted to _il_via_versioned_runtime so _get_il_output stays flat.

TestCSharpILRuntimePairing covers it with a fake store and fake runtime
paths, needing no dotnet install. The suite was mutation-tested rather
than trusted green: against the old pinned glob two tests fail, and
against the naive widening four fail, including the one asserting a
net9.0 assembly is never handed to dotnet@8.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* constant-time-analysis: don't depend on one Homebrew keg existing

Review P2 on #283: pairing the store TFM with /opt/homebrew/opt/dotnet@N
assumes a keg for that major exists, and if it does not the motivating
failure just moves from the glob to the exists() check.

`brew info dotnet@9` says the keg does exist — stable 9.0.120 — so the
ilspycmd 9.x case the PR was written for does work as shipped. The
general concern holds anyway: homebrew-core carries dotnet@6, dotnet@8
and dotnet@9 but dropped dotnet@7 at end of life, and no Linux
distribution ships a versioned keg at all.

So the exact-major keg is now preferred rather than required. After it
come the unversioned Homebrew prefixes, the official installer paths for
macOS and Linux, and the PATH dotnet, each tried with
DOTNET_ROLL_FORWARD=Major, which is what permits a net9.0 assembly to
start on a 10.x runtime. Roll-forward is set only on those candidates:
setting it on the exact-major keg would mask a genuinely mismatched pair
instead of letting it fail, which is the property the existing test
pins. The PATH entry resolves through shutil.which, since dotnet_path
defaults to the bare name "dotnet" and exists() on a bare name tests the
cwd.

The except clause widens from FileNotFoundError to OSError. This is P3,
included because the change makes it reachable: adding the Intel prefixes
means an Intel keg on an Apple Silicon box without Rosetta is now a live
candidate, and it raises OSError("Bad CPU type in executable") rather
than FileNotFoundError, which escaped the helper and aborted the whole
analysis.

Review P2 on references/vm-compiled.md: the only user-facing remedy still
said `brew install dotnet@8` and claimed the analyzer detects dotnet@8.
It now tells the reader to read the TFM out of the tool store, names the
keg gap, and explains that the roll-forward path means no install is
strictly required. The store lookup uses find rather than ls on a glob,
for the reason #282 documents.

Five tests added, each mutation-checked: dropping the generic tier,
setting roll-forward unconditionally, narrowing OSError back, and
deleting the DOTNET_ROOT line each fail exactly the test that covers
them. DOTNET_ROOT had no assertion before, so that line could be deleted
with the suite green.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-27 11:05:27 -04:00
..