-
Notifications
You must be signed in to change notification settings - Fork 947
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
Stubs on Windows exit abnormally, includes succinct repro with busybox, related to some wider issue #6699
Comments
I can see the problem, but don't have much idea why it occurs. What I've done:
The question is why not. I was suspicious of the changes the busybox-w32 shell makes to environment variables when it reads them in as shell variables. By default it converts the variable names to uppercase and replaces backslashes with forward slashes in the value. (There are a couple of exceptions to the latter, it seemed possible more might be needed.) I made a custom shell so those changes could be avoided. It remains necessary to change |
Thanks for the report. I presume this is a bug in our "trampoline" that's used for executables on Windows. I don't see an error message in the video, what's the failure mode exactly? |
Does this behave as if it was a MinGW based environment? There's been a number of MinGW related issues, especially when it comes to paths. e.g. #3573 |
@zanieb In my experience the failure mode is a 0xc0000005 error, which I (possibly wrongly) equate to a segfault. |
@samypr100 The issue you reference seems to be somewhat confused about what MinGW means. (And I'm not sure I can be lucid enough to clear up the confusion.) MinGW (and these days that generally means MinGW-w64) is a set of headers and libraries which make it possible to build native Windows applications. There are various ways that can be done:
busybox-w32 is built using MinGW, so it's a native Windows binary which deals in native Windows paths. This can be opposed to binaries built using the Cygwin DLL, such as those that come with MSYS2: these see fake POSIX paths. When the referenced issue talks of 'mingw python' it seems to mean the Python that's shipped with MSYS2. This is built using the Cygwin DLL and understands non-Windows paths. I wouldn't call that a 'MinGW Python'. Furthermore, I wouldn't be at all surprised to hear there have been issues with it's expectations regarding paths. |
@rmyorston Thanks for the explanation. I've made an adjustment in #6792 that would fix this issue, or at least not fault. I haven't digged into the busybox impl, but uv/crates/uv-trampoline/src/bounce.rs Lines 347 to 349 in 3be4fe5
|
@samypr100 The fix sounds promising, thanks. The shell in busybox-w32 uses It'll be interesting to know if the fix also resolves #6464. |
## Summary Closes #6699 On cases like the ones described in #6699, `lpReserved2` somehow seems to report multiple file descriptors that were not tied to any valid handles. The previous implementation was faulting as it would try to dereference these invalid handles. This change moves to using `HANDLE` directly and check if its is_invalid instead before attempting to close them. ## Test Plan Manually tested and verified using `busybox-w32` like described in the issue. --------- Co-authored-by: konstin <[email protected]>
Is it expected to see
when invoking the stub from within sh onto stderr? otherwise things appear to be behaving normally |
#6955) ## Summary Resolves issues mentioned in comments * #6699 (comment) * #6866 (comment) Further investigation on the comments revealed that the pointer arithmethic being performed in `let handle_start = unsafe { crt_magic.offset(1 + handle_count) };` from [posy trampoline](https://github.com/njsmith/posy/blob/dda22e6f90f5fefa339b869dd2bbe107f5b48448/src/trampolines/windows-trampolines/posy-trampoline/src/bounce.rs#L146) had some slight errors. Since `crt_magic` was a `*const u32`, doing an offset by `1 + handle_count` would offset by too much, with some possible out of bounds reads or attempts to call CloseHandle on garbage. We needed to offset differently since we want to offset by `handle_count` bytes after the initial offset as seen in [launcher.c](https://github.com/pypa/distlib/blob/888c48b56886b03398646be1217508830427bd75/PC/launcher.c#L578). Similarly, we needed to skip the first 3 handles, otherwise we'd still be attempting to close standard I/O handles of the parent (in this case the shell from `busybox.exe sh -l`). I also added a few extra checks available from `launcher.c` which checks if the handle value is `-2` just to match the distlib implementation more closely and minimize differences. ## Test Plan Manually compiled distlib's launcher with additional logging and replaced `Lib/site-packages/pip/_vendor/distlib/t64.exe` with the compiled one to log pointers. As a result, I was able to verify the retrieved handle memory addresses in this function actually match in both uv and distlib's implementation from within busybox.exe nested shell where this behavior can be observed and manually tested. I was also able to confirm this fixes the issues mentioned in the comments, at least with busybox's shell, but I assume this would fix the case with cmake. ## Open areas `launcher.c` also [checks the size](https://github.com/pypa/distlib/blob/888c48b56886b03398646be1217508830427bd75/PC/launcher.c#L573-L576) of `cbReserved2` before retrieving `handle_start` which this function currently doesn't do. If we wanted to, we could add the additional check here as well, but I wasn't fully sure why it wasn't added in the first place. Thoughts? ```rust // Verify the buffer is large enough if si.cbReserved2 < (size_of::<u32>() as isize + handle_count + size_of::<HANDLE>() as isize * handle_count) as u16 { return; } ``` --------- Co-authored-by: konstin <[email protected]>
@doctorpangloss Would you be able to confirm 0.4.5 fixes the fd issue for you? |
no, unfortunately the stubs still show the issue, they do work though |
Could you provide steps on how to reproduce this particular case? |
nervermind it's resolved! 0.4.8 has fixed it |
related: rmyorston/busybox-w32#451
related: #6464
Observe
pip
exits abnormally under this shell. In Powershell it works fine.uv 0.3.4 (39f3cd2 2024-08-26)
Windows 2022
All stubs, not just
pip
, are cursed this way. The stubs created by nativepip
do not have any issues.The text was updated successfully, but these errors were encountered: