Registry Mirror
Skip to content

Conversation

@siegfriedpammer

Copy link
Copy Markdown
Member

Problem

RecordDecompiler disagrees with itself about the accessibility of a record's copy constructor.

IsCopyConstructor ties it to sealedness:

&& (recordTypeDef.IsSealed
    ? (method.Accessibility == Accessibility.Private)
    : (method.Accessibility == Accessibility.Protected))

but IsGeneratedCopyConstructor, twenty lines further down, accepts protected either way:

if (method.Accessibility != Accessibility.Protected && (!isSealed || method.Accessibility != Accessibility.Private))
    return false;

IsCopyConstructor gates the call to IsGeneratedCopyConstructor, so for a sealed record with a protected copy constructor the looser check is unreachable. Such a record is not recognized as having a copy constructor at all: the constructor falls through to the general handling in TransformFieldAndConstructorInitializers, where its first statement is a base call rather than a this(...) chain, so it is counted as not chained. That makes two unchained constructors alongside the primary one and trips

// if there exists a primary constructor, all other constructors must call it
Debug.Assert(constructorsNotChainedWithThis.Count == 1);

The combination arises when a record is sealed after it was compiled, which is what obfuscators do.

Fix

Align IsCopyConstructor with the predicate IsGeneratedCopyConstructor already uses. The only shape whose classification changes is sealed + protected, which the latter already considered valid; sealed + private and unsealed + protected are unaffected, and unsealed + private stays rejected.

Testing

New ILPretty fixture SealedRecordProtectedCopyCtor, built by compiling an ordinary record and marking the class sealed in IL. It fails without the fix on the assertion above.

The fix is not merely silencing an assertion -- it corrects the output. The affected types previously could not render as records; they now decompile to positional records:

private sealed record HuggingFaceApiResponse(SafetensorsInfo safetensors, string downloadUrl)

Verified on the assembly this was found in (Aspose.AI.LLM.dll from aspose.ocr 26.7.0): the whole assembly now decompiles with no assertion and no errors.

Full ILSpy.XPlat.slnf suite: 3367 tests, 0 failed, 44 skipped (Windows-only).

How it was found

Fuzzing the nuget.org catalog through the decompiler.


Written by an AI agent (Claude) on Siegfried's behalf.

IsCopyConstructor required the copy constructor to be private on a sealed
record and protected otherwise, but IsGeneratedCopyConstructor in the same
class accepts protected regardless of sealedness. Since the former gates the
latter, a sealed record whose copy constructor stayed protected -- what you get
when a record is sealed after it was compiled -- was not recognized as one at
all: it fell through to the general constructor handling, where its base call
made it count as unchained, and the primary-constructor invariant then failed.

Found by fuzzing nuget.org. Beyond silencing the assertion this improves the
output, as the affected types now decompile to positional records.

Assisted-by: Claude:claude-opus-5[1m]:Claude Code
@siegfriedpammer
siegfriedpammer force-pushed the fix-sealed-record-copy-ctor branch from 44781de to a4d2aac Compare August 7, 2026 04:32
@siegfriedpammer
siegfriedpammer merged commit e8346dc into master Aug 7, 2026
15 checks passed
@siegfriedpammer
siegfriedpammer deleted the fix-sealed-record-copy-ctor branch August 7, 2026 05:05
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