Skip to content
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

Preview handlers fail to handle 64-bit handles #32823

Open
z4pf1sh opened this issue May 11, 2024 · 7 comments
Open

Preview handlers fail to handle 64-bit handles #32823

z4pf1sh opened this issue May 11, 2024 · 7 comments
Assignees
Labels
Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams Product-File Explorer Power Toys that touch explorer like Preview Pane Status-In progress This issue or work-item is under development

Comments

@z4pf1sh
Copy link

z4pf1sh commented May 11, 2024

Microsoft PowerToys version

0.80.1

Installation method

GitHub, PowerToys auto-update

Running as admin

Yes

Area(s) with issue?

File Explorer: Preview Pane

Steps to reproduce

Appears totally random. I just previewed some random JSON file and PowerToys.MonacoPreviewHandler.exe crashed. But with a new File Explorer window it renders correctly again.

✔️ Expected Behavior

The preview rendering correctly.

❌ Actual Behavior

PowerToys.MonacoPreviewHandler.exe just crashed. I attached Visual Studio 2022 to it and the exception turns out was:

System.OverflowException
  HResult=0x80131516
  Message=Value was either too large or too small for a UInt32.
  Source=System.Private.CoreLib
  StackTrace:
   at System.Number.ThrowOverflowException[TInteger]() in System\Number.cs: line 5936
   at System.ParseNumbers.GrabInts(Int32 radix, ReadOnlySpan`1 s, Int32& i, Boolean isUnsigned) in System\ParseNumbers.cs: line 263
   at System.ParseNumbers.StringToInt(ReadOnlySpan`1 s, Int32 radix, Int32 flags, Int32& currPos) in System\ParseNumbers.cs: line 130
   at System.Convert.ToInt32(String value, Int32 fromBase) in System\Convert.cs: line 2525
   at Microsoft.PowerToys.PreviewHandler.Monaco.Program.Main(String[] args) in Microsoft.PowerToys.PreviewHandler.Monaco\Program.cs: line 29

Other Software

No response

@z4pf1sh z4pf1sh added Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams labels May 11, 2024
Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@z4pf1sh
Copy link
Author

z4pf1sh commented May 11, 2024

I did some debugging myself, and the faulty line turns out to be:

int hwnd = Convert.ToInt32(args[1], 16);

... where it assumes that the passed window handle is a signed 32-bit number.

This should not be how it's implemented. This time, Windows passed a 64-bit handle to the process, with args[1] = FFFF FFFF A290 0D2C, as shown in my Immediate Window:

image

And the process promptly crashed, with an exception of "Value was either too large or too small for a UInt32."

The confusing thing for me is this line below, where it's explicitly converted to IntPtr, when the hwnd is actually used:

_previewHandlerControl.SetWindow((IntPtr)hwnd, s);

With reference from Microsoft Learn on the IntPtr struct:

The IntPtr type is designed to be an integer whose size is the same as a pointer. That is, an instance of this type is expected to be 32 bits in a 32-bit process and 64 bits in a 64-bit process.

Here's my thinking: why don't just convert the input string to a IntPtr at the very beginning, instead of the flow of: A Potentially 64-bit Hexadecimal String -> A Signed 32-bit Integer -> A Platform-dependent Handle Type, when you can parse it at the first shot? I think this should be a relatively easy fix, and I will try to fix it with a PR once approved.

@z4pf1sh
Copy link
Author

z4pf1sh commented May 11, 2024

So hey, I'd like to work on this, thus as mandated in #28769, here's my request of an attempt to fix it.

@Aaron-Junker Aaron-Junker added Status-In progress This issue or work-item is under development Product-File Explorer Power Toys that touch explorer like Preview Pane labels May 11, 2024
@Aaron-Junker
Copy link
Collaborator

So hey, I'd like to work on this, thus as mandated in #28769, here's my request of an attempt to fix it.

Good catch. Yes, absolutely, do implement it! Thank you!

@z4pf1sh
Copy link
Author

z4pf1sh commented May 14, 2024

According to comments in the PR #32826 (comment), this affects all other preview handlers as well. I will work on applying the same fix to all other affected handlers as well once I got the approval.

@z4pf1sh z4pf1sh changed the title MonacoPreviewHandler fails to handle 64-bit handles Preview handlers fail to handle 64-bit handles May 14, 2024
@thawaffle
Copy link

So hey, I'd like to work on this, thus as mandated in #28769, here's my request of an attempt to fix it.

Hi, so I arrived here after a google search, trying to find out what the problem with SVG previews is and found the exact problem in issue #30370. However, it was fixed in v0.77 and thus closed. The exact same error is happening to me though, and the bot referred me to this issue. Is your planned implementation on this issue intertwined with the crash I am seeing or should I open a new issue? I'm very new to all this :)

@z4pf1sh
Copy link
Author

z4pf1sh commented May 20, 2024

Hi @thawaffle, I had a look on the referenced issue and can pretty much confirm that it is irrelevant to this one. This issue has nothing to do with the EdgeWebView framework.

You should open a new issue or follow other open issues for your case. There are still many open issues that are related with EdgeWebView, and you may want to take a look at those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug Something isn't working Needs-Triage For issues raised to be triaged and prioritized by internal Microsoft teams Product-File Explorer Power Toys that touch explorer like Preview Pane Status-In progress This issue or work-item is under development
Projects
None yet
Development

No branches or pull requests

3 participants