mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-14 06:17:18 +01:00
Merge pull request #1611 from ila-embsys/fix/ar_hdr_attr_access
Fix `dataoff` attribute access on `ext_fnhdr`
This commit is contained in:
commit
2afae5d78a
@ -147,8 +147,10 @@ class Ar:
|
||||
"""
|
||||
|
||||
# read extended header with long file names and then only seek into the right offsets
|
||||
self.__file.seek(self.ext_fnhdr.dataoff, os.SEEK_SET)
|
||||
ext_fnhdr_data = self.__file.read(self.ext_fnhdr.size)
|
||||
ext_fnhdr_data = None
|
||||
if self.ext_fnhdr:
|
||||
self.__file.seek(self.ext_fnhdr.dataoff, os.SEEK_SET)
|
||||
ext_fnhdr_data = self.__file.read(self.ext_fnhdr.size)
|
||||
|
||||
for h in self.hdrs:
|
||||
if h.file == b'/':
|
||||
@ -159,8 +161,12 @@ class Ar:
|
||||
h.file = h.file[:-1]
|
||||
continue
|
||||
|
||||
if not h.file.startswith(b'/'):
|
||||
continue
|
||||
|
||||
# long file name
|
||||
assert h.file[0:1] == b"/"
|
||||
assert ext_fnhdr_data is not None
|
||||
start = int(h.file[1:])
|
||||
end = ext_fnhdr_data.find(b'/', start)
|
||||
|
||||
|
6
tests/fixtures/README
vendored
6
tests/fixtures/README
vendored
@ -33,3 +33,9 @@ Create archive.cpio
|
||||
|
||||
printf "/tmp/foo\0/123\0very-long-long-long-long-name\0very-long-long-long-long-name2\0very-long-name
|
||||
-with-newline\0a\nb\0dir/file\0" | cpio -ocv0 --owner=root:root > archive.cpio
|
||||
|
||||
|
||||
Create archive-no-ext_fnhdr.ar
|
||||
------------------------------
|
||||
|
||||
ar qP archive-no-ext_fnhdr.ar dir/file
|
||||
|
3
tests/fixtures/archive-no-ext_fnhdr.ar
vendored
Normal file
3
tests/fixtures/archive-no-ext_fnhdr.ar
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
!<arch>
|
||||
dir/file/ 1724142481 1000 1000 100644 14 `
|
||||
file-in-a-dir
|
@ -81,6 +81,12 @@ class TestAr(unittest.TestCase):
|
||||
# this is supposed to throw an error, extracting files with absolute paths might overwrite system files
|
||||
self.assertRaises(ArError, f.saveTo, self.tmpdir)
|
||||
|
||||
def test_no_exthdr(self):
|
||||
self.archive = os.path.join(FIXTURES_DIR, "archive-no-ext_fnhdr.ar")
|
||||
self.ar = Ar(self.archive)
|
||||
self.ar.read()
|
||||
self.test_saveTo_subdir()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user