Honor explicit NUP compression for .zs members #456

Merged
klimovich008 merged 1 commit from codex/nup-explicit-codec into main 2026-11-08 08:19:57 +00:00
klimovich008 commented 2026-11-08 03:45:06 +00:00 (Migrated from github.com)

What this fixes

Extracting a NUP can silently corrupt .zs textures while producing files of the expected size. This happens when the package compresses a member whose decoded payload is not another Zstd frame.

Why merge

  • Honor the explicit compression codec before guessing from the filename or payload.
  • Keep reads inside the stored extent and reject incomplete frames; retain the decoded-size check.
  • Preserve legacy compression detection and existing extraction paths.

Change

  • nx2/nup.py: read the codec byte, use it to select package decompression and enforce its stored extent.
  • nx2/test_nup_codec.py: check compressed .zs plaintext, raw game Zstd, legacy detection and a truncated extent.

Tested

  • python -I -B nx2/test_nup_codec.py exercises the actual constructor and copy routine using synthetic packages.
  • Fails on the old code, passes now.
  • Windows: a fresh extraction of 186,587 members has three incorrect hashes before the fix and zero afterward.
  • Existing source checks pass in Windows and Linux CI; the AppImage build passes.

Not covered

  • Existing same-size cached files are reused; extract into a fresh folder to repair them.
  • Runtime use of the three affected textures has not been tested.

No game data is included.

## What this fixes Extracting a NUP can silently corrupt `.zs` textures while producing files of the expected size. This happens when the package compresses a member whose decoded payload is not another Zstd frame. ## Why merge - Honor the explicit compression codec before guessing from the filename or payload. - Keep reads inside the stored extent and reject incomplete frames; retain the decoded-size check. - Preserve legacy compression detection and existing extraction paths. ## Change - `nx2/nup.py`: read the codec byte, use it to select package decompression and enforce its stored extent. - `nx2/test_nup_codec.py`: check compressed `.zs` plaintext, raw game Zstd, legacy detection and a truncated extent. ## Tested - `python -I -B nx2/test_nup_codec.py` exercises the actual constructor and copy routine using synthetic packages. - Fails on the old code, passes now. - Windows: a fresh extraction of 186,587 members has three incorrect hashes before the fix and zero afterward. - Existing source checks pass in Windows and Linux CI; the AppImage build passes. ## Not covered - Existing same-size cached files are reused; extract into a fresh folder to repair them. - Runtime use of the three affected textures has not been tested. No game data is included.
Commenting is not possible because the repository is archived.
No description provided.