Skip to content

Fix GH-10992: Improper long path support for relative paths #16687

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

Closed
wants to merge 2 commits into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Nov 3, 2024

Relative paths are passed to the ioutils APIs, these are not properly converted to long paths. If the path length already exceeds a given threshold (usually 259 characters, but only 247 for mkdir()), the long path prefix is prepended, resulting in an invalid path, since long paths have to be absolute. If the path length does not exceed that threshold, no conversion to a long path is done, although that may be necessary.

Thus we take the path length of the current working directory into account when checking the threshold, and prepend it to the filename if necessary.

Since this is only relevant for NTS builds, and using the current working directory of the process would be erroneous for ZTS builds, we skip the new code for ZTS builds.


Note that I chose the least intrusive solution I could think of since I would like to fix this issue for stable branches; still, I'm not absolutely sure that this patch may not have inadvertent side effects, so I've targeted PHP-8.4 for now.

I think in the long run the whole ioutil code should be reviewed and overhauled. I doubt that the heavy inlining is reasonable, especially considering the many (re-)allocations of buffers (all using native Windows malloc() and friends which are supposed to be relatively slow), and some operations might be simplified (possibly at the cost of some runtime performance loss, which may not really matter here). Furthermore, the "module" dependencies are not quite clear (ioutils, Zend, TSRM is all a bit mixed up).

cc @nielsdos

Relative paths are passed to the ioutils APIs, these are not properly
converted to long paths.  If the path length already exceeds a given
threshold (usually 259 characters, but only 247 for `mkdir()`), the
long path prefix is prepended, resulting in an invalid path, since long
paths have to be absolute.  If the path length does not exceed that
threshold, no conversion to a long path is done, although that may be
necessary.

Thus we take the path length of the current working directory into
account when checking the threshold, and prepend it to the filename if
necessary.

Since this is only relevant for NTS builds, and using the current
working directory of the process would be erroneous for ZTS builds, we
skip the new code for ZTS builds.
@cmb69 cmb69 marked this pull request as ready for review November 3, 2024 16:45
@cmb69 cmb69 requested a review from bukka as a code owner November 3, 2024 16:45
@cmb69
Copy link
Member Author

cmb69 commented Nov 3, 2024

I don't think there is an ABI break, and even no API break (except that consumers would need to be rebuilt to get the new functionality). Still, something to consider.

@cmb69 cmb69 removed the ABI break label Nov 3, 2024
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of code duplication and convoluted logic. Hard to follow ngl (not your fault ofc).
But it seems right, I think, but not sure.

@cmb69 cmb69 closed this in 5c76ef7 Nov 7, 2024
@cmb69 cmb69 deleted the cmb/gh10992 branch November 7, 2024 12:35
@cmb69
Copy link
Member Author

cmb69 commented Nov 7, 2024

I've applied to master only, since some extensions may already have been built, and that might cause different behavior, which could be very confusing.

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

Successfully merging this pull request may close these issues.

2 participants