Skip to content

Fix codec correctness, add strong naming, and improve inflate performance - #12

Merged
cinderblocks merged 14 commits into
cinderblocks:masterfrom
jogibear9988:fix/codec-correctness-and-signing
Nov 1, 2026
Merged

cinderblocks merged 14 commits into
cinderblocks:masterfrom
jogibear9988:fix/codec-correctness-and-signing

Conversation

@jogibear9988

Copy link
Copy Markdown
Contributor

Valid zlib data followed by extra bytes could hang ZOutputStream, malformed history references could silently produce zero bytes, some raw DEFLATE streams needed a dummy byte, and output finalization could hide failures. This PR fixes those cases with regression tests and adds the requested strong naming and larger output buffer.

Changes are split into 14 commits:

  • Track completion, require codec progress, reject trailing data consistently across writes/Span/Memory, and make Finish idempotent.
  • Propagate finalization failures while always releasing resources; validate levels and write arguments before mutating codec state.
  • Check initialized history in both inflate paths, including dictionaries and stored/window-wrapped data.
  • Apply the terminal Huffman lookup correction described in SharpCompress #118 to both LEN and DIST.
  • Repair inflateSync recovery for buffered marker bytes, wrapped trailers, and input split across calls.
  • Interleave three-byte encoder symbols so pending output cannot overwrite unread symbols. An adversarial fixed-tree test failed before this change; golden compressed-output tests still pass. This tests an internal buffer invariant and is not a claim of a demonstrated public-API CVE.
  • Replace overlapping match byte loops with bounded bulk expansion, checked against an independent bytewise oracle including wraparound.
  • Raise the default output buffer from 4 KB to 16 KB and add constructors for explicit buffer sizes.
  • Fully strong-name sign all library targets and friend assemblies using a stable checked-in source-distribution key (token d3655c1a090d0873). Related to strong name support #11 and Add strong naming support #10.
  • Compare successful fuzz decodes against platform zlib and add audit regression seeds.
  • Document ComponentAce → JCraft/JZlib → zlib 1.1.3 provenance, clarify the inherited version string, and include third-party notices in the package.

Compatibility

Disposal now reports finalization errors. Decompression-mode ZOutputStream rejects trailing bytes/members with ZStreamException, including across write boundaries. Compression writes after completion throw InvalidOperationException. Signing changes assembly identity; consumers should rebuild. These behaviors are documented in the README. The package version is unchanged; no release/tag or NuGet publication is included.

Validation

Windows ARM64 / .NET 8.0.28:

  • net8.0 library: 255 tests passed.
  • netstandard2.1 library on net8.0: 255 tests passed.
  • netstandard2.0 library on net8.0: 226 tests passed.
  • netstandard2.0 library on net48: 209 tests passed.
  • Fuzz corpus replay: 40 inflate and 36 roundtrip inputs passed.
  • Release package and symbols built; all three library signatures verified with sn -vf, plus signature verification tests.
  • BenchmarkDotNet smoke run: all six output-buffer scenarios executed.
  • Local warmed diagnostic measurements at a fixed 16 KB output buffer: 4 MiB zero-data inflate decreased from ~5.44 ms to ~0.97 ms after bulk match copying; structured text decreased from ~2.06 ms to ~1.90 ms. These are directional measurements on one machine, not cross-platform performance guarantees.
  • git diff --check passes; working tree is clean.

Long-running AFL++ fuzzing and Linux/macOS execution were not run locally; the existing CI workflows cover those platforms and scheduled fuzzing.

@cinderblocks
cinderblocks merged commit 8d41e1c into cinderblocks:master Nov 1, 2026
5 of 6 checks passed
@cinderblocks

Copy link
Copy Markdown
Owner

You rock. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants