dstorage: name a damaged archive instead of a bare zlib error #3387

Open
github-bot wants to merge 1 commit from github-bot/gh-3387 into main AGit
Owner

@⁠suluojin-ui on GitHub · 2026-11-29 22:39 UTC · original
suluojin-ui:diag-damaged-archive → main · +59 −2 · 1 files · 1 commits · open

The two zlib paths in dstorage already return ERROR_INVALID_DATA when the bytes at an offset the archive's own table named are not a zlib stream. Nothing says why. On a machine whose extraction was incomplete this showed up as a title stopping at +0x4da6315, with two requests refused four milliseconds earlier and nothing but hr=0x8007000d to go on (#3335).

This adds one check on the failing path only, and changes no behaviour that succeeds:

  • starts_a_zlib_stream implements RFC 1950's header test — compression method 8 and (CMF << 8 | FLG) % 31 == 0 — rather than comparing against a literal 0x78, so valid streams with a smaller window are not misreported.
  • note_damaged_archive fires only when the result is ERROR_INVALID_DATA and the source does not begin a zlib stream. It logs once per (path, offset) through a OnceLock<Mutex<BTreeSet<..>>>, so a run that refuses the same block a hundred times names that archive once.
  • Both map_err sites call it. inflate, the destination closure and the success paths are untouched.

The message is:

dstorage: an archive is damaged: the block named at this offset does not start a zlib stream, so the package was not extracted completely; re-extract it

with path, offset and the first two bytes as fields.

Checked with cargo check -p victory-hle and cargo test -p victory-hle dstorage (30 passed, 2 ignored, 0 failed).

Why this is worth a line rather than a fix: the offset comes from the archive's own table, so a mismatch between the table and the bytes is a statement about the file, not about the loader. Saying it once turns a silent ERROR_INVALID_DATA into the one thing a user can act on.

**@⁠suluojin-ui** on GitHub · 2026-11-29 22:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3387) `suluojin-ui:diag-damaged-archive` → `main` · +59 −2 · 1 files · 1 commits · open The two zlib paths in `dstorage` already return `ERROR_INVALID_DATA` when the bytes at an offset the archive's own table named are not a zlib stream. Nothing says why. On a machine whose extraction was incomplete this showed up as a title stopping at `+0x4da6315`, with two requests refused four milliseconds earlier and nothing but `hr=0x8007000d` to go on (#3335). This adds one check on the failing path only, and changes no behaviour that succeeds: - `starts_a_zlib_stream` implements RFC 1950's header test — compression method `8` and `(CMF << 8 | FLG) % 31 == 0` — rather than comparing against a literal `0x78`, so valid streams with a smaller window are not misreported. - `note_damaged_archive` fires only when the result is `ERROR_INVALID_DATA` *and* the source does not begin a zlib stream. It logs once per `(path, offset)` through a `OnceLock<Mutex<BTreeSet<..>>>`, so a run that refuses the same block a hundred times names that archive once. - Both `map_err` sites call it. `inflate`, the destination closure and the success paths are untouched. The message is: ``` dstorage: an archive is damaged: the block named at this offset does not start a zlib stream, so the package was not extracted completely; re-extract it ``` with `path`, `offset` and the first two bytes as fields. Checked with `cargo check -p victory-hle` and `cargo test -p victory-hle dstorage` (30 passed, 2 ignored, 0 failed). Why this is worth a line rather than a fix: the offset comes from the archive's own table, so a mismatch between the table and the bytes is a statement about the file, not about the loader. Saying it once turns a silent `ERROR_INVALID_DATA` into the one thing a user can act on.
A package extracted short, resumed or out of order keeps its size but shifts
blocks against the archive's own table; zlib then returns INVALID_DATA for a
block that is not there, and the title stops at its own breakpoint with nothing
naming the file (#3335). Say so once per archive and offset, at error level,
with the path, the offset and the two bytes found there; the failure line and
the request's outcome are unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 22:40:38 +00:00
Author
Owner

@⁠babuakhil on GitHub · 2026-11-30 18:05 UTC · original

Checked on Windows 11 (Rust 1.98.1, pinned), applied on current main (84bd61e2); cherry-picks cleanly. cargo test -p victory-hle --lib dstorage gives 38 passed, 0 failed, including the new header test. Clippy on victory-hle stops in victory-gpu (ranged never used), which is on main too. Not tested in the game.

One correction to the description first: main already names the file. Since 96270e51 (also in this PR's base), every failed request goes through fail, which logs path, offset, the sizes and hr with "dstorage: request failed: zlib". So what this adds is the diagnosis, not the file name.

I ran execute directly with a tracing subscriber capturing WARN and up, on both, from a throwaway test (not part of this PR):

request result (both) main logs this PR logs
intact zlib block from a file ok nothing nothing
block that doesn't start a zlib stream, from a file ERROR_INVALID_DATA WARN request failed, with path ERROR "archive is damaged … re-extract it", path, offset, first=74 68 + the same WARN
the same request again ERROR_INVALID_DATA WARN WARN only (once per path and offset, as described)
zlib header intact, body damaged ERROR_INVALID_DATA WARN WARN only, no "damaged" line
block that doesn't start a zlib stream, memory source ERROR_INVALID_DATA WARN, path="" ERROR "archive is damaged … re-extract it" with path="" + WARN

So it does what it says for a file whose table and bytes disagree, and changes no result. Two suggestions:

  • Memory sources. With MEMORY_SOURCE the bytes came from title memory, not a package on disk, so "the package was not extracted completely; re-extract it" sends the user the wrong way, and the line names no file. Returning early when source_path(request) is empty (or the option is set) would keep the message to files.
  • The wording is more certain than the check. A block whose first two bytes aren't a zlib header is what a short extraction looks like, but a wrong offset or file on our side would look the same. Something like "the bytes at this offset are not a zlib stream: the package may be damaged or incompletely extracted" would point users the same way without ruling that out. A damaged body behind a good header isn't caught, which seems fine for a check this cheap, but it could say so in the doc comment.
**@⁠babuakhil** on GitHub · 2026-11-30 18:05 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3387#issuecomment-7287325604) Checked on Windows 11 (Rust 1.98.1, pinned), applied on current `main` (`84bd61e2`); cherry-picks cleanly. `cargo test -p victory-hle --lib dstorage` gives 38 passed, 0 failed, including the new header test. Clippy on `victory-hle` stops in `victory-gpu` (`ranged` never used), which is on `main` too. Not tested in the game. One correction to the description first: `main` already names the file. Since 96270e51 (also in this PR's base), every failed request goes through `fail`, which logs `path`, `offset`, the sizes and `hr` with "dstorage: request failed: zlib". So what this adds is the diagnosis, not the file name. I ran `execute` directly with a tracing subscriber capturing WARN and up, on both, from a throwaway test (not part of this PR): | request | result (both) | `main` logs | this PR logs | |---|---|---|---| | intact zlib block from a file | ok | nothing | nothing | | block that doesn't start a zlib stream, from a file | `ERROR_INVALID_DATA` | WARN request failed, with path | **ERROR "archive is damaged … re-extract it", path, offset, `first=74 68`** + the same WARN | | the same request again | `ERROR_INVALID_DATA` | WARN | WARN only (once per path and offset, as described) | | zlib header intact, body damaged | `ERROR_INVALID_DATA` | WARN | WARN only, no "damaged" line | | block that doesn't start a zlib stream, **memory source** | `ERROR_INVALID_DATA` | WARN, `path=""` | **ERROR "archive is damaged … re-extract it" with `path=""`** + WARN | So it does what it says for a file whose table and bytes disagree, and changes no result. Two suggestions: - **Memory sources.** With `MEMORY_SOURCE` the bytes came from title memory, not a package on disk, so "the package was not extracted completely; re-extract it" sends the user the wrong way, and the line names no file. Returning early when `source_path(request)` is empty (or the option is set) would keep the message to files. - **The wording is more certain than the check.** A block whose first two bytes aren't a zlib header is what a short extraction looks like, but a wrong offset or file on our side would look the same. Something like "the bytes at this offset are not a zlib stream: the package may be damaged or incompletely extracted" would point users the same way without ruling that out. A damaged body behind a good header isn't caught, which seems fine for a check this cheap, but it could say so in the doc comment.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3387/head:github-bot/gh-3387'
git switch 'github-bot/gh-3387'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3387'
git switch 'github-bot/gh-3387'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3387'
git switch 'github-bot/gh-3387'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3387'
git switch 'main'
git merge --squash 'github-bot/gh-3387'
git switch 'main'
git merge --ff-only 'github-bot/gh-3387'
git switch 'main'
git merge 'github-bot/gh-3387'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3387
No description provided.