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

[PreviewPane] Parse input window handle as IntPtr type instead of Int32 #32826

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

z4pf1sh
Copy link

@z4pf1sh z4pf1sh commented May 11, 2024

Summary of the Pull Request

Fixes a problem where File Explorer preview handlers may crash when receiving 64-bit handles that are out of the 32-bit range.

PR Checklist

  • Closes: Preview handlers fail to handle 64-bit handles #32823
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: None introduced
  • Dev docs: Not needed
  • New binaries: None introduced
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

In some cases, a 64-bit Windows installation may pass a negative 64-bit handle to preview handlers, causing the current implementation (by parsing input handle as Int32) to fail. See the associated issue for details.

Affected (and fixed) preview handlers:

  • GcodePreviewHandler
  • MarkdownPreviewHandler
  • MonacoPreviewHandler
  • PdfPreviewHandler
  • QoiPreviewHandler
  • SvgPreviewHandler

This is a very rare case as I have personally never encountered this bug in months of use, till today. It was fixed with an improved input parsing process.

Validation Steps Performed

The updated implementation works just as the old implementation before with 32-bit handles, and can be verified in C# Interactive Window with this simple one-liner:

>> WriteLine(
    IntPtr.Parse("0000000000A01234",
                 System.Globalization.NumberStyles.HexNumber,
                 System.Globalization.CultureInfo.InvariantCulture) ==
    (IntPtr)Convert.ToInt32("0000000000A01234", 16));

<< True

Yet it works correctly with the value demonstrated in the issue:

>> WriteLine(
    IntPtr.Parse("FFFFFFFFA2900D2C",
                 System.Globalization.NumberStyles.HexNumber,
                 System.Globalization.CultureInfo.InvariantCulture)
        .ToString("X2"));

<< FFFFFFFFA2900D2C

@z4pf1sh
Copy link
Author

z4pf1sh commented May 12, 2024

@Aaron-Junker For whatever reason the build timed out (not the recent geomagnetic storm right?) at building PowerRenameUI (totally unrelated), could you please manually trigger the CI build again? Only the x64 build failed while the arm64 build completed just fine within normal time. Thanks for your time!

@Aaron-Junker
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@stefansjfw
Copy link
Collaborator

Note: The same fix should be applied to other preview pane handlers

@z4pf1sh
Copy link
Author

z4pf1sh commented May 14, 2024

Note: The same fix should be applied to other preview pane handlers

@stefansjfw Gotcha, thanks, should all other fixes be applied with this PR (preferred), or in separate PRs? I'll work on it once I heard back from you.

GcodePreviewHandler
MarkdownPreviewHandler
PdfPreviewHandler
QoiPreviewHandler
SvgPreviewHandler
@z4pf1sh
Copy link
Author

z4pf1sh commented May 14, 2024

@Aaron-Junker I'd like to know your opinion as well. Should this fix be applied to all affected preview handlers? If so, could I might as well change the original issue title to something like "Preview handlers fail to handle 64-bit handles"?

Edit: Since some decisions are not confirmed yet, this PR has been marked as draft. I will respond ASAP if there is any update.

@z4pf1sh z4pf1sh marked this pull request as draft May 14, 2024 18:34
@Aaron-Junker
Copy link
Collaborator

@z4pf1sh I think you can do all in one PR. Thank you!

@z4pf1sh
Copy link
Author

z4pf1sh commented May 14, 2024

@microsoft-github-policy-service agree

@z4pf1sh z4pf1sh marked this pull request as ready for review May 14, 2024 19:26
@stefansjfw
Copy link
Collaborator

@z4pf1sh I think you can do all in one PR. Thank you!

yes, all in one is ok. It's rather simple change to review

@z4pf1sh
Copy link
Author

z4pf1sh commented May 15, 2024

@Aaron-Junker @stefansjfw Seems like the latest CI build failed for a problem (looks fixed) unrelated to this PR. Could you guys consider taking some time reviewing it and proceed to merging? I do not have the permission of requesting reviews directly from GitHub UI, and am thus making this separate request. Thanks!

@stefansjfw
Copy link
Collaborator

@Aaron-Junker @stefansjfw Seems like the latest CI build failed for a problem (looks fixed) unrelated to this PR. Could you guys consider taking some time reviewing it and proceed to merging? I do not have the permission of requesting reviews directly from GitHub UI, and am thus making this separate request. Thanks!

Can you merge latest main into your branch and push? Should help with the CI fail.

This likely won't make it into the next release (will happen soon). So it might take some time to get this in

@z4pf1sh
Copy link
Author

z4pf1sh commented May 15, 2024

@stefansjfw Gotcha, done, it's fixed. Thanks for the help of you guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants