Skip to content

* Decode bzip2 pages in BitRock installers - #400

Merged
Hawkynt merged 2 commits into
mainfrom
feat/bitrock-bzip2-cookfs-pages
Sep 30, 2026
Merged

Hawkynt merged 2 commits into
mainfrom
feat/bitrock-bzip2-cookfs-pages

Conversation

@Hawkynt

@Hawkynt Hawkynt commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

What changed

BitRock's cookfs (CFS0002) content reader handled stored and raw-DEFLATE pages and rejected compression id 2. This adds bzip2 pages.

In a CFS0002 bzip2 page the uncompressed size comes first, as a big-endian u32, followed by the bzip2 stream: libbz2's buffer API needs the output size, and the CFS0002 index doesn't record it. The first revision of this PR decoded from byte 0 and built its fixture the same way, so the test passed while real pages would fail. The reader now skips the prefix and checks it. A page too short for the prefix, or one that decodes to a different length, is rejected.

Sourcing

Rung 1 used as a specification: the BSD-licensed cookfs 1.x sources (generic/pagesCompr.c, CookfsReadPageBz2 / CookfsWritePageBz2, tag v1.4.0 of github.com/chpock/cookfs). No code was copied. Decoding uses the repository's managed BZip2 stream.

Verification

  • Byte-exact reconstruction across many pages with a short tail, a single byte, and exactly one page.
  • Rejection of a page without the prefix, a page shorter than the prefix, and prefixes off by -1 and +1.
  • dotnet test --filter Compression.Tests.BitRock: 15 passed.
  • The corpus has no InstallBuilder sample with bzip2 pages, so this path is pinned by fixtures built to the cookfs layout. FORMAT-NOTES.md says so.

BitRock stays read-only.

@Hawkynt
Hawkynt force-pushed the feat/bitrock-bzip2-cookfs-pages branch 3 times, most recently from 43653e3 to 1870474 Compare September 30, 2026 16:06
InstallBuilder content reconstruction rejects cookfs pages with compression id 2 even though the embedded Cookfs format supports bz2 pages. Decode each page with the managed BZip2 stream and cover it with a multi-page byte-exact fixture. Creation is still unavailable because a valid installer requires the vendor runtime stub.
… bzip2 stream

A CFS0002 bzip2 page is [u32 BE uncompressed size][bzip2 stream], but the
reader handed the whole page to the bzip2 decoder, so a real page fails on
its first four bytes. The fixture was built to the same wrong layout, which
is why the round-trip test passed.

Layout taken from the BSD-licensed cookfs 1.4 sources (CookfsReadPageBz2 /
CookfsWritePageBz2, rung 1 as specification; no code copied). The reader now
skips and checks the prefix: a page too short for it, or one whose stream
decodes to a different length, is rejected. Fixtures follow the cookfs
layout; the notes no longer claim bzip2 InstallBuilder samples were seen.
@Hawkynt
Hawkynt force-pushed the feat/bitrock-bzip2-cookfs-pages branch from 4a4ac51 to eef0eb5 Compare September 30, 2026 18:03
@Hawkynt
Hawkynt merged commit f190b47 into main Sep 30, 2026
5 of 7 checks passed
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.

1 participant