-
Notifications
You must be signed in to change notification settings - Fork 609
Disposing SKStreamAsset when asset MemoryBase is not IntPtr.Zero #3376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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(); }); | ||
|
||
| } | ||
|
|
||
| blob.MakeImmutable(); | ||
|
|
||
There was a problem hiding this comment.
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 withlength = sizeanyway. This can lead to HarfBuzz reading uninitialized memory and producing incorrect shaping results. Consider reading in a loop untilsizebytes are read (or throw if EOF/0 bytes read early), and create theBlobwith the actual number of bytes read.