Commit Graph

20 Commits

Author SHA1 Message Date
Fidel
de8ee30b17 BZip2: add opt-in tolerateTruncatedStream to decode a footerless/partial stream
Add a `tolerateTruncatedStream` option (default false) to `BZip2Stream.Create`/`CreateAsync`,
threaded through to `CBZip2InputStream`. When enabled, the decoder accepts a stream that has no
trailing footer - e.g. a truncated stream, or a sub-range of blocks extracted for random access:

- An end-of-input reached while reading a block/footer header (a true block boundary, tracked by
  `expectingBlockStart`) is treated as a normal end of stream instead of throwing
  `ArchiveOperationException("BZip2 compressed file ends unexpectedly")`. EOF in the middle of a
  block, the block CRC, or the Huffman tables still throws.
- The whole-stream combined CRC in the footer is not verified, since a partial decode's running
  combined CRC won't match the stored whole-stream value. Per-block CRCs are still enforced.

Default behaviour is unchanged (the flag defaults to false) and the change is applied symmetrically
to the sync and async read paths.

Tests (BZip2StreamTests):
- a footerless header-only stream decodes to empty with the flag and throws without it;
- a real block followed by end-of-input at the next block boundary decodes with the flag and throws
  without it;
- a corrupted whole-stream combined CRC is tolerated with the flag and fatal without it;
- a complete, well-formed stream still round-trips with the flag set.
All existing BZip2 tests continue to pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 13:08:02 +10:00
Adam Hathcock
808524d917 BZip2, GZip and XZ done 2026-06-15 09:59:48 +01:00
Adam Hathcock
25a5b7beeb BZip2 fixed? 2026-05-05 08:19:55 +01:00
copilot-swe-agent[bot]
698257de29 Fix async-only stream violations: defer sync writes to async paths in writers and compressors
Agent-Logs-Url: https://github.com/adamhathcock/sharpcompress/sessions/6e4dec7d-12cd-4044-9935-4d354b911d11

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
2026-04-28 10:24:36 +00:00
Adam Hathcock
855d4b4ce2 Use more SC exceptions instead of generic ones 2026-02-16 12:40:07 +00:00
Adam Hathcock
4ab03c0093 fixed more 2026-02-16 09:27:06 +00:00
Adam Hathcock
c5814502f6 clean up and fixing tests....need to revisit disposal 2026-01-22 16:24:07 +00:00
Adam Hathcock
5152e3197e fix build flags 2026-01-22 15:12:18 +00:00
Adam Hathcock
895699d22e fmt 2026-01-20 16:53:08 +00:00
Adam Hathcock
cf901c2784 fix test 2026-01-20 16:44:34 +00:00
Adam Hathcock
a8d5b8e86b intermediate commit 2026-01-20 15:19:46 +00:00
Adam Hathcock
0a9c5bfe15 format changes 2026-01-20 13:40:51 +00:00
Adam Hathcock
ff0769e988 Create factory for CBZip2InputStream 2026-01-20 13:21:11 +00:00
Adam Hathcock
ec310c87de merge fixes and fmt 2026-01-15 15:20:52 +00:00
Adam Hathcock
c55a383112 Merge remote-tracking branch 'origin/master' into adam/async-again
# Conflicts:
#	tests/SharpCompress.Test/GZip/GZipReaderAsyncTests.cs
#	tests/SharpCompress.Test/Rar/RarArchiveAsyncTests.cs
#	tests/SharpCompress.Test/SevenZip/SevenZipArchiveAsyncTests.cs
#	tests/SharpCompress.Test/Tar/TarArchiveAsyncTests.cs
#	tests/SharpCompress.Test/Tar/TarReaderAsyncTests.cs
#	tests/SharpCompress.Test/Zip/Zip64AsyncTests.cs
#	tests/SharpCompress.Test/Zip/ZipMemoryArchiveWithCrcAsyncTests.cs
2026-01-15 15:18:05 +00:00
Adam Hathcock
7b76858ae1 refactoring naming again 2026-01-15 11:41:30 +00:00
Adam Hathcock
84b5b5a717 add more tests 2026-01-14 14:33:20 +00:00
Adam Hathcock
3747a27109 Task to ValueTask 2026-01-08 12:35:12 +00:00
Adam Hathcock
ccc8587e5f review fixes 2025-10-31 10:55:33 +00:00
Lars Vahlenberg
33dd519f56 Throw exception when bzip2 is corrupt 2024-06-08 18:26:12 +02:00