Skip to content

Commit 2afae5d

Browse files
authored
Merge pull request openSUSE#1611 from ila-embsys/fix/ar_hdr_attr_access
Fix `dataoff` attribute access on `ext_fnhdr`
2 parents 735bab7 + 2920529 commit 2afae5d

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

osc/util/ar.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ def _fixupFilenames(self):
147147
"""
148148

149149
# read extended header with long file names and then only seek into the right offsets
150-
self.__file.seek(self.ext_fnhdr.dataoff, os.SEEK_SET)
151-
ext_fnhdr_data = self.__file.read(self.ext_fnhdr.size)
150+
ext_fnhdr_data = None
151+
if self.ext_fnhdr:
152+
self.__file.seek(self.ext_fnhdr.dataoff, os.SEEK_SET)
153+
ext_fnhdr_data = self.__file.read(self.ext_fnhdr.size)
152154

153155
for h in self.hdrs:
154156
if h.file == b'/':
@@ -159,8 +161,12 @@ def _fixupFilenames(self):
159161
h.file = h.file[:-1]
160162
continue
161163

164+
if not h.file.startswith(b'/'):
165+
continue
166+
162167
# long file name
163168
assert h.file[0:1] == b"/"
169+
assert ext_fnhdr_data is not None
164170
start = int(h.file[1:])
165171
end = ext_fnhdr_data.find(b'/', start)
166172

tests/fixtures/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ Create archive.cpio
3333

3434
printf "/tmp/foo\0/123\0very-long-long-long-long-name\0very-long-long-long-long-name2\0very-long-name
3535
-with-newline\0a\nb\0dir/file\0" | cpio -ocv0 --owner=root:root > archive.cpio
36+
37+
38+
Create archive-no-ext_fnhdr.ar
39+
------------------------------
40+
41+
ar qP archive-no-ext_fnhdr.ar dir/file
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!<arch>
2+
dir/file/ 1724142481 1000 1000 100644 14 `
3+
file-in-a-dir

tests/test_util_ar.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ def test_saveTo_abspath(self):
8181
# this is supposed to throw an error, extracting files with absolute paths might overwrite system files
8282
self.assertRaises(ArError, f.saveTo, self.tmpdir)
8383

84+
def test_no_exthdr(self):
85+
self.archive = os.path.join(FIXTURES_DIR, "archive-no-ext_fnhdr.ar")
86+
self.ar = Ar(self.archive)
87+
self.ar.read()
88+
self.test_saveTo_subdir()
89+
8490

8591
if __name__ == "__main__":
8692
unittest.main()

0 commit comments

Comments
 (0)