Skip to content

Fix legacy pak compression method mapping - #62

Open
gravenuance wants to merge 1 commit into
trumank:masterfrom
gravenuance:pr/legacy-compression-flags
Open

gravenuance wants to merge 1 commit into
trumank:masterfrom
gravenuance:pr/legacy-compression-flags

Conversation

@gravenuance

Copy link
Copy Markdown

Paks older than FNameBasedCompression (UE < 4.22) store no compression method names. There the entry's compression field is an ECompressionFlags value: 0x01 ZLIB, 0x02 GZIP, 0x04 COMPRESS_Custom. Entry::read turns it into slot flag - 1, but the hardcoded fallback list was [Zlib, Gzip, Oodle]. As a result:

  • an entry using COMPRESS_Custom (slot 3) indexes past the end of the list and panics;
  • writing Oodle to a legacy pak stores 0x03 (ZLIB|GZIP).

This sets the list to [Zlib, Gzip, None, Oodle] for both reading and writing, and returns an error instead of panicking when an entry's slot is out of range.

Found on Days Gone (UE 4.17): only the values 0 and 4 appear in its 216,747 entries, and the 0x04 blocks decompress correctly as Oodle. COMPRESS_Custom is game-defined, but Oodle is the common case.

Tests: footer and Pak::new slot lists, plus an out-of-range slot that now errors instead of panicking. All three fail without the change. cargo test and cargo fmt --check pass. test_readme_help fails on Windows with and without this change (repak.exe in the usage line).

Risk: legacy paks whose custom codec isn't Oodle still fail, now with a decompression error.

Paks older than FNameBasedCompression store no compression method names;
the entry's compression field is an ECompressionFlags value (0x01 ZLIB,
0x02 GZIP, 0x04 COMPRESS_Custom), so slot = flag - 1. The fallback list
put Oodle at slot 2 (flag 0x03), so COMPRESS_Custom entries (slot 3)
indexed past the end of the list and panicked, and writing Oodle to a
legacy pak stored flag 0x03.

Use Zlib, Gzip, None, Oodle for both reading and writing, and return an
error instead of panicking when an entry's slot is out of range.
gravenuance added a commit to gravenuance/repak that referenced this pull request Nov 4, 2026
11fa9fa described slot = ECompressionFlags - 1 with a None hole at 0x03 and
Oodle at 0x04, but the footer pushed Zlib, Gzip, Oodle, Zstd, so 0x03 read
as Oodle and COMPRESS_Custom (0x04) as Zstd, and Pak::new kept the old
three-entry list, so writing Oodle to a legacy pak stored 0x03. Days Gone's
0x04 blocks are Oodle.

Use one list, Zlib, Gzip, None, Oodle, for reading and writing, as on
pr/legacy-compression-flags (trumank#62). The raw-block Zstd fallback
stays for paks whose names say Zstd.
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