Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static Blob ToHarfBuzzBlob(this SKStreamAsset asset)
{
var ptr = Marshal.AllocCoTaskMem(size);
asset.Read(ptr, size);
blob = new Blob(ptr, size, MemoryMode.ReadOnly, () => Marshal.FreeCoTaskMem(ptr));
blob = new Blob(ptr, size, MemoryMode.ReadOnly, () => { Marshal.FreeCoTaskMem(ptr); asset.Dispose(); });
Comment on lines 28 to +30
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

asset.Read(ptr, size) can return fewer bytes than requested; the return value is ignored and the blob is created with length = size anyway. This can lead to HarfBuzz reading uninitialized memory and producing incorrect shaping results. Consider reading in a loop until size bytes are read (or throw if EOF/0 bytes read early), and create the Blob with the actual number of bytes read.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

This change fixes a resource-leak scenario; please add a unit test that asserts the SKStreamAsset is disposed when the returned Blob is disposed for both paths: (1) a stream with GetMemoryBase() != IntPtr.Zero (e.g., SKMemoryStream) and (2) a stream with GetMemoryBase() == IntPtr.Zero (e.g., SKFileStream).

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jan 26, 2026

Choose a reason for hiding this comment

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

The PR title/description mention the leak when MemoryBase is not IntPtr.Zero, but this change disposes the asset in the memoryBase == IntPtr.Zero branch. Please update the PR title/description (or clarify the scenario) to match what is being fixed.

Copilot uses AI. Check for mistakes.
}

blob.MakeImmutable();
Expand Down
Loading