Allow partial reads in ACE signature detection

This commit is contained in:
Adam Hathcock
2026-10-10 15:40:35 +01:00
parent d01539ae3c
commit b442327e5f
2 changed files with 22 additions and 1 deletions

View File

@@ -100,7 +100,7 @@ public abstract partial class AceHeader
// First two bytes are typically 0x60 0xEA (signature bytes)
// At offset 7, there should be "**ACE**" (7 bytes)
var bytes = new byte[14];
if (stream.Read(bytes, 0, 14) != 14)
if (!stream.ReadFully(bytes))
{
return false;
}

View File

@@ -0,0 +1,21 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using SharpCompress.Common.Ace.Headers;
using SharpCompress.Test.Mocks;
using Xunit;
namespace SharpCompress.Test.Ace;
public class AceHeaderReadTests
{
[Fact]
public async Task Ace_Signature_Allows_Partial_Reads()
{
byte[] header = [0, 0, 0, 0, 0, 0, 0, 42, 42, 65, 67, 69, 42, 42];
using var sync = new ShortReadStream(new MemoryStream(header));
using var asyncInput = new ShortReadStream(new MemoryStream(header));
Assert.True(AceHeader.IsArchive(sync));
Assert.True(await AceHeader.IsArchiveAsync(asyncInput, CancellationToken.None));
}
}