Conversation
FractionApprox rejects inputs above 0x7FFFFFFF because they cannot be stored as a fraction, but the check was one-sided while the sign is stripped right after it. A large negative value therefore reached the continued-fraction loop and overflowed the terms it accumulates. ICSharpCode.Decompiler is built with CheckForOverflowUnderflow, so that aborted decompilation of the whole member instead of wrapping. Found by fuzzing nuget.org; reproduces on MathNet.Numerics, whose constants reach the approximation through their ratio to PI. Assisted-by: Claude:claude-opus-5[1m]:Claude Code
siegfriedpammer
force-pushed
the
fix-fractionapprox-negative-overflow
branch
from
August 7, 2026 06:28
4688927 to
1c389be
Compare
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.
Problem
TypeSystemAstBuilder.FractionApproxrejects inputs that cannot be stored as a fraction, but the range check is one-sided and the sign is stripped immediately after it:A large negative value therefore reaches the continued-fraction loop and overflows the terms it accumulates.
ICSharpCode.Decompileris built withCheckForOverflowUnderflow, so this throws rather than wrapping, and theOverflowExceptionaborts decompilation of the whole member:Fix
Check the magnitude, matching what the surrounding code already assumes.
Testing
Two constants added to the
WellKnownConstantsfixture, one of each sign. The negative one fails without the fix with the stack above; the positive one is already handled and guards the symmetry.Note that the trigger has to be non-integral:
ConvertFloatingPointLiteralshort-circuits integral doubles viaMath.Floor(v) == v, so those never reach the approximation at all. The value used here is an actual constant from MathNet.Numerics, which arrives atFractionApproxthrough its ratio to PI.Full
ILSpy.XPlat.slnfsuite: 3366 tests, 0 failed, 44 skipped (Windows-only). The completeMathNet.Numericsassembly now decompiles with zero errors.How it was found
Fuzzing the nuget.org catalog through the decompiler.
Written by an AI agent (Claude) on Siegfried's behalf.