Skip to content

Commit ea4d2a1

Browse files
Copilotgfs
andcommitted
Fix ZipExtractor to dispose backing stream and skip failed entries
Co-authored-by: gfs <98900+gfs@users.noreply.github.com>
1 parent 2b2a9c2 commit ea4d2a1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

RecursiveExtractor/Extractors/ZipExtractor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ public async IAsyncEnumerable<FileEntry> ExtractAsync(FileEntry fileEntry, Extra
136136
catch (Exception e)
137137
{
138138
Logger.Debug(Extractor.FAILED_PARSING_ERROR_MESSAGE_STRING, ArchiveFileType.ZIP, fileEntry.FullPath, zipEntry.Key, e.GetType());
139+
target?.Dispose();
140+
continue;
139141
}
140142

141-
target ??= new MemoryStream();
142143
var name = zipEntry.Key?.Replace('/', Path.DirectorySeparatorChar) ?? "";
143144
var newFileEntry = new FileEntry(name, target, fileEntry, modifyTime: zipEntry.LastModifiedTime, memoryStreamCutoff: options.MemoryStreamCutoff);
144145

@@ -222,7 +223,7 @@ public IEnumerable<FileEntry> Extract(FileEntry fileEntry, ExtractorOptions opti
222223
{
223224
governor.CheckResourceGovernor(zipEntry.Size);
224225

225-
using var fs = StreamFactory.GenerateAppropriateBackingStream(options, zipEntry.Size);
226+
var fs = StreamFactory.GenerateAppropriateBackingStream(options, zipEntry.Size);
226227

227228
try
228229
{
@@ -232,6 +233,8 @@ public IEnumerable<FileEntry> Extract(FileEntry fileEntry, ExtractorOptions opti
232233
catch (Exception e)
233234
{
234235
Logger.Debug(Extractor.FAILED_PARSING_ERROR_MESSAGE_STRING, ArchiveFileType.ZIP, fileEntry.FullPath, zipEntry.Key, e.GetType());
236+
fs?.Dispose();
237+
continue;
235238
}
236239

237240
var name = zipEntry.Key?.Replace('/', Path.DirectorySeparatorChar) ?? "";

0 commit comments

Comments
 (0)