Skip to content

[File Locksmith] Fix Interop access-violation crashes from TerminateThread hang recovery - #49502

Draft
Ryan Johnson (AMDphreak) wants to merge 1 commit into
microsoft:mainfrom
AMDphreak:fix/file-locksmith-terminate-thread-crash
Draft

[File Locksmith] Fix Interop access-violation crashes from TerminateThread hang recovery#49502
Ryan Johnson (AMDphreak) wants to merge 1 commit into
microsoft:mainfrom
AMDphreak:fix/file-locksmith-terminate-thread-crash

Conversation

@AMDphreak

Copy link
Copy Markdown

Summary

  • Remove the TerminateThread watchdog in NtdllExtensions::handles(). Killing a thread mid-NtQueryObject / CRT heap use causes later 0xc0000005 crashes in PowerToys.FileLocksmithLib.Interop.dll (WER offsets map to the worker lambda / memcpy).
  • Skip handle access masks known to hang NtQueryObject/GetFileType (including the previously commented 0x0012019f filter).
  • Null-check UNICODE_STRING buffers and OpenProcess in pid_to_full_path.

Fixes / relates to: #45158, #47200

This is distinct from the already-merged icon crash fix in #48719 (0xc000027b).

Test plan

  • Build FileLocksmithLibInterop / File Locksmith UI (x64 Release)
  • Right-click a file/folder → Unlock with File Locksmith repeatedly (10+ times) on a machine that previously crashed within ~5s
  • Confirm no Application Error / c0000005 for PowerToys.FileLocksmithUI.exe in Event Viewer
  • Confirm results still populate for a known locked file (e.g. open document)
  • Optional: right-click a drive root (enumerates many handles) and verify UI stays up

Made with Cursor

Killing the NtQueryObject worker with TerminateThread corrupts CRT/heap
state and leads to c0000005 crashes in FileLocksmithLib.Interop.dll
(microsoft#45158, microsoft#47200). Skip access masks known to hang instead, and guard
null UNICODE_STRING / OpenProcess failures.

Co-authored-by: Cursor <cursoragent@cursor.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions github-actions Bot added the Product-File Locksmith Refers to the File Locksmith utility label Jul 27, 2026
@daverayment
Dave Rayment (daverayment) marked this pull request as draft July 28, 2026 00:19
@daverayment

Copy link
Copy Markdown
Collaborator

Converted this to draft, as it's AI-developed and there is no proof given that this solves the underlying issue.

Ryan Johnson (@AMDphreak) Please fill in the PR details correctly, read the contributor guidelines and refer us to the issue where a maintainer agreed with your approach and approved your work on this. You also seem to have forgotten to include your test results. Many thanks.

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

Labels

Product-File Locksmith Refers to the File Locksmith utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants