Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PFSCReader.ReadSectordecompresses a sector with a singleDeflateStream.Read(output, 0, BlockSz). Since .NET 6,DeflateStream.Readreturns as soon as some output is available, so it can return less than a full 64 KiB sector. The rest ofoutputthen 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_DecompressesMixedBlocksExactlybuilds 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).