Skip to content

System.Reflection.Metadata: preserve pre-linked suffix chain when linking into empty BlobBuilder#127246

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-blobbuilder-linksuffix-issue
Open

System.Reflection.Metadata: preserve pre-linked suffix chain when linking into empty BlobBuilder#127246
Copilot wants to merge 2 commits intomainfrom
copilot/fix-blobbuilder-linksuffix-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

BlobBuilder.LinkSuffix could drop already-linked content when the destination builder was empty and the incoming suffix had its own linked suffix chain. This change preserves the full chain so byte order and total content are retained (11-22, not 22-00).

  • Behavior fix (BlobBuilder.LinkSuffix)

    • Added an explicit empty-destination path after head-buffer swap.
    • When destination is empty, destination now adopts the suffix chain tail (_nextOrPrevious) instead of leaving chain links in a state that loses prior suffix content.
    • Non-empty destination relinking logic is unchanged.
  • Regression coverage (BlobTests)

    • Added LinkSuffix_EmptyDestination_SuffixAlreadyLinked.
    • Repro shape:
      • element contains 0x11
      • tail contains 0x22
      • element.LinkSuffix(tail)
      • emptyPrefix.LinkSuffix(element)
    • Asserts resulting bytes are { 0x11, 0x22 } and counts remain consistent across builders.
element.LinkSuffix(tail);
emptyPrefix.LinkSuffix(element);

AssertEx.Equal(new byte[] { 0x11, 0x22 }, emptyPrefix.ToArray());

…e-linked

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/31683964-9cee-4d89-b561-87c8f1509e4b

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot April 21, 2026 21:30
Copilot AI changed the title [WIP] Fix BlobBuilder.LinkSuffix dropping content when destination is empty System.Reflection.Metadata: preserve pre-linked suffix chain when linking into empty BlobBuilder Apr 21, 2026
Copilot AI requested a review from jkoritzinsky April 21, 2026 21:32
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-reflection-metadata
See info in area-owners.md if you want to be subscribed.

@jkoritzinsky jkoritzinsky marked this pull request as ready for review April 21, 2026 23:00
Copilot AI review requested due to automatic review settings April 21, 2026 23:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes BlobBuilder.LinkSuffix to correctly preserve an incoming suffix’s existing linked-suffix chain when linking into an empty destination builder, ensuring previously-linked content isn’t dropped and byte order/content are retained.

Changes:

  • Update BlobBuilder.LinkSuffix to adopt the suffix chain tail (_nextOrPrevious) when the destination builder is empty.
  • Add a regression test covering “empty destination + suffix already linked” to verify byte sequence and counts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/BlobBuilder.cs Adjusts empty-destination LinkSuffix relinking to preserve an already-linked suffix chain.
src/libraries/System.Reflection.Metadata/tests/Metadata/BlobTests.cs Adds regression coverage for linking a pre-linked suffix into an empty destination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

System.Reflection.Metadata: BlobBuilder.LinkSuffix loses pre-linked content when destination is empty

4 participants