Skip to content

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

@jkoritzinsky

Description

@jkoritzinsky

Note

This issue body was drafted with assistance from GitHub Copilot.

Description

BlobBuilder.LinkSuffix appears to drop previously linked content when the destination builder is empty and the suffix builder already has a linked suffix.

Minimal repro

using System;
using System.Reflection.Metadata;

static string Hex(byte[] bytes) => BitConverter.ToString(bytes);

var emptyPrefix = new BlobBuilder(16);
var element = new BlobBuilder(16);
var tail = new BlobBuilder(16);

element.WriteByte(0x11);
tail.WriteByte(0x22);

// Pre-link element + tail
element.LinkSuffix(tail);

// Then link into empty destination
emptyPrefix.LinkSuffix(element);

Console.WriteLine(Hex(emptyPrefix.ToArray()));

Actual behavior

Output:

22-00

Expected behavior

Output should preserve both bytes in order:

11-22

Notes

A control case with a non-empty destination (prefix.WriteByte(0xAA) before linking) behaves as expected. The issue reproduces specifically when the destination BlobBuilder is empty.

Observed in local repro project targeting net11.0 in this repository.

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions