Repository navigation
fix(rdp): rebuild GDI in place on failed resize and lock CLIPRDR data for remote file downloads - #14
Open
heartacker wants to merge 4 commits into
Open
heartacker wants to merge 4 commits into
heartacker wants to merge 4 commits into
Conversation
Reaching into SSH.NET's private _channel field and invoking SendWindowChangeRequest by reflection broke whenever the library reshaped its internals, and reflection is unavailable under NativeAOT. ShellStream exposes ChangeWindowSize publicly, so call it directly.
RebuildKeyMap runs on every selection query and scanned the item type with up to eight GetProperty calls per row, so selection cost grew with the number of properties rather than the number of rows. Resolve the nested and direct key properties once per type and reuse them, keeping the existing key format of type:property:value:instance-hash. Adds coverage for the nested, direct and no-key fallbacks.
Reproducible Access Violation during RDP resolution switches (11-27 and 11-29): FreeRDP 3.32.2 gdi_init_primary assigns primary_buffer before its final allocations, and its fail_hwnd path frees the bitmap without clearing the cached pointer. After a failed gdi_resize the cached value dangles at freed data while gdi->width/height already carry the new size, so push_frame passed every null check and CopyDirtyRectFromNative read freed memory. - push_frame now publishes gdi->primary->bitmap->data (the bitmap owns the buffer; it can only be freed together with gdi->primary) - cx_desktop_resize rebuilds the GDI in place when gdi_resize fails destructively (unbind/rebind the EGFX pipeline around gdi_init, abort the session only when the rebuild fails) - cx_begin_paint guards the primary->hdc->hwnd->invalid chain
rdpclip answers FILECONTENTS requests with CB_RESPONSE_FAIL once both sides negotiated CB_CAN_LOCK_CLIPDATA, so a client must hold a lock and reference its clipDataId in every file contents request - exactly what mstsc and FreeRDP FUSE clients do. The bridge never sent CB_LOCK_CLIPDATA and skipped FILECONTENTS_SIZE when the descriptor already carried FD_FILESIZE, so every remote-to-local file download died on the first range request, silently (the FAIL path returned without logging). - Store the server capability flags and lock the remote file list before pulling descriptors; unlock on completion, failure, clipboard change and teardown. - Reference the clipDataId in every FILECONTENTS request. - Always open each file stream with FILECONTENTS_SIZE first (MS-RDPECLIP 3.1.5.4.5 calls the size a prerequisite). - Log failed file contents requests instead of swallowing them. Verified against a live Windows RDP server: remote clipboard file downloads now complete (a bisect run without clipDataId still failed, confirming it is the decisive part); local-to-remote paste upload still works.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two native
CxRdpBridgefixes. Note on stacking: the first two commits in this branch are byte-identical (same SHAs) to the two commits in #13 (fix/ssh-resize-and-datagrid-keys). This branch is deliberately stacked on them, so once #13 lands this PR automatically reduces to the two RDP commits below — either PR can merge first.1. Stop frame callbacks reading a freed GDI buffer on resize (
native/CxRdpBridge/cxrdp_bridge.cpp)Reproducible Access Violation during RDP resolution switches (seen 11-27 and 11-29): FreeRDP 3.32.2's
gdi_init_primaryassignsprimary_bufferbefore its final allocations, and itsfail_hwndpath frees the bitmap without clearing the cached pointer. After a failedgdi_resizethe cached value dangles at freed data whilegdi->width/heightalready hold the new size, sopush_framepassed every null check and handed freed memory toCopyDirtyRectFromNative.push_framenow publishesgdi->primary->bitmap->data— the bitmap owns the buffer and can only be freed together withgdi->primary— turning every broken state into a skipped frame instead of a crash.cx_desktop_resizerebuilds the GDI in place whengdi_resizefails destructively (unbind_gfx_pipeline->gdi_initat the settings size ->bind_gfx_pipeline, becausegfx->customstill points at the broken struct) and only aborts the session viafreerdp_abort_connectwhen the rebuild itself fails.cx_begin_paintkeeps a null-guardedprimary->hdc->hwnd->invalidchain for the same broken state.2. Lock server clipboard data when downloading remote files (
native/CxRdpBridge/cxrdp_bridge.cpp)rdpclipanswersFILECONTENTSrequests withCB_RESPONSE_FAILonce both sides negotiatedCB_CAN_LOCK_CLIPDATA, so a client must hold a lock and reference itsclipDataIdin every file-contents request — exactly what mstsc and FreeRDP's FUSE clients do. The bridge never sentCB_LOCK_CLIPDATAand skippedFILECONTENTS_SIZEwhen the descriptor already carriedFD_FILESIZE, so every remote-to-local file download died on the first range request, silently (the FAIL path returned without logging).generalFlags) and lock the remote file list before pulling descriptors; unlock on completion, failure, clipboard change and teardown.clipDataIdin everyFILECONTENTSrequest.FILECONTENTS_SIZEfirst (MS-RDPECLIP 3.1.5.4.5 calls the size a prerequisite, and rdpclip associates the server-side handle with the streamId it first sees).Verification
dotnet build CxShell.csproj: 0 warnings, 0 errorsdotnet test CxShell.Tests/CxShell.Tests.csproj: 793 passed, 0 failedclipDataIdstill failed, confirming it is the decisive part); local-to-remote paste upload still works