Visitar URL original
test(win32): Cover reading a DIB after release by mikernet · Pull Request #25864 · unoplatform/uno · GitHub
Skip to content

test(win32): Cover reading a DIB after release - #25864

Open
mikernet wants to merge 1 commit into
unoplatform:masterfrom
mikernet:dev/mikernet/win32-drag-bitmap-test
Open

mikernet wants to merge 1 commit into
unoplatform:masterfrom
mikernet:dev/mikernet/win32-drag-bitmap-test

Conversation

@mikernet

@mikernet mikernet commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #25863 (fixed on master by eb508ad in #23924; this adds its regression test)

PR Type:

💬 Other: test only (a regression test for a bug that master already fixed)

What changed? 🚀

On Skia Win32 (Windows desktop), when an external drag enters the window, DragEnter in Win32DragDropExtension.DropTarget.cs reads each standard format offered as TYMED_HGLOBAL with IDataObject::GetData, passes the handles to Win32ClipboardExtension.ReadContentIntoPackage, and releases every medium (ReleaseStgMedium) before it returns. A format reader must therefore copy its data before ReadContentIntoPackage returns.

The CF_DIB reader, GetBitmap, used to break that rule: it registered a data provider that kept the raw HGLOBAL and only locked it when the app called DataPackageView.GetBitmapAsync(), typically from its DragOver or Drop handler. The handle was usually freed by then, so GetBitmapAsync threw for the Bitmap format of any CF_DIB drag.

eb508ad (in #23924, a RichEditBox feature PR) changed GetBitmap to build the BMP (the DIB behind a file header) and call package.SetBitmap before returning, which fixed the bug on master. It came without a test, so nothing stops the lazy reader from coming back. servicing/6.8 still has the bug; #25865 backports the fix.

This PR adds Given_Win32DragDrop.When_Bitmap_Drop_Read_After_Medium_Released, in the style of the other tests in that class:

  • it builds a 2×3, 32-bit BI_RGB CF_DIB in a GMEM_MOVEABLE HGLOBAL;
  • it calls ReadContentIntoPackage with it through reflection;
  • it frees the handle with GlobalFree, which is what ReleaseStgMedium does for an HGLOBAL medium without pUnkForRelease, and checks that the free succeeded;
  • it then calls GetBitmapAsync and checks the stream: a 14-byte BITMAPFILEHEADER starting with BM, whose bfSize is the stream's length and whose bfOffBits is 54, followed by the DIB bytes unchanged.

The test reads the bitmap once. Reading it twice, for example in DragOver and again in Drop, depends on the RandomAccessStreamReference.CreateFromStream fix in #25867.

No product code changes.

Tests: on Skia Desktop (Windows), Given_Win32DragDrop:

Code When_Bitmap_Drop_Read_After_Medium_Released Other Given_Win32DragDrop tests
master (1f2fc30) with this PR passes 4 pass
master with this PR and GetBitmap locally reverted to the lazy data provider fails 4 pass

With the lazy reader, GetBitmapAsync throws InvalidOperationException ("Failed to asynchronously load the data of id 'Bitmap'") with an inner TaskCanceledException, because DataPackage swallows the provider's error: it logs it ("GlobalLock failed: The handle is invalid.") and completes the request without data.

PR Checklist ✅

@mergify

mergify Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

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

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Skia Win32] GetBitmapAsync fails for an external drag offering CF_DIB

1 participant