Skip to content

Commit

Permalink
Merge pull request #850 from Erior/feature/Issue-842
Browse files Browse the repository at this point in the history
Issue 842
  • Loading branch information
adamhathcock authored Jun 18, 2024
2 parents 4e4e89b + a767219 commit 3eaac68
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/SharpCompress/Compressors/BZip2/CBZip2InputStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable disable
#nullable disable

using System;
using System.IO;
Expand Down Expand Up @@ -42,14 +42,17 @@ internal class CBZip2InputStream : Stream
private static void Cadvise()
{
//System.out.Println("CRC Error");
//throw new CCoruptionError();
throw new InvalidOperationException("BZip2 error");
}

private static void BadBGLengths() => Cadvise();

private static void BitStreamEOF() => Cadvise();

private static void CompressedStreamEOF() => Cadvise();
private static void CompressedStreamEOF()
{
throw new InvalidOperationException("BZip2 compressed file ends unexpectedly");
}

private void MakeMaps()
{
Expand Down
21 changes: 21 additions & 0 deletions tests/SharpCompress.Test/BZip2/BZip2ReaderTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.IO;
using SharpCompress.Common;
using SharpCompress.IO;
using SharpCompress.Readers;
using SharpCompress.Readers.GZip;
using Xunit;

namespace SharpCompress.Test.BZip2;

public class BZip2ReaderTests : ReaderTests
{
[Fact]
public void BZip2_Reader_Factory()
{
Stream stream = new MemoryStream(
new byte[] { 0x42, 0x5a, 0x68, 0x34, 0x31, 0x41, 0x59, 0x26, 0x53, 0x59, 0x35 }
);
Assert.Throws(typeof(InvalidOperationException), () => ReaderFactory.Open(stream));
}
}

0 comments on commit 3eaac68

Please sign in to comment.