Compare commits

...

5 Commits

Author SHA1 Message Date
Adam Hathcock
4aa98aa3e2 run CI on release branch 2025-12-08 11:12:38 +00:00
Adam Hathcock
41c4263a66 Merge pull request #1067 from adamhathcock/adam/fix-arj-factory
Fix: Should not throw on ARJ detection
2025-12-08 11:04:24 +00:00
Adam Hathcock
2215d60394 Update tests/SharpCompress.Test/ArchiveTests.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-08 10:50:39 +00:00
Adam Hathcock
a8c33ab729 mark for 0.42.1 2025-12-08 10:50:07 +00:00
Adam Hathcock
eede5aa9cc Should not throw on ARJ detection 2025-12-08 10:45:50 +00:00
4 changed files with 41 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ on:
push:
branches:
- 'master'
- 'release'
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]

View File

@@ -28,12 +28,19 @@ namespace SharpCompress.Factories
int bufferSize = ReaderOptions.DefaultBufferSize
)
{
var arjHeader = new ArjMainHeader(new ArchiveEncoding());
if (arjHeader.Read(stream) == null)
try
{
var arjHeader = new ArjMainHeader(new ArchiveEncoding());
if (arjHeader.Read(stream) == null)
{
return false;
}
return true;
}
catch
{
return false;
}
return true;
}
public IReader OpenReader(Stream stream, ReaderOptions? options) =>

View File

@@ -2,9 +2,9 @@
<PropertyGroup>
<AssemblyTitle>SharpCompress - Pure C# Decompression/Compression</AssemblyTitle>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>0.42.0</VersionPrefix>
<AssemblyVersion>0.42.0</AssemblyVersion>
<FileVersion>0.42.0</FileVersion>
<VersionPrefix>0.42.1</VersionPrefix>
<AssemblyVersion>0.42.1</AssemblyVersion>
<FileVersion>0.42.1</FileVersion>
<Authors>Adam Hathcock</Authors>
<TargetFrameworks>net48;net481;netstandard2.0;net6.0;net8.0</TargetFrameworks>
<AssemblyName>SharpCompress</AssemblyName>

View File

@@ -654,4 +654,31 @@ public class ArchiveTests : ReaderTests
Assert.Equal(3, archive.Entries.Count());
}
}
[Fact]
public void ArchiveFactory_IsArchive_NonArchiveFile_ShouldReturnFalse()
{
// Test that ArchiveFactory.IsArchive returns false instead of throwing
// when called on a non-archive file (regression test for issue #1064)
using (var stream = new MemoryStream(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 }))
{
var result = ArchiveFactory.IsArchive(stream, out var type);
Assert.False(result);
Assert.Null(type);
}
}
[Fact]
public void ArchiveFactory_IsArchive_ValidArchive_ShouldReturnTrue()
{
// Test that ArchiveFactory.IsArchive correctly identifies valid archives
var testArchive = Path.Combine(TEST_ARCHIVES_PATH, "Zip.bzip2.noEmptyDirs.zip");
using (var stream = File.OpenRead(testArchive))
{
var result = ArchiveFactory.IsArchive(stream, out var type);
Assert.True(result);
Assert.Equal(ArchiveType.Zip, type);
}
}
}