Skip to content

fix(PFSCReader): read each compressed sector fully - #27

Open
skippdot wants to merge 1 commit into
OpenOrbis:masterfrom
skippdot:pr/pfsc-reader-partial-read
Open

skippdot wants to merge 1 commit into
OpenOrbis:masterfrom
skippdot:pr/pfsc-reader-partial-read

Conversation

@skippdot

@skippdot skippdot commented Oct 6, 2026

Copy link
Copy Markdown

PFSCReader.ReadSector decompresses a sector with a single DeflateStream.Read(output, 0, BlockSz). Since .NET 6, DeflateStream.Read returns as soon as some output is available, so it can return less than a full 64 KiB sector. The rest of output then keeps whatever the previous sector left there, and files extracted from compressed (PFSC) packages are silently corrupted.

In practice this hit most files of real fake packages (e.g. 147 of 204 files of one game's base package differed from an independent zlib decode).

Fix: loop until the sector is full; zero any remainder if the stream ends early.

Test: PfscReaderTests.PfscReader_DecompressesMixedBlocksExactly builds a PFSC image with mixed raw/zlib blocks and compares the decoded data. It fails on master (first mismatch at byte 36173) and passes with the fix.

Possibly related: #18 (bad sectors while reading compressed images).

A single Read can return a partial sector on .NET 6+, which silently corrupted most files extracted from compressed (PFSC) packages; the rest of the sector kept stale data from the previous one.
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