diff --git a/osc/util/ar.py b/osc/util/ar.py index 66c02918b..8c501e66c 100644 --- a/osc/util/ar.py +++ b/osc/util/ar.py @@ -147,8 +147,10 @@ def _fixupFilenames(self): """ # 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 @@ def _fixupFilenames(self): 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) diff --git a/tests/fixtures/README b/tests/fixtures/README index 2b7fa007f..2801ea7ef 100644 --- a/tests/fixtures/README +++ b/tests/fixtures/README @@ -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 diff --git a/tests/fixtures/archive-no-ext_fnhdr.ar b/tests/fixtures/archive-no-ext_fnhdr.ar new file mode 100644 index 000000000..1da64b1bc --- /dev/null +++ b/tests/fixtures/archive-no-ext_fnhdr.ar @@ -0,0 +1,3 @@ +! +dir/file/ 1724142481 1000 1000 100644 14 ` +file-in-a-dir diff --git a/tests/test_util_ar.py b/tests/test_util_ar.py index 227fd4737..099e7b4d1 100644 --- a/tests/test_util_ar.py +++ b/tests/test_util_ar.py @@ -81,6 +81,12 @@ def test_saveTo_abspath(self): # 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()