-
Notifications
You must be signed in to change notification settings - Fork 3.2k
screenshot: long filename handling improvements #10052
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
255 is a magic number. It should not be hardcoded. It should probably be MAX_PATH.
On windows MAX_PATH can be more than 255, because it has enough space to hold UTF8 of 260
wchar_telements.Also, if
extlenis 255 or more, thenmax_utf8_byteswill wrap around to a huge number...Uh oh!
There was an error while loading. Please reload this page.
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.
It should not be
MAX_PATHbecauseMAX_PATHis not the basename length.MAX_PATHis to hold drive-letter +":\"+ basename of255256(??)wchar_t/charelements + NUL terminator.Per Maximum Path Length Limitation for Windows:
Bothering to check
GetVolumeInformationisn't worth doing though.All relevant filesystem use 255 for segments of filename (including for non-Windows OSes).
If
ext_lenis 255 let mpv blow up because that's an absurd case to care about.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.
Which is why I said probably, I.e. you should figure whether it should be MAX_PATH or something else, like MAX_NAME.
The point is that 255 should not be hardcoded. It should be appropriate for the current platform, and if it's not MAX_PATH and not MAX_NAME then you should figure out what it needs to be, without calling APIs.
It should probably be some existing constant of the platform, and not hardcoded inside this function.
In your applications maybe. Not in mpv.
You mean that the example you gave which should be fixed are not absurd cases, and so we should really care about them, like this?
Luckily for you though, it won't blow up, but it will also not work.
It's not rocket science. Please fix it correctly.
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.
Which is what I did and why 255.
Don't hardcode but also figure it out without calling APIs? Okay...
The extension comes from mpv. If mpv decides to use 255 character long extensions then that is mpv's fault.
You're missing something if you think that won't work, or why it was listed as an example for testing removal of invalidated UTF-8 codepoints due to truncation.
Uh oh!
There was an error while loading. Please reload this page.
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.
I don't know if it's available.
We have this:
mpv/osdep/io.c
Lines 539 to 547 in ef4c6df
But it's only used privately at this C file when enumerating files in a directory.
Not sure how to solve this in general. I don't think we should change the global MAX_PATH either.
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.
NAME_MAXseems to available inlimits.hfor Linux/macos as 255. It's also in my mingw64/msys2'slimits.hbut behind a_POSIX_ifdef. BSDs haveMAXNAMELENwhich is 255 as far as I can tell.Something like this, hardcoding 255, or calling out to
GetVolumeInformation/pathconf(_PC_NAME_MAX)Uh oh!
There was an error while loading. Please reload this page.
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.
For win32 you can use
_MAX_FNAMEhttps://learn.microsoft.com/en-us/cpp/c-runtime-library/path-field-limitsNote that
_MAX_FNAMEincludes space for terminating null, whileNAME_MAXdoes not.EDIT: And just as I mentioned in the other PR. Shouldn't we set long paths support in manifest on Windows?
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.
I didn't include it because of that but yeah a Windows specific define could be
(_MAX_FNAME-1)which is 255There 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.
In my opinion, yes..