@@ -550,7 +550,7 @@ def test_extractfile_attrs(self):
550550 self .assertIs (fobj .seekable (), True )
551551
552552
553- class _ReadSizeRecorder (io .BytesIO ):
553+ class ReadSizeRecorder (io .BytesIO ):
554554 # Records the largest size ever passed to read(), so a test can check
555555 # that tarfile does not request far more data than the archive holds
556556 # (which on a real file would pre-allocate it).
@@ -564,36 +564,37 @@ def read(self, size=-1):
564564 return super ().read (size )
565565
566566
567+ @support .cpython_only
567568class ExtendedHeaderMemoryTest (unittest .TestCase ):
568569 # gh-151497: the size of a GNU long name/link or a pax extended header is
569570 # read from the archive and is untrusted. A crafted header can claim a
570571 # size far larger than the file actually contains; opening such an archive
571572 # must not try to read (and so pre-allocate) the claimed size in one go.
572573
573- def _crafted_archive (self , hdrtype ):
574+ def crafted_archive (self , hdrtype ):
574575 tarinfo = tarfile .TarInfo ("A" )
575576 tarinfo .type = hdrtype
576577 tarinfo .size = 0xFFFFFFFF # ~4 GiB claimed in a 512-byte header
577578 return tarinfo .tobuf (format = tarfile .GNU_FORMAT )
578579
579- def _check (self , hdrtype ):
580- fobj = _ReadSizeRecorder (self ._crafted_archive (hdrtype ))
580+ def check (self , hdrtype ):
581+ fobj = ReadSizeRecorder (self .crafted_archive (hdrtype ))
581582 try :
582583 with tarfile .open (fileobj = fobj , mode = "r:" ) as tar :
583584 tar .getmembers ()
584585 except tarfile .ReadError :
585586 pass # a truncated header is fine; we only check the allocation
586587 # The bogus ~4 GiB size must never reach a single read() call.
587- self .assertLess (fobj .max_read_size , 10 * 1024 * 1024 )
588+ self .assertLessEqual (fobj .max_read_size , tarfile . _EXTHEADER_READ_CHUNK )
588589
589590 def test_gnu_longname_oversized_size (self ):
590- self ._check (tarfile .GNUTYPE_LONGNAME )
591+ self .check (tarfile .GNUTYPE_LONGNAME )
591592
592593 def test_gnu_longlink_oversized_size (self ):
593- self ._check (tarfile .GNUTYPE_LONGLINK )
594+ self .check (tarfile .GNUTYPE_LONGLINK )
594595
595596 def test_pax_header_oversized_size (self ):
596- self ._check (tarfile .XHDTYPE )
597+ self .check (tarfile .XHDTYPE )
597598
598599
599600class MiscReadTestBase (CommonReadTest ):
0 commit comments