]> git.ipfire.org Git - thirdparty/libarchive.git/commit
Improve newline handling on Windows (#2115)
authorTobias Stoeckmann <stoeckmann@users.noreply.github.com>
Sat, 13 Apr 2024 05:40:02 +0000 (05:40 +0000)
committerGitHub <noreply@github.com>
Sat, 13 Apr 2024 05:40:02 +0000 (22:40 -0700)
commit46818684c3dfcb8ace2721491b9e15aff5341725
tree31262ad58073c16420910d1ba02527ce30ef26d3
parentf4d5aaed1e5c12c6a8b6d40ed80374ebab5f59a5
Improve newline handling on Windows (#2115)

If libarchive is compiled on Windows without cygwin, strip \r and \n the
same way as it is done on POSIX systems.

Also, entering an empty password as "\r\n" should lead to an empty
string. Right now, the newlines are kept.

Proof of Concept:

1. Compile libarchive with Visual Studio
2. Create a password-protected ZIP file
```
PS> bsdtar.exe --format zip --options 'zip:encryption' -cf archive.zip input.txt
Enter passphrase: <press enter>
```
3. Extract ZIP file on Windows
```
PS> bsdtar.exe -xf archive.zip
Enter passphrase: <press enter>
```
4. Extract ZIP file on Linux
```
$ bsdtar -xf archive.zip
Enter passphrase: <press enter>
Enter passphrase:
```

As can be seen in step 4, it is impossible to extract the file on Linux
with interactive input, because \r and \n are stripped.
The only way to extract the content is through command line option
passphrase:
```
$ bsdtar -xf archive.zip --passphrase $'\r\n'
```

It's also true the other way around: Creating a ZIP file with an empty
password on Linux cannot be extracted interactively on Windows. Not
allowing empty passwords at all should be part of another PR. This one
is about unifying Windows and POSIX systems regarding newline handling.
libarchive_fe/passphrase.c