Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/SharpCompress/Archives/Tar/TarArchive.Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ public static bool IsTarFile(Stream stream)
&& Enum.IsDefined(typeof(EntryType), tarHeader.EntryType);
return readSucceeded || isEmptyArchive;
}
catch { }
return false;
catch (Exception)
{
// Catch all exceptions during tar header reading to determine if this is a valid tar file
// Invalid tar files or corrupted streams will throw various exceptions
return false;
}
}

public static async ValueTask<bool> IsTarFileAsync(
Expand All @@ -182,8 +186,12 @@ public static async ValueTask<bool> IsTarFileAsync(
&& Enum.IsDefined(typeof(EntryType), tarHeader.EntryType);
return readSucceeded || isEmptyArchive;
}
catch { }
return false;
catch (Exception)
{
// Catch all exceptions during tar header reading to determine if this is a valid tar file
// Invalid tar files or corrupted streams will throw various exceptions
return false;
}
}

public static IWritableArchive CreateArchive() => new TarArchive();
Expand Down