CoreRun tries to execute .exe from incorrect path.
This was tested and observed at both ARM/Linux and x64/Linux.
Reproduction
- Install coreclr & corefx at directory
/A/ - Install
a.exeat directory/B/ - Create another
a.exe(different from/B/a.exe) at/A/(for a more dramatic failure, create a null file,/A/a.exe) - At
/A/, run./corerun /B/a.exe
Expected
- The file
/B/a.exeis executed.
Result
- The file
/A/a.exeis executed.
Note that if /A/a.exe does not exist, it properly executed B/a.exe.
I had similar issue.
I was playing with 'HelloWord' example trying to create some test but it was not working. Finally I took original 'HelloWord' example and just changed the message but on launch it printed original unmodified message. I even tried to change file name but it didn't help.
It printed new message only when I changed name of the 'class' in my modified 'HelloWord' example.
It helped me to find that I had 'HelloWord' application binary in directory with 'corerun'.
I suppose it worked in the following way: when I launched corerun_dir/corerun my_dir/my_app.exe, 'corerun' extracted name of the 'class' from my binary and started to load 'class' with than name but instead of using explicit path (my_dir/my_app.exe) specified in command line 'corerun' started to search for file with necessary 'class' name and found alternative file with different file name but with the same 'class' name in its own directory (corerun_dir).
HRESULT AssemblyBinder::BindByTpaList(...)uses simpleName that extracts the filename from the full path, which later makes the fileName at line 1362 of the same function, to refer /A/a.exe, not /B/a.exe. (pTpaEntry->m_wszILFileName is incorrectly initialized)
This is a logic error in ``HRESULT AssemblyBinder::BindByTpaList`.
Another really fishy scheme is at AssemblyBinder::BindWhereRef() (src/binder/assemblybinder.cpp):
It first gets "assemblyName" from the "assemblyPath" (/B/a.exe), which results in a as the assemblyName. at Line 1006-1021.
Then, it retrieves the assembly based on the assemblyName, a, which results in searching for /A/a.exe before trying the original full path /B/a.exe.
The code around here is juggling around the path info too excessively while we do not support anything like GAC yet. :(
A fix is being implemented by enforcing CLRPrivBinderCoreCLR::Bind()'s call to AssemblyBinder::BindAssembly() explicitly state that it MUST find the assembly in the given path.
This could be done by nullptr test of szCodeBase argument of AssemblyBinder::BindAssembly()
, which is supposed to do so by calling BindByName if it's null and BindWhereRef if it's not null.
However, in the current coreclr, it goes to BindByTpaList regardless of what's being intended.
~~It look like the current commit of CoreCLR has this issue fixed. I'll verify if it's completely gone and close this afterwards.~~
Negative.
The linked PR had some issues and wasn't completed, so this issu remains up for grabs.