Menu

#212 handle special chars in filenames

v1.0 (example)
open
nobody
None
5
2018-06-26
2018-06-18
md-work
No

p7zip has problems handling special chars in filenames.
(tested on openSUSE-15.0 with p7zip-16.02 on an ext4 filesystem)
Some examples:

Can't add files containig a newline via -i, because a newline ends the filename when using -i. (escaping needed)

$ echo 'Hello world!' > "$(echo -ne 'newline_\n_newline.txt')"
$ echo -e 'test_\x0A_newline.txt' > listfile
$ 7z a -i@listfile test.zip 
[...]

WARNING: No more files
test_


WARNING: No more files
_newline.txt

0 files, 0 bytes

7z can't correctly list ZIP files with newline-filenames included. (again escaping needed)

$ 7z a test.zip test_*_newline.txt
[...]
Scanning the drive:
1 file, 13 bytes (1 KiB)

Creating archive: test.zip

Items to compress: 1
$ 7z l test.zip 
[...]
   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2018-06-13 14:40:36 .....           13           13  test_
_newline.txt
------------------- ----- ------------ ------------  ------------------------
2018-06-13 14:40:36                 13           13  1 files

p7zip can't add files with invalid chars inside the filename.
It should either say, that it doesn't accept them and escape the invalid chars in the error message when quoting the filename. Or p7zip should handle those files just like others (at least Linux allows normal handling of those filenames).
(0x80 is an invalid char in UTF-8)

$ echo 'Hello world!' > "$(echo -ne 'test_\x80_x80.txt')"
$ 7z a test.zip "$(echo -ne 'test_\x80_x80.txt')"                             
[...]          
WARNING: No more files
test__x80.txt

0 files, 0 bytes

Creating archive: test.zip

Items to compress: 0


Files read from disk: 0
Archive size: 22 bytes (1 KiB)

Scan WARNINGS for files and folders:

test__x80.txt : No more files
----------------
Scan WARNINGS: 1

To handle strange chars more easily in output and with the "-i" listfile, p7zip should maybe introduce an escape char to hex representation. Somilar to what echo -e '\x80' does. Except \\ is probably not a good escape char in filename context. Maybe ? is better, so it's ?x80 for 0x80 and ?x3F for ? itself.

Discussion

  • Igor Pavlov

    Igor Pavlov - 2018-06-19

    p7zip is not updated.
    Now I don't know any good solution.
    If you think that we can do something for original 7-zip for Windows, write your suggestion and attach example archive.

     
  • Anonymous

    Anonymous - 2018-06-26

    I just noticed that p7zip hasn't been updated in a while (at least from official stable ubuntu repository), the solution I would reccomend (maybe adding this to your website as a better way of using 7zip for unix) would be using it via wine. Unlike a lot of windows software, 7zip x64 seems to work great on v18.05 latest as of this writing. By installing wine & wine64, then just running - winecfg and letting wine create configuration. I kept it at default virtual os emulation of windows xp. Then i just created a shortcut on desktop, the program ui looks exactly the same, no weird cropping or missing options and all features seem to still work as they did on my windows pc. I haven't tested the command-line version of 7zip, but maybe i can also experiment with that later as well.

    I've been curious though, have you ever considered comming out with official support for linux? I don't if if it's coded in a certain way that would just require to much rewrite to support it or not.

     

Log in to post a comment.

MongoDB Logo MongoDB