-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[IIS] Manually parse exe bitness #61894
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
Conversation
return true; | ||
} | ||
|
||
LOG_INFOF(L"%ls is unknown architecture %i", dotnetPath, fileHeader.Machine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? include the magic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic only really has 3 values. So by default this is the 3rd case so won't have an interesting value to log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR switches from using GetBinaryTypeW to manually parsing the PE header, avoiding side effects from loading the executable.
- Introduces a new static function IsX64 to determine executable bitness via PE header parsing.
- Replaces the GetBinaryTypeW call in InvokeWhereToFindDotnet with a call to IsX64.
- Implements detailed PE header checks and logging in HostFxrResolver.cpp.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.h | Declares the new IsX64 method. |
src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp | Replaces GetBinaryTypeW with IsX64 and implements PE header parsing for bitness detection. |
|
||
// Read the DOS header | ||
IMAGE_DOS_HEADER dosHeader; | ||
file.read(reinterpret_cast<char*>(&dosHeader), sizeof(dosHeader)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider verifying that the file.read operation successfully read the expected number of bytes for the DOS header to handle cases of incomplete or corrupted files.
file.read(reinterpret_cast<char*>(&dosHeader), sizeof(dosHeader)); | |
if (!file.read(reinterpret_cast<char*>(&dosHeader), sizeof(dosHeader))) | |
{ | |
LOG_INFOF(L"Failed to read DOS header from %ls", dotnetPath); | |
return false; | |
} |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem too interesting, worst case there is nothing left to read and dosHeader.e_magic
will be zero and not match IMAGE_DOS_SIGNATURE
.
} | ||
|
||
// Seek to the PE header | ||
file.seekg(dosHeader.e_lfanew, std::ios::beg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the result of file.seekg to ensure that the PE header offset is valid before proceeding with reading the PE header.
file.seekg(dosHeader.e_lfanew, std::ios::beg); | |
file.seekg(dosHeader.e_lfanew, std::ios::beg); | |
if (file.fail()) | |
{ | |
LOG_INFOF(L"Failed to seek to PE header in file %ls. Invalid e_lfanew offset: %ld", dotnetPath, dosHeader.e_lfanew); | |
return false; | |
} |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, not interesting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming something interesting does happen here, what does the failure mode look like? Does something higher up handle the exception gracefully?
src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp
Outdated
Show resolved
Hide resolved
/backport to release/8.0 |
Started backporting to release/8.0: https://github.com/dotnet/aspnetcore/actions/runs/15143703516 |
/backport to release/9.0 |
Started backporting to release/9.0: https://github.com/dotnet/aspnetcore/actions/runs/15143709929 |
@BrennanConroy backporting to "release/8.0" failed, the patch most likely resulted in conflicts: $ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: [IIS] Manually parse exe bitness
Using index info to reconstruct a base tree...
M src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp
CONFLICT (content): Merge conflict in src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 [IIS] Manually parse exe bitness
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@BrennanConroy backporting to "release/9.0" failed, the patch most likely resulted in conflicts: $ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: [IIS] Manually parse exe bitness
Using index info to reconstruct a base tree...
M src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp
CONFLICT (content): Merge conflict in src/Servers/IIS/AspNetCoreModuleV2/CommonLib/HostFxrResolver.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 [IIS] Manually parse exe bitness
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
GetBinaryTypeW
seems to load the exe into executable space which might trigger custom windows policies. Switch to parsing the PE header to find the bitness.Tested running x64 app on ARM, ARM x64 emulation mode, and x64 machine.
Tested running x86 app on ARM and x64 machine.
Tested with invalid dotnet.exe file and empty dotnet.exe file.