0.83: XnView MP can rename files to too long names
Moderators: XnTriq, helmut, xnview, Dreamer
-
- Posts: 33
- Joined: Wed Feb 10, 2016 2:16 pm
0.83: XnView MP can rename files to too long names
Hello. Using: XnViewMP Version 0.83 x64 (Oct 3 2016) Libformat version 6.92, under Windows 7 64 bit.
Using F2 to rename a file can cause the file to have a filename too long so it can't be accessed. This bug has two possible outcomes.
As you might already know, under Windows the complete path to a file must be under MAX_PATH which currently is 260 characters. That includes drive letter, all folders and slash separators, and the file's name and extension (unlike in old 8.3 fashion, period does count too). Usually you shouldn't be able to deal with files longer than this limit, unless you're using certain API functions which it seems you do. However, these functions aren't used consistently across all the libraries used by XMP, and outside XMP it's kind of rare. The normal way to find this problem is moving a folder which has a file near the limit inside a folder which with its combined name length causes the file to exceed the limit. Without special software you can't access these files, but you can always move to root the folder which has the file for a simple rename (or from now on, use XMP).
In the case of XMP, you can rename directly a file so it's complete path is longer than the limit. This can happen in two ways. First, we can try to rename to a filename with extension which is longer than the limit. In such case, XMP shows the overwriting file panel, without any file information, not knowing to do with such a long filename.
And second, we can rename a file with a name shorter than the limit, but still with complete path longer than the limit. So if the name is 240 characters long, and it's inside a 10 character long folder, and when renaming we add 15 chars more, XMP will happily rename it, and read the thumbnail, but you will not be able to see the image (neither trying to launch it from the browser, which shows a blank screen, nor from outside XMP, which shows a 'file not found' error from XMP. However with XMP you can rename the file back to shorter than the limit.
My suggestion is that while renaming a file, each time the text changes, you calculate the complete path length and if it's larger than MAX_PATH, crop the last chars of the name (without touching the extension) so it is still accessable both to XMP and to any other program without giving problems. You could even add an option to specify how many 'safe characters' are between the limit and the maximum length that XMP will allow to rename.
I haven't tested with the autorenamer since I use another specific tool for that and I'm not familiar with yours. I'd also check name and path length limits for the other OS XMP is released for.
Regards, JMM.
Using F2 to rename a file can cause the file to have a filename too long so it can't be accessed. This bug has two possible outcomes.
As you might already know, under Windows the complete path to a file must be under MAX_PATH which currently is 260 characters. That includes drive letter, all folders and slash separators, and the file's name and extension (unlike in old 8.3 fashion, period does count too). Usually you shouldn't be able to deal with files longer than this limit, unless you're using certain API functions which it seems you do. However, these functions aren't used consistently across all the libraries used by XMP, and outside XMP it's kind of rare. The normal way to find this problem is moving a folder which has a file near the limit inside a folder which with its combined name length causes the file to exceed the limit. Without special software you can't access these files, but you can always move to root the folder which has the file for a simple rename (or from now on, use XMP).
In the case of XMP, you can rename directly a file so it's complete path is longer than the limit. This can happen in two ways. First, we can try to rename to a filename with extension which is longer than the limit. In such case, XMP shows the overwriting file panel, without any file information, not knowing to do with such a long filename.
And second, we can rename a file with a name shorter than the limit, but still with complete path longer than the limit. So if the name is 240 characters long, and it's inside a 10 character long folder, and when renaming we add 15 chars more, XMP will happily rename it, and read the thumbnail, but you will not be able to see the image (neither trying to launch it from the browser, which shows a blank screen, nor from outside XMP, which shows a 'file not found' error from XMP. However with XMP you can rename the file back to shorter than the limit.
My suggestion is that while renaming a file, each time the text changes, you calculate the complete path length and if it's larger than MAX_PATH, crop the last chars of the name (without touching the extension) so it is still accessable both to XMP and to any other program without giving problems. You could even add an option to specify how many 'safe characters' are between the limit and the maximum length that XMP will allow to rename.
I haven't tested with the autorenamer since I use another specific tool for that and I'm not familiar with yours. I'd also check name and path length limits for the other OS XMP is released for.
Regards, JMM.
-
- Posts: 8705
- Joined: Sun Oct 12, 2003 6:47 pm
- Location: Frankfurt, Germany
Re: 0.83: XnView MP can rename files to too long names
I could reproduce this problem by renaming an image file to this:JMM72 wrote:First, we can try to rename to a filename with extension which is longer than the limit. In such case, XMP shows the overwriting file panel, without any file information, not knowing to do with such a long filename.
"My Image with 265 charachter filename 901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.jpg"
Also confirmed. (I removed some characters from my filename above).JMM72 wrote:And second, we can rename a file with a name shorter than the limit, but still with complete path longer than the limit. So if the name is 240 characters long, and it's inside a 10 character long folder, and when renaming we add 15 chars more, XMP will happily rename it, and read the thumbnail, but you will not be able to see the image (neither trying to launch it from the browser, which shows a blank screen, nor from outside XMP, which shows a 'file not found' error from XMP. However with XMP you can rename the file back to shorter than the limit.
-
- Posts: 1
- Joined: Fri May 19, 2017 4:12 pm
Re: 0.83: XnView MP can rename files to too long names
Try with the long path tool. I used it for similar but not the exact problem and it worked. It was related to a long path file deletion problem.
-
- Author of XnView
- Posts: 44920
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: 0.83: XnView MP can rename files to too long names
O.k., thank you, I can also reproduce the problem. Issue 1268 is fixed in next version.
Pierre.
-
- Author of XnView
- Posts: 44920
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: 0.83: XnView MP can rename files to too long names
This problem is supposed to be fixed in XnView MP 0.87. Please check and confirm the bug fix here.
Pierre.
-
- Posts: 218
- Joined: Thu Jan 28, 2010 7:30 am
Re: 0.83: XnView MP can rename files to too long names
Tested with 0.87 beta 2, not fixed.
Tested bij renaming a file with XnViewMP (F2) to something with <250 characters>.jpg, in a path of 15 characters.
I understood XnViewMP wasn't supposed to allow that anymore.
In version 0.86 the thumb of the long filename file isn't shown and the file cannot be opened.
In 0.87 the thumb is shown, but the file cannot be opened, message File can't be loaded.
In Windows Explorer the file cannot be deleted, not even renamed...
Only after renaming the file in XnViewMP, shortening it 20 characters, the file can be handled again.
In Windows Explorer, when typing a filename, the input just stops after the max amount of characters.
When pasting a too long name in the rename dialog, the string is truncated.
Tested bij renaming a file with XnViewMP (F2) to something with <250 characters>.jpg, in a path of 15 characters.
I understood XnViewMP wasn't supposed to allow that anymore.
In version 0.86 the thumb of the long filename file isn't shown and the file cannot be opened.
In 0.87 the thumb is shown, but the file cannot be opened, message File can't be loaded.
In Windows Explorer the file cannot be deleted, not even renamed...
Only after renaming the file in XnViewMP, shortening it 20 characters, the file can be handled again.
In Windows Explorer, when typing a filename, the input just stops after the max amount of characters.
When pasting a too long name in the rename dialog, the string is truncated.
-
- Author of XnView
- Posts: 44920
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: 0.83: XnView MP can rename files to too long names
you are able to rename a full path to more than 260 chars???
Pierre.
-
- Posts: 218
- Joined: Thu Jan 28, 2010 7:30 am
Re: 0.83: XnView MP can rename files to too long names
Yes....
But it depends on how you test.
Because it it not easy to test by counting 250 keypresses or so, I used an editor and types a filename with 250 characters, looking at the column counter of the editor. Then I copy/pasted that 250 character string into the Rename dialog of XnViewMP.
If you start typing a long filename in the Rename dialog of XnViewMP, it's different.
So please test yourselves with the following procedures:
Still possible to rename:
Copy/paste a 250 character string into the Rename dialog of XnViewMP. The name is accepted, the file is renamed, but not accessible
Not possible to rename:
Copy/paste a 257 character string into the Rename dialog of XnViewMP. A message "An error occurs during rename!" appears.
SO: only the filename length is checked, NOT the complete path.
But it depends on how you test.
Because it it not easy to test by counting 250 keypresses or so, I used an editor and types a filename with 250 characters, looking at the column counter of the editor. Then I copy/pasted that 250 character string into the Rename dialog of XnViewMP.
If you start typing a long filename in the Rename dialog of XnViewMP, it's different.
So please test yourselves with the following procedures:
Still possible to rename:
Copy/paste a 250 character string into the Rename dialog of XnViewMP. The name is accepted, the file is renamed, but not accessible
Not possible to rename:
Copy/paste a 257 character string into the Rename dialog of XnViewMP. A message "An error occurs during rename!" appears.
SO: only the filename length is checked, NOT the complete path.
-
- XnThusiast
- Posts: 4186
- Joined: Sun Apr 29, 2012 9:45 am
- Location: Cheltenham, U.K.
Re: 0.83: XnView MP can rename files to too long names
Could you post test long filenames for Pierre to use?
You could if you wish edit the above post, either pasting in the long names (if that works satisfactorily) or attach a suitable file (a text file would have to be placed in a ZIP or similar archive, I think).
You could if you wish edit the above post, either pasting in the long names (if that works satisfactorily) or attach a suitable file (a text file would have to be placed in a ZIP or similar archive, I think).
-
- Posts: 218
- Joined: Thu Jan 28, 2010 7:30 am
Re: 0.83: XnView MP can rename files to too long names
Of course I could, but I cannot imagine that just I can create the bug, because it's so obvious.
Just try it on a file that is located in a path with 10 characters in lengt or so, and pase a filename with 250 characters in it.
To help, here is a 250 character string:
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567890
Just paste that string above in the Rename dialog box and press OK.
The file s renamed, which shouldn't be possible.
The file cannot be opened with XnViewMP and not with Windows explorer.
Luckily it can be renamed back to something short with both applications to get access again.
Just try it on a file that is located in a path with 10 characters in lengt or so, and pase a filename with 250 characters in it.
To help, here is a 250 character string:
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567890
Just paste that string above in the Rename dialog box and press OK.
The file s renamed, which shouldn't be possible.
The file cannot be opened with XnViewMP and not with Windows explorer.
Luckily it can be renamed back to something short with both applications to get access again.
-
- Posts: 15
- Joined: Sat Jan 03, 2015 11:32 am
Re: 0.83: XnView MP can rename files to too long names
I hope this bug wasn't fixed in the linux version because linux can handle >260 character path names.
-
- Author of XnView
- Posts: 44920
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: 0.83: XnView MP can rename files to too long names
it was a fix for windows onlyShnoober wrote:I hope this bug wasn't fixed in the linux version because linux can handle >260 character path names.
Pierre.
-
- Posts: 218
- Joined: Thu Jan 28, 2010 7:30 am
Re: 0.83: XnView MP can rename files to too long names
Just form my "administration": Not yet fixed in 0.87 final.
-
- Posts: 218
- Joined: Thu Jan 28, 2010 7:30 am
Re: 0.83: XnView MP can rename files to too long names
Not yet fixed in 0.88.
Tested again:
Used a directory D:\1234567890
Copied a file in that directory and started the rename process.
- A filename of more than 260 characters long cannot be entered in the File rename field.
- A filename of 260 characters can be entered, but when clicking OK, the message An error occurs during rename! appears.
- A filename of 252 can be entered and is accepted. This is the longest filename accepted by XnViewMP, no matter where the file is, so for example in the root. But in this example the file is in D:\1234567890 and it cannot be handled by Windows Explorer.
The total path:
D:\1234567890\1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 123456789.JPG
- Shortened the filename until it could be handled by Windows Explorer that was when the total path length was 260 characters, so the filename in this example was 242 characters.
The total path of the longest Windows-accepted filename:
D:\1234567890\1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890.JPG
Tested again:
Used a directory D:\1234567890
Copied a file in that directory and started the rename process.
- A filename of more than 260 characters long cannot be entered in the File rename field.
- A filename of 260 characters can be entered, but when clicking OK, the message An error occurs during rename! appears.
- A filename of 252 can be entered and is accepted. This is the longest filename accepted by XnViewMP, no matter where the file is, so for example in the root. But in this example the file is in D:\1234567890 and it cannot be handled by Windows Explorer.
The total path:
D:\1234567890\1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 123456789.JPG
- Shortened the filename until it could be handled by Windows Explorer that was when the total path length was 260 characters, so the filename in this example was 242 characters.
The total path of the longest Windows-accepted filename:
D:\1234567890\1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890.JPG