File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -785,6 +785,43 @@ def test_pax_number_fields(self):
785785 finally :
786786 tar .close ()
787787
788+ def test_pax_header_bad_formats (self ):
789+ # The fields from the pax header have priority over the
790+ # TarInfo.
791+ pax_header_replacements = (
792+ b" foo=bar\n " ,
793+ b"0 \n " ,
794+ b"1 \n " ,
795+ b"2 \n " ,
796+ b"3 =\n " ,
797+ b"4 =a\n " ,
798+ b"1000000 foo=bar\n " ,
799+ b"0 foo=bar\n " ,
800+ b"-12 foo=bar\n " ,
801+ b"000000000000000000000000036 foo=bar\n " ,
802+ )
803+ pax_headers = {"foo" : "bar" }
804+ for replacement in pax_header_replacements :
805+ tar = tarfile .open (tmpname , "w" , format = tarfile .PAX_FORMAT ,
806+ encoding = "iso8859-1" )
807+ try :
808+ t = tarfile .TarInfo ()
809+ t .name = "pax" # non-ASCII
810+ t .uid = 1
811+ t .pax_headers = pax_headers
812+ tar .addfile (t )
813+ finally :
814+ tar .close ()
815+ with open (tmpname , "rb" ) as f :
816+ data = f .read ()
817+ self .assertIn (b"11 foo=bar\n " , data )
818+ data = data .replace (b"11 foo=bar\n " , replacement )
819+ with open (tmpname , "wb" ) as f :
820+ f .truncate ()
821+ f .write (data )
822+ with self .assertRaisesRegexp (tarfile .ReadError , r"file could not be opened successfully" ):
823+ tarfile .open (tmpname , encoding = "iso8859-1" )
824+
788825
789826class WriteTestBase (unittest .TestCase ):
790827 # Put all write tests in here that are supposed to be tested
You can’t perform that action at this time.
0 commit comments