SGD5: a marker inside a record's packed bytes is not another record #273

Closed
SkippySteve wants to merge 72 commits from upstream-pr/273 into main
SkippySteve commented 2026-11-24 01:58:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T01:58:42Z.


sgd5::records matched every 0x000DDCE7 marker in the file, including ones inside an already-found record's packed bytes. Deflate stored blocks carry the container's bytes as they are, so a container that holds a record-shaped run of bytes was reported as an extra record (and the shader CLI would try to unpack it).

The search now resumes after each record's packed bytes. A marker that does not form a record still advances by one byte, as before.

Game tests: every known build's hash is one identify() can match (was #303)

KNOWN_BUILDS is matched against the hex BLAKE3 that run.rs computes, so an entry with a typo, a truncated hash, stray whitespace or a duplicate would silently never identify the build it names. Three tests in crates/victory-game/src/lib.rs check that each entry is 64 lowercase hex digits with unique label and hash, that identify() finds each build by its own hash in either case, and that an unknown digest, an empty string or non-hex text identifies nothing. The list is empty today, so the first two guard future entries. Test-only; no game data.

This PR now carries #303, which is closed in its favour.

A record's header cannot sit inside the previous record

After a record, the search resumed right at the end of its packed bytes, so a marker found there read its NUL, kind and n from the last bytes of the previous record (and its name from further back). Bytes after the end of a deflate stream are not checked, so this produced a phantom record. The search now starts 6 bytes after the previous record (or the magic), and a record's header and name are read only from bytes after it.

  • New header_inside_a_record_is_not_another_record: before [Some("PS_first"), None], after [Some("PS_first")].
  • New empty_container_unpacks and damaged_file_yields_disjoint_records (every single-byte change to a two-record file, 8 values each: no panic, records in order, inside the file, not overlapping).

The shader survey does not count a stored container twice

Deflate stored blocks carry a record's container as it is, so victory shader's raw DXBC scan (apps/victory/src/shader.rs, sources) found it inside the record's packed bytes and counted it again, next to the unpacked record. sgd5::Record::span (marker to end of packed stream) and sgd5::in_record (binary search over the records, which are in file order and disjoint) let the scan skip those offsets. Containers between or after records, and in files with no SGD5 magic, are still found as before.

  • New offsets_inside_records: a level-0 record holding a DXBC run, then DXBC between and after records. The stored one is inside a record; the magic, the gap, the tail and each record's header are not.

A truncated record does not expose the records it stores

A record whose packed bytes run past the end of the file (a cut-off file) was dropped, but the search then went on one byte at a time through its bytes, so a record stored as is inside it (deflate stored blocks) was found and reported. The search now ends at such a record: every byte after its marker belongs to it. Sizes are added with checked_add.

  • New truncated_record_hides_the_records_it_stores: the file cut right after the stored inner record. Before [PS_first, PS_inner], after [PS_first].

A marker with sizes deflate cannot produce is not a record

Bytes between records (a container stored as is, say) that read as a marker with a huge packed size were taken for a truncated record, and a truncated record ends the search, so every record after them was lost. A record's packed size may now be at most what deflate can take for its stated unpacked size (9 bits a byte for fixed codes, which also covers stored blocks' 5 bytes per 65535) plus 4096 bytes of slack, since the stream's end is not checked.

  • New marker_with_impossible_sizes_does_not_end_the_search: FFFFFFFF E7DC0D00 FFFFFFFF 10000000 before a record. Before [], after [PS_after].
  • New packed_size_bound_holds_for_every_level: incompressible input of 0 to 200000 bytes at miniz levels 0 to 10 never exceeds the bound.

A marker running past the end is truncated only if a deflate stream starts there

Bytes between records (a container stored as is, say) that read as a marker with sizes that fit the bound above, but whose packed bytes run past the end of the file, were still taken for a truncated record, which ends the search and loses every record after them. Such a record now counts as truncated only if its bytes so far are a deflate stream of the stated unpacked size: inflating them runs out of input mid-stream, or the stream ends having produced exactly that many bytes. Otherwise the marker is not a record and the search goes on one byte later. A truncated record that is a real one (a cut-off file) still ends the search as before.

  • New marker_running_past_the_end_without_a_stream_does_not_end_the_search: a 64 KiB/64 KiB marker followed by a reserved deflate block type, between two records. Before [PS_first], after [PS_first, PS_after].
  • New truncated_stream_is_told_from_noise: every prefix of a 4000-byte stream at miniz levels 0, 1, 6 and 10 starts a stream; the whole stream does only for its own size; a reserved block type and a stored block whose length check fails do not.

Seeded random files yield exactly the planted records

New random_files_yield_exactly_the_planted_records (200 seeds): 1 to 6 records with gaps of noise and near-miss markers (sizes that disagree, sizes no deflate stream could have) between them, half of them stored as is (level 0) and holding a record and a DXBC magic of their own. records() returns exactly the planted records, with their offsets, names and containers, and in_record() agrees with a linear scan of their spans at every offset. Reverting the skip over packed bytes or the packed-size bound makes it fail. Test-only.

An empty name is no name

A length byte of 1 right before the NUL read as the name "", so any 01 00 before a record's kind (noise, or a nameless record) named it Some(""), and victory shader labelled it with nothing instead of ?. Such a name is now None.

  • New empty_name_is_no_name: before [Some(""), Some("PS_named")], after [None, Some("PS_named")].
  • New archive_with_two_sgd5_files_yields_both: two SGD5 files in one archive, the second magic in a gap between them; both files' records are found. Test-only.

The shader survey does not count a container kept in another one twice

victory shader's raw DXBC scan accepted every magic that parses, so a container kept in a part of another container stored as is (outside any SGD5 record) was counted a second time. New victory_shader::dxbc::find_all returns containers stored as is, in file order, bounded to their stated size, and skips a magic that lies inside a found container's parts. Only parts count: a magic in junk right before a real container can read its size and part count from the real header and parse with no parts, and it must not hide the real one. shader.rs sources uses it, passing sgd5::in_record as the skip. victory-shader now depends on the workspace memchr.

  • New container_in_a_part_is_not_another_container: a container holding another in an ILDB part, then one after a gap. Found: the outer and the last; skipping the outer exposes the inner.
  • New header_reading_into_a_container_does_not_hide_it and finds_nothing_in_noise.
  • cargo test -p victory-shader (59) passes; cargo xwin check/clippy -p victory --target x86_64-pc-windows-msvc are clean.

Records and the raw scan, tested together as the survey runs them

victory shader's sources combines sgd5::records, sgd5::in_record and dxbc::find_all, but the CLI does not build on Linux, so nothing ran that combination. New crates/victory-game/tests/survey.rs (victory-shader as a dev-dependency) does the same thing sources does:

  • stored_record_container_is_counted_once: a level-0 record's container counts as the record only, not also as a raw container; the container between records is raw; without the SGD5 magic the stored container is found as is.
  • random_archives_survey_each_container_once (200 seeds): another file's container before the magic, records (some stored as is, holding a container, a record and a container of their own), and gaps with noise, magics that do not parse, and containers (some keeping another in a part). Exactly the planted records and top-level raw containers are found, each once, and no raw container overlaps a record.
  • Passing |_| false as the skip, or dropping find_all's part check, makes them fail. Test-only; synthetic bytes. cargo test -p victory-game (20 + 2) and cargo clippy -p victory-game --all-targets -- -D warnings pass.

A marker with too few packed bytes for its size is not a record

A marker whose packed size is less than any deflate stream of its stated unpacked size needs (2 bytes, and no fewer than unpacked / 1032) was yielded as a record that never unpacks, and with any packed bytes its span covered the next record's length byte, so that record lost its name.

  • New packed_size_lower_bound_holds_for_every_level (zeros up to 4 MiB at every miniz level), marker_with_too_few_packed_bytes_does_not_hide_the_next_record (before [PS_first, None, PS_after] or [PS_first, None, None], after [PS_first, PS_after]), smallest_containers_are_records.

Bytes that are no deflate stream do not hide the record they cover

Bytes between records that read as a marker with sizes inside both bounds and inside the file were yielded as a corrupt record, and the search resumed after their packed bytes, so a real record whose header they covered was lost. If a record whose packed bytes are a deflate stream starts inside such a marker's span, it now wins and the marker is skipped. A corrupt record that covers no other record is still yielded (unpack() is None), so victory shader still reports it. Streams are inflated only when a span covers another record's header.

  • New marker_without_a_stream_does_not_hide_the_record_it_covers: before [PS_first, None], after [PS_first, PS_after]. Disabling the check makes it fail.
  • New corrupt_record_is_still_a_record: a damaged record and the one after it are both yielded.
  • cargo test -p victory-game (25 + 2) and cargo clippy -p victory-game --all-targets -- -D warnings pass.

Markers laid over one another are each looked at once

A marker whose span covers a stream record, but whose own bytes are no stream, is skipped and the search goes on one byte later. Each such marker scanned its whole span again and inflated every stream record it found, so a file with many markers that each cover the rest of the file took n² work or more: 8000 of them (150 KB) took 43 s. records() now remembers which markers start stream records as the search moves forward through the file, so each marker is looked at once. The records found are unchanged (all earlier tests, including the random-file test, pass as before).

  • New nested_markers_without_streams_take_linear_work: 8000 such markers, then a real record. Before: 43 s (fails its 5 s bound); after: 0.03 s, and only PS_real is found.
  • cargo test -p victory-game (26 + 2) and cargo clippy -p victory-game --all-targets -- -D warnings pass.

Chained markers do not make the stream check read the whole file

Every marker that might be a record has its bytes checked for the start of a deflate stream (when its packed bytes run past the end, when it covers another record, and for each record it covers). Stored blocks that each end where the next marker's stored block begins make every marker's bytes a valid stream through all the markers after it, so each check inflated the rest of the chain: 16000 markers (1 MB) took 2.5 s, 32000 (2 MB) took 9 s, growing as n². starts_stream now reads at most 4096 packed bytes and makes at most 4096 unpacked ones (PROBE). A stream that ends inside the probe must still have the stated size; one that goes on past it counts as a stream.

  • New chained_markers_inside_the_file_take_linear_work: 32000 markers whose packed bytes end at the end of the file. Before: 9 s (fails its 5 s bound); after: milliseconds, same result (one corrupt record spanning them).
  • New chained_markers_past_the_end_take_linear_work: the same chain with packed sizes past the end. Before: 9 s; after: milliseconds. Trade-off: the chain is valid deflate for far longer than the probe, so its first marker is now taken for a truncated record and ends the search (before, the record after the chain was found, after 9 s). Noise that is no deflate stream within 4 KiB still does not end the search (marker_running_past_the_end_without_a_stream_does_not_end_the_search is unchanged).
  • cargo test -p victory-game (28 + 2), cargo clippy -p victory-game --all-targets -- -D warnings and cargo fmt --check pass.

Linear-work tests count work instead of timing it

The three linear-work tests bounded records() by wall clock (5 s), so a slow or loaded machine could fail them and a fast one could hide a regression. A test-only, per-thread counter in starts_stream now records the stream checks made and the packed bytes they read, and the tests bound those: at most two checks per marker, each reading at most PROBE bytes. The code under test is unchanged.

  • Checked against the regressions they guard: with the Streams memo disabled, nested_markers_without_streams_take_linear_work makes 31.6M checks for 8000 markers (bound 16002) and fails; with the probe removed, both chained-marker tests read about 2 MB per check and fail.
  • cargo test -p victory-game (28 + 2), cargo clippy -p victory-game --all-targets -- -D warnings and cargo fmt --check pass.

Test

  • New marker_inside_a_record_is_not_another_record: a synthetic record whose payload is another record, packed at level 0 (stored blocks), followed by a normal record. Before: [PS_outer, PS_inner, PS_after]; after: [PS_outer, PS_after].

  • cargo test -p victory-game (20 tests) and cargo clippy -p victory-game --all-targets -- -D warnings pass on Linux.

  • victory (CLI) does not build on Linux on main (victory-gpu host_resource), so the shader.rs change was checked with cargo check -p victory --target x86_64-pc-windows-msvc.

A printable byte before a long name is not its length byte

From 32 characters on, a name's length byte is printable, so name_before reads back through the bytes before it too (the previous record's packed tail, say). It took the earliest byte equal to its distance to the NUL, so a stray byte there (one in about 256 for names right after random bytes) made the name read as .PS_.... Shader names are identifiers, and a length byte for 32–46 characters is punctuation, so the earliest length byte whose name is all letters, digits and _ now wins; failing that, the earliest, as before. (Taking the nearest instead would misread names of 48+ characters holding a character equal to its distance, like the 4 in PS_4_0_www….)

  • New printable_bytes_before_a_long_name_are_not_part_of_it: a 45-character name after /, 0A, x.. Before: Some(".PS_DeferredLightingComposite_0011aabb_Wrapped"); after: the name. Also a 107-character name and PS_4_0_ + 48 w, read whole.
  • cargo test -p victory-game (29 + 2), cargo clippy -p victory-game --all-targets -- -D warnings and cargo fmt --check pass.

A name does not start with its length byte

A name of 47 to 56 characters has a digit (0–9) for its length byte, so a stray byte right before it that equals its distance to the NUL (one in 256 after random bytes) read as a length byte whose name, the digit then the real name, is all letters, digits and _, and won as the earliest: 0PS_www…. Names are identifiers, which do not start with a digit, so such a candidate is no longer taken for one. (Names of 64+ characters have a letter for a length byte, which this does not tell apart.)

  • New a_name_does_not_start_with_its_length_byte: names of 47, 49 and 56 characters after such a byte. Before: Some("0PS_…"); after: the name.
  • cargo test -p victory-game (30 + 2), cargo clippy -p victory-game --all-targets -- -D warnings and cargo fmt -p victory-game --check pass.

Bytes without a stream over a cut-off record hide nothing

A marker with sizes that fit, followed by bytes that are no deflate stream, laid over the header of a record that the end of the file cuts off, was not counted as covering a record, because only whole records counted. So it was yielded as a corrupt record, and the search went on inside the cut-off record and found the records it stores as is. The whole file yields neither of them. A cut-off record whose bytes so far are a deflate stream now counts as covered, so the phantom is skipped and the cut-off record ends the search, as it does without the phantom.

  • New marker_without_a_stream_over_a_cut_off_record_hides_nothing: whole file [PS_first, PS_outer]; cut after the stored inner record, before [PS_first, None, PS_inner], after [PS_first].
  • cargo test -p victory-game (32 + 2), cargo clippy -p victory-game --all-targets -- -D warnings and cargo fmt -p victory-game --check pass.

Names of every length, the magic in a name, and records in an archive

Test-only: three hermetic synthetic tests in crates/victory-game/src/sgd5.rs that pin down behaviour the search already has.

  • New every_name_length_a_byte_can_state_is_read_whole: 254 back-to-back records named with 1 to 254 characters. Their length bytes run through control bytes, punctuation, digits, letters and bytes past 0x7F. Each name is read whole and each container unpacks.
  • New magic_in_a_name_is_part_of_the_name: records named PS_SGD5_Wrapped and SGD5 after the file's magic. They keep their whole names, and the search does not restart at the magic in a name.
  • New records_in_an_archive_are_the_bare_files_shifted: the same three-record file after 0 to 40 bytes of zeros, printable length-byte look-alikes or marker bytes. It yields the same records, with every offset and span moved by the prefix length and the same names, kinds and containers.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6572870251 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/273). Originally posted by [SkippySteve](https://github.com/SkippySteve) on 2026-11-24T01:58:42Z. --- `sgd5::records` matched every `0x000DDCE7` marker in the file, including ones inside an already-found record's packed bytes. Deflate stored blocks carry the container's bytes as they are, so a container that holds a record-shaped run of bytes was reported as an extra record (and the shader CLI would try to unpack it). The search now resumes after each record's packed bytes. A marker that does not form a record still advances by one byte, as before. ## Game tests: every known build's hash is one `identify()` can match (was #303) `KNOWN_BUILDS` is matched against the hex BLAKE3 that `run.rs` computes, so an entry with a typo, a truncated hash, stray whitespace or a duplicate would silently never identify the build it names. Three tests in `crates/victory-game/src/lib.rs` check that each entry is 64 lowercase hex digits with unique label and hash, that `identify()` finds each build by its own hash in either case, and that an unknown digest, an empty string or non-hex text identifies nothing. The list is empty today, so the first two guard future entries. Test-only; no game data. This PR now carries #303, which is closed in its favour. ## A record's header cannot sit inside the previous record After a record, the search resumed right at the end of its packed bytes, so a marker found there read its NUL, kind and `n` from the last bytes of the previous record (and its name from further back). Bytes after the end of a deflate stream are not checked, so this produced a phantom record. The search now starts 6 bytes after the previous record (or the magic), and a record's header and name are read only from bytes after it. - New `header_inside_a_record_is_not_another_record`: before `[Some("PS_first"), None]`, after `[Some("PS_first")]`. - New `empty_container_unpacks` and `damaged_file_yields_disjoint_records` (every single-byte change to a two-record file, 8 values each: no panic, records in order, inside the file, not overlapping). ## The shader survey does not count a stored container twice Deflate stored blocks carry a record's container as it is, so `victory shader`'s raw `DXBC` scan (`apps/victory/src/shader.rs`, `sources`) found it inside the record's packed bytes and counted it again, next to the unpacked record. `sgd5::Record::span` (marker to end of packed stream) and `sgd5::in_record` (binary search over the records, which are in file order and disjoint) let the scan skip those offsets. Containers between or after records, and in files with no SGD5 magic, are still found as before. - New `offsets_inside_records`: a level-0 record holding a `DXBC` run, then `DXBC` between and after records. The stored one is inside a record; the magic, the gap, the tail and each record's header are not. ## A truncated record does not expose the records it stores A record whose packed bytes run past the end of the file (a cut-off file) was dropped, but the search then went on one byte at a time through its bytes, so a record stored as is inside it (deflate stored blocks) was found and reported. The search now ends at such a record: every byte after its marker belongs to it. Sizes are added with `checked_add`. - New `truncated_record_hides_the_records_it_stores`: the file cut right after the stored inner record. Before `[PS_first, PS_inner]`, after `[PS_first]`. ## A marker with sizes deflate cannot produce is not a record Bytes between records (a container stored as is, say) that read as a marker with a huge packed size were taken for a truncated record, and a truncated record ends the search, so every record after them was lost. A record's packed size may now be at most what deflate can take for its stated unpacked size (9 bits a byte for fixed codes, which also covers stored blocks' 5 bytes per 65535) plus 4096 bytes of slack, since the stream's end is not checked. - New `marker_with_impossible_sizes_does_not_end_the_search`: `FFFFFFFF E7DC0D00 FFFFFFFF 10000000` before a record. Before `[]`, after `[PS_after]`. - New `packed_size_bound_holds_for_every_level`: incompressible input of 0 to 200000 bytes at miniz levels 0 to 10 never exceeds the bound. ## A marker running past the end is truncated only if a deflate stream starts there Bytes between records (a container stored as is, say) that read as a marker with sizes that fit the bound above, but whose packed bytes run past the end of the file, were still taken for a truncated record, which ends the search and loses every record after them. Such a record now counts as truncated only if its bytes so far are a deflate stream of the stated unpacked size: inflating them runs out of input mid-stream, or the stream ends having produced exactly that many bytes. Otherwise the marker is not a record and the search goes on one byte later. A truncated record that is a real one (a cut-off file) still ends the search as before. - New `marker_running_past_the_end_without_a_stream_does_not_end_the_search`: a 64 KiB/64 KiB marker followed by a reserved deflate block type, between two records. Before `[PS_first]`, after `[PS_first, PS_after]`. - New `truncated_stream_is_told_from_noise`: every prefix of a 4000-byte stream at miniz levels 0, 1, 6 and 10 starts a stream; the whole stream does only for its own size; a reserved block type and a stored block whose length check fails do not. ## Seeded random files yield exactly the planted records New `random_files_yield_exactly_the_planted_records` (200 seeds): 1 to 6 records with gaps of noise and near-miss markers (sizes that disagree, sizes no deflate stream could have) between them, half of them stored as is (level 0) and holding a record and a `DXBC` magic of their own. `records()` returns exactly the planted records, with their offsets, names and containers, and `in_record()` agrees with a linear scan of their spans at every offset. Reverting the skip over packed bytes or the packed-size bound makes it fail. Test-only. ## An empty name is no name A length byte of 1 right before the NUL read as the name `""`, so any `01 00` before a record's kind (noise, or a nameless record) named it `Some("")`, and `victory shader` labelled it with nothing instead of `?`. Such a name is now `None`. - New `empty_name_is_no_name`: before `[Some(""), Some("PS_named")]`, after `[None, Some("PS_named")]`. - New `archive_with_two_sgd5_files_yields_both`: two SGD5 files in one archive, the second magic in a gap between them; both files' records are found. Test-only. ## The shader survey does not count a container kept in another one twice `victory shader`'s raw `DXBC` scan accepted every magic that parses, so a container kept in a part of another container stored as is (outside any SGD5 record) was counted a second time. New `victory_shader::dxbc::find_all` returns containers stored as is, in file order, bounded to their stated size, and skips a magic that lies inside a found container's parts. Only parts count: a magic in junk right before a real container can read its size and part count from the real header and parse with no parts, and it must not hide the real one. `shader.rs` `sources` uses it, passing `sgd5::in_record` as the skip. `victory-shader` now depends on the workspace `memchr`. - New `container_in_a_part_is_not_another_container`: a container holding another in an `ILDB` part, then one after a gap. Found: the outer and the last; skipping the outer exposes the inner. - New `header_reading_into_a_container_does_not_hide_it` and `finds_nothing_in_noise`. - `cargo test -p victory-shader` (59) passes; `cargo xwin check`/`clippy -p victory --target x86_64-pc-windows-msvc` are clean. ## Records and the raw scan, tested together as the survey runs them `victory shader`'s `sources` combines `sgd5::records`, `sgd5::in_record` and `dxbc::find_all`, but the CLI does not build on Linux, so nothing ran that combination. New `crates/victory-game/tests/survey.rs` (`victory-shader` as a dev-dependency) does the same thing `sources` does: - `stored_record_container_is_counted_once`: a level-0 record's container counts as the record only, not also as a raw container; the container between records is raw; without the SGD5 magic the stored container is found as is. - `random_archives_survey_each_container_once` (200 seeds): another file's container before the magic, records (some stored as is, holding a container, a record and a container of their own), and gaps with noise, magics that do not parse, and containers (some keeping another in a part). Exactly the planted records and top-level raw containers are found, each once, and no raw container overlaps a record. - Passing `|_| false` as the skip, or dropping `find_all`'s part check, makes them fail. Test-only; synthetic bytes. `cargo test -p victory-game` (20 + 2) and `cargo clippy -p victory-game --all-targets -- -D warnings` pass. ## A marker with too few packed bytes for its size is not a record A marker whose packed size is less than any deflate stream of its stated unpacked size needs (2 bytes, and no fewer than unpacked / 1032) was yielded as a record that never unpacks, and with any packed bytes its span covered the next record's length byte, so that record lost its name. - New `packed_size_lower_bound_holds_for_every_level` (zeros up to 4 MiB at every miniz level), `marker_with_too_few_packed_bytes_does_not_hide_the_next_record` (before `[PS_first, None, PS_after]` or `[PS_first, None, None]`, after `[PS_first, PS_after]`), `smallest_containers_are_records`. ## Bytes that are no deflate stream do not hide the record they cover Bytes between records that read as a marker with sizes inside both bounds and inside the file were yielded as a corrupt record, and the search resumed after their packed bytes, so a real record whose header they covered was lost. If a record whose packed bytes are a deflate stream starts inside such a marker's span, it now wins and the marker is skipped. A corrupt record that covers no other record is still yielded (`unpack()` is `None`), so `victory shader` still reports it. Streams are inflated only when a span covers another record's header. - New `marker_without_a_stream_does_not_hide_the_record_it_covers`: before `[PS_first, None]`, after `[PS_first, PS_after]`. Disabling the check makes it fail. - New `corrupt_record_is_still_a_record`: a damaged record and the one after it are both yielded. - `cargo test -p victory-game` (25 + 2) and `cargo clippy -p victory-game --all-targets -- -D warnings` pass. ## Markers laid over one another are each looked at once A marker whose span covers a stream record, but whose own bytes are no stream, is skipped and the search goes on one byte later. Each such marker scanned its whole span again and inflated every stream record it found, so a file with many markers that each cover the rest of the file took n² work or more: 8000 of them (150 KB) took 43 s. `records()` now remembers which markers start stream records as the search moves forward through the file, so each marker is looked at once. The records found are unchanged (all earlier tests, including the random-file test, pass as before). - New `nested_markers_without_streams_take_linear_work`: 8000 such markers, then a real record. Before: 43 s (fails its 5 s bound); after: 0.03 s, and only `PS_real` is found. - `cargo test -p victory-game` (26 + 2) and `cargo clippy -p victory-game --all-targets -- -D warnings` pass. ## Chained markers do not make the stream check read the whole file Every marker that might be a record has its bytes checked for the start of a deflate stream (when its packed bytes run past the end, when it covers another record, and for each record it covers). Stored blocks that each end where the next marker's stored block begins make every marker's bytes a valid stream through all the markers after it, so each check inflated the rest of the chain: 16000 markers (1 MB) took 2.5 s, 32000 (2 MB) took 9 s, growing as n². `starts_stream` now reads at most 4096 packed bytes and makes at most 4096 unpacked ones (`PROBE`). A stream that ends inside the probe must still have the stated size; one that goes on past it counts as a stream. - New `chained_markers_inside_the_file_take_linear_work`: 32000 markers whose packed bytes end at the end of the file. Before: 9 s (fails its 5 s bound); after: milliseconds, same result (one corrupt record spanning them). - New `chained_markers_past_the_end_take_linear_work`: the same chain with packed sizes past the end. Before: 9 s; after: milliseconds. Trade-off: the chain is valid deflate for far longer than the probe, so its first marker is now taken for a truncated record and ends the search (before, the record after the chain was found, after 9 s). Noise that is no deflate stream within 4 KiB still does not end the search (`marker_running_past_the_end_without_a_stream_does_not_end_the_search` is unchanged). - `cargo test -p victory-game` (28 + 2), `cargo clippy -p victory-game --all-targets -- -D warnings` and `cargo fmt --check` pass. ## Linear-work tests count work instead of timing it The three linear-work tests bounded `records()` by wall clock (5 s), so a slow or loaded machine could fail them and a fast one could hide a regression. A test-only, per-thread counter in `starts_stream` now records the stream checks made and the packed bytes they read, and the tests bound those: at most two checks per marker, each reading at most `PROBE` bytes. The code under test is unchanged. - Checked against the regressions they guard: with the `Streams` memo disabled, `nested_markers_without_streams_take_linear_work` makes 31.6M checks for 8000 markers (bound 16002) and fails; with the probe removed, both chained-marker tests read about 2 MB per check and fail. - `cargo test -p victory-game` (28 + 2), `cargo clippy -p victory-game --all-targets -- -D warnings` and `cargo fmt --check` pass. ## Test - New `marker_inside_a_record_is_not_another_record`: a synthetic record whose payload is another record, packed at level 0 (stored blocks), followed by a normal record. Before: `[PS_outer, PS_inner, PS_after]`; after: `[PS_outer, PS_after]`. - `cargo test -p victory-game` (20 tests) and `cargo clippy -p victory-game --all-targets -- -D warnings` pass on Linux. - `victory` (CLI) does not build on Linux on `main` (victory-gpu `host_resource`), so the `shader.rs` change was checked with `cargo check -p victory --target x86_64-pc-windows-msvc`. ## A printable byte before a long name is not its length byte From 32 characters on, a name's length byte is printable, so `name_before` reads back through the bytes before it too (the previous record's packed tail, say). It took the earliest byte equal to its distance to the NUL, so a stray byte there (one in about 256 for names right after random bytes) made the name read as `.PS_...`. Shader names are identifiers, and a length byte for 32–46 characters is punctuation, so the earliest length byte whose name is all letters, digits and `_` now wins; failing that, the earliest, as before. (Taking the nearest instead would misread names of 48+ characters holding a character equal to its distance, like the `4` in `PS_4_0_www…`.) - New `printable_bytes_before_a_long_name_are_not_part_of_it`: a 45-character name after `/`, `0A`, `x.`. Before: `Some(".PS_DeferredLightingComposite_0011aabb_Wrapped")`; after: the name. Also a 107-character name and `PS_4_0_` + 48 `w`, read whole. - `cargo test -p victory-game` (29 + 2), `cargo clippy -p victory-game --all-targets -- -D warnings` and `cargo fmt --check` pass. ## A name does not start with its length byte A name of 47 to 56 characters has a digit (`0`–`9`) for its length byte, so a stray byte right before it that equals its distance to the NUL (one in 256 after random bytes) read as a length byte whose name, the digit then the real name, is all letters, digits and `_`, and won as the earliest: `0PS_www…`. Names are identifiers, which do not start with a digit, so such a candidate is no longer taken for one. (Names of 64+ characters have a letter for a length byte, which this does not tell apart.) - New `a_name_does_not_start_with_its_length_byte`: names of 47, 49 and 56 characters after such a byte. Before: `Some("0PS_…")`; after: the name. - `cargo test -p victory-game` (30 + 2), `cargo clippy -p victory-game --all-targets -- -D warnings` and `cargo fmt -p victory-game --check` pass. ## Bytes without a stream over a cut-off record hide nothing A marker with sizes that fit, followed by bytes that are no deflate stream, laid over the header of a record that the end of the file cuts off, was not counted as covering a record, because only whole records counted. So it was yielded as a corrupt record, and the search went on inside the cut-off record and found the records it stores as is. The whole file yields neither of them. A cut-off record whose bytes so far are a deflate stream now counts as covered, so the phantom is skipped and the cut-off record ends the search, as it does without the phantom. - New `marker_without_a_stream_over_a_cut_off_record_hides_nothing`: whole file `[PS_first, PS_outer]`; cut after the stored inner record, before `[PS_first, None, PS_inner]`, after `[PS_first]`. - `cargo test -p victory-game` (32 + 2), `cargo clippy -p victory-game --all-targets -- -D warnings` and `cargo fmt -p victory-game --check` pass. ## Names of every length, the magic in a name, and records in an archive Test-only: three hermetic synthetic tests in `crates/victory-game/src/sgd5.rs` that pin down behaviour the search already has. - New `every_name_length_a_byte_can_state_is_read_whole`: 254 back-to-back records named with 1 to 254 characters. Their length bytes run through control bytes, punctuation, digits, letters and bytes past 0x7F. Each name is read whole and each container unpacks. - New `magic_in_a_name_is_part_of_the_name`: records named `PS_SGD5_Wrapped` and `SGD5` after the file's magic. They keep their whole names, and the search does not restart at the magic in a name. - New `records_in_an_archive_are_the_bare_files_shifted`: the same three-record file after 0 to 40 bytes of zeros, printable length-byte look-alikes or marker bytes. It yields the same records, with every offset and span moved by the prefix length and the same names, kinds and containers.
catminou4 commented 2026-11-24 06:48:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T06:48:43Z.

Review: APPROVED


Verified locally on macOS 26 arm64, rustc 1.98.1:

  • cargo test -p victory-game --locked: 56 + 2 passed, 0 failed — the new SGD5 marker/survey tests run green on macOS (main: 2 passed).
  • cargo test -p victory-shader --locked: 59 passed, 0 failed (+3 for the dxbc.rs changes).
  • cargo check -p victory --locked: clean with #235's head merged locally (uncommitted; main's app crate doesn't compile on macOS due to the known host_resource cfg issue). No conflicts with #235.
  • The Cargo.lock delta matches the manifest changes (victory-game → victory-shader, victory-shader + memchr); no cycle.

Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6034848036 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/273#pullrequestreview-6034848036). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T06:48:43Z. **Review:** APPROVED --- Verified locally on macOS 26 arm64, rustc 1.98.1: - `cargo test -p victory-game --locked`: **56 + 2 passed, 0 failed** — the new SGD5 marker/survey tests run green on macOS (main: 2 passed). - `cargo test -p victory-shader --locked`: **59 passed, 0 failed** (+3 for the dxbc.rs changes). - `cargo check -p victory --locked`: clean with #235's head merged locally (uncommitted; main's app crate doesn't compile on macOS due to the known `host_resource` cfg issue). No conflicts with #235. - The Cargo.lock delta matches the manifest changes (victory-game → victory-shader, victory-shader + memchr); no cycle. Approving.
jeremygold02 commented 2026-11-24 06:55:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T04:11:27Z.


Tested PR #273 at head 7c033d911d1deda65306692dc0e94beed1507b9b (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at 7c033d911d1deda65306692dc0e94beed1507b9b.

  • cargo test --locked -p victory-game — passed (25 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out); cases included sgd5::tests::marker_running_past_the_end_without_a_stream_does_not_end_the_search, sgd5::tests::reads_records, sgd5::tests::empty_container_unpacks, sgd5::tests::corrupt_stream_does_not_unpack, and 21 others.
  • cargo test --locked -p victory-shader container_in_a_part_is_not_another_container — passed (1 passed; 0 failed; 71 filtered out): dxbc::tests::container_in_a_part_is_not_another_container.

Behavior covered: SGD5 record spans remain disjoint, and the DXBC survey does not count containers inside packed records. Relevant code: sgd5.rs, dxbc.rs, shader.rs.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121790338 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/273#issuecomment-7121790338). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T04:11:27Z. --- Tested PR #273 at head `7c033d911d1deda65306692dc0e94beed1507b9b` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `7c033d911d1deda65306692dc0e94beed1507b9b`. - `cargo test --locked -p victory-game` — passed (25 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out); cases included `sgd5::tests::marker_running_past_the_end_without_a_stream_does_not_end_the_search`, `sgd5::tests::reads_records`, `sgd5::tests::empty_container_unpacks`, `sgd5::tests::corrupt_stream_does_not_unpack`, and 21 others. - `cargo test --locked -p victory-shader container_in_a_part_is_not_another_container` — passed (1 passed; 0 failed; 71 filtered out): `dxbc::tests::container_in_a_part_is_not_another_container`. Behavior covered: SGD5 record spans remain disjoint, and the DXBC survey does not count containers inside packed records. Relevant code: [sgd5.rs](https://github.com/Marvisak/VIctory/blob/7c033d911d1deda65306692dc0e94beed1507b9b/crates/victory-game/src/sgd5.rs), [dxbc.rs](https://github.com/Marvisak/VIctory/blob/7c033d911d1deda65306692dc0e94beed1507b9b/crates/victory-shader/src/dxbc.rs), [shader.rs](https://github.com/Marvisak/VIctory/blob/7c033d911d1deda65306692dc0e94beed1507b9b/apps/victory/src/shader.rs).
upstream-sync closed this pull request 2026-11-24 23:04:01 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!273
No description provided.