Registry Mirror
Skip to content

Conversation

@siegfriedpammer

Copy link
Copy Markdown
Member

Problem

TypeSystemAstBuilder.FractionApprox rejects inputs that cannot be stored as a fraction, but the range check is one-sided and the sign is stripped immediately after it:

if (value > 0x7FFFFFFF)          // negatives pass straight through
    return (0, 0);

double startValue = value;
if (value < 0)
    value = -value;              // ...and are then made positive

A large negative value therefore reaches the continued-fraction loop and overflows the terms it accumulates. ICSharpCode.Decompiler is built with CheckForOverflowUnderflow, so this throws rather than wrapping, and the OverflowException aborts decompilation of the whole member:

System.OverflowException: Arithmetic operation resulted in an overflow.
   at ICSharpCode.Decompiler.CSharp.Syntax.TypeSystemAstBuilder.FractionApprox(Double, Int32)
   at ICSharpCode.Decompiler.CSharp.Syntax.TypeSystemAstBuilder.TryExtractExpression(...)
   at ICSharpCode.Decompiler.CSharp.Syntax.TypeSystemAstBuilder.ConvertFloatingPointLiteral(...)

Fix

Check the magnitude, matching what the surrounding code already assumes.

Testing

Two constants added to the WellKnownConstants fixture, 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: ConvertFloatingPointLiteral short-circuits integral doubles via Math.Floor(v) == v, so those never reach the approximation at all. The value used here is an actual constant from MathNet.Numerics, which arrives at FractionApprox through its ratio to PI.

Full ILSpy.XPlat.slnf suite: 3366 tests, 0 failed, 44 skipped (Windows-only). The complete MathNet.Numerics assembly 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.

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
siegfriedpammer force-pushed the fix-fractionapprox-negative-overflow branch from 4688927 to 1c389be Compare August 7, 2026 06:28
@siegfriedpammer
siegfriedpammer merged commit 6e218fa into master Aug 7, 2026
15 checks passed
@siegfriedpammer
siegfriedpammer deleted the fix-fractionapprox-negative-overflow branch August 7, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant