@@ -475,7 +475,8 @@ public bool VerifyFile(string entryName)
475475
476476 Logger . LogInformation ( "Verifying file integrity: {name}" , entryName ) ;
477477
478- byte [ ] hash = Bundle . ComputeSHA512Hash ( GetStream ( entryName ) ) ;
478+ using Stream stream = GetStream ( entryName ) ;
479+ byte [ ] hash = ComputeSHA512Hash ( stream ) ;
479480 bool result = Manifest . GetEntries ( ) [ entryName ] . SequenceEqual ( hash ) ;
480481
481482 Logger . LogInformation ( "File integrity verification result for {name}: {result}" , entryName , result ) ;
@@ -498,7 +499,7 @@ public bool VerifySignature(string certificateHash)
498499
499500 Logger . LogInformation ( "Verifying signature with certificate: {name}" , certificate . Subject ) ;
500501
501- byte [ ] manifestHash = GetBytes ( ".manifest.ec" , ReadSource . Bundle ) ;
502+ byte [ ] manifestHash = ComputeSHA512Hash ( GetBytes ( ".manifest.ec" , ReadSource . Bundle ) ) ;
502503 bool result = pubKey . VerifyHash ( manifestHash , hash , HashAlgorithmName . SHA512 , RSASignaturePadding . Pkcs1 ) ;
503504
504505 Logger . LogInformation ( "Signature verification result for certificate {name}: {result}" , certificate . Subject , result ) ;
@@ -607,7 +608,8 @@ public byte[] GetBytes(string entryName, ReadSource readSource)
607608
608609 if ( ! _cache . TryGetValue ( entryName , out byte [ ] ? data ) )
609610 {
610- data = ReadStream ( GetStream ( entryName , readSource ) ) ;
611+ using Stream stream = GetStream ( entryName , readSource ) ;
612+ data = ReadStream ( stream ) ;
611613
612614 _ = CacheEntry ( entryName , data ) ;
613615 }
@@ -639,19 +641,19 @@ public Stream GetStream(string entryName, ReadSource readSource = ReadSource.Bot
639641 {
640642 Logger . LogDebug ( "Entry {name} not found in cache" , entryName ) ;
641643 }
642-
643- Stream stream ;
644-
644+
645645 if ( ! CheckEntryNameSecurity ( entryName , false ) )
646646 {
647647 readSource = ReadSource . Bundle ;
648648 }
649649
650+ Stream stream ;
651+
650652 if ( readSource != ReadSource . Disk && ( readSource == ReadSource . Bundle || Manifest . StoreOriginalFiles ) )
651653 {
652654 Logger . LogDebug ( "Reading file: {name} from the bundle" , entryName ) ;
653655
654- using ZipArchive zip = GetZipArchive ( ) ;
656+ ZipArchive zip = GetZipArchive ( ) ;
655657
656658 ZipArchiveEntry entry = zip . GetEntry ( entryName ) ?? throw new FileNotFoundException ( "Entry not found" , entryName ) ;
657659 stream = entry . Open ( ) ;
@@ -664,11 +666,6 @@ public Stream GetStream(string entryName, ReadSource readSource = ReadSource.Bot
664666 stream = File . OpenRead ( path ) ;
665667 }
666668
667- if ( ReadOnly && stream . Length < _maxCacheSize )
668- {
669- _ = CacheEntry ( entryName , ReadStream ( stream ) ) ;
670- }
671-
672669 return stream ;
673670 }
674671
@@ -814,10 +811,6 @@ protected static byte[] ReadStream(Stream stream)
814811 {
815812 Ensure . Any . IsNotNull ( stream , nameof ( stream ) ) ;
816813
817- if ( stream . Length > int . MaxValue )
818- {
819- throw new OverflowException ( "Stream length is too big for buffering" ) ;
820- }
821814
822815 byte [ ] result ;
823816 if ( stream is MemoryStream memoryStream )
0 commit comments