mirror of
https://github.com/openSUSE/osc.git
synced 2025-01-14 01:26:23 +01:00
Use os.getcwdb() instead of os.getcwd().encode() in util.cpio.CpioRead
Using os.getcwd() in combination with a subsequent .encode() is error
prone:
marcus@linux:~> mkdir illegal_utf-8_encoding_$'\xff'_dir
marcus@linux:~> cd illegal_utf-8_encoding_$'\xff'_dir/
marcus@linux:~/illegal_utf-8_encoding_ÿ_dir> python3
Python 3.8.6 (default, Nov 09 2020, 12:09:06) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getcwd().encode()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 36: surrogates not allowed
>>>
Hence, use os.getcwdb(), which returns a bytes, instead of
os.getcwd().encode().
Fixes: commit 36f7b8ffe9
("Fix a
potential TypeError in CpioRead.copyin and CpioRead.copyin_file")
This commit is contained in:
parent
674ea78815
commit
1933da5bcc
@ -182,7 +182,7 @@ class CpioRead:
|
||||
hdr = self._get_hdr(filename)
|
||||
if not hdr:
|
||||
raise CpioError(filename, '\'%s\' does not exist in archive' % filename)
|
||||
dest = dest or os.getcwd().encode()
|
||||
dest = dest or os.getcwdb()
|
||||
fn = new_fn or filename
|
||||
self._copyin_file(hdr, dest, fn)
|
||||
|
||||
@ -191,7 +191,7 @@ class CpioRead:
|
||||
extracts the cpio archive to dest.
|
||||
If dest is None $PWD will be used.
|
||||
"""
|
||||
dest = dest or os.getcwd().encode()
|
||||
dest = dest or os.getcwdb()
|
||||
for h in self.hdrs:
|
||||
self._copyin_file(h, dest, h.filename)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user