File tree Expand file tree Collapse file tree 4 files changed +23
-2
lines changed
Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -33,3 +33,9 @@ Create archive.cpio
3333
3434printf "/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
Original file line number Diff line number Diff line change 1+ !<arch>
2+ dir/file/ 1724142481 1000 1000 100644 14 `
3+ file-in-a-dir
Original file line number Diff line number Diff 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
8591if __name__ == "__main__" :
8692 unittest .main ()
You can’t perform that action at this time.
0 commit comments