fix(host): a SARC name offset is 24 bits, not 16 #2145
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2145
Loading…
Reference in a new issue
No description provided.
Delete branch "dazemc/Longshot:fix/sarc-name-offset-24bit"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
heart_sarc_findreads a SARCSFATnode's name offset asattributes & 0xffff. In the format, bits 0-23 are the name's word offset into theSFNTstring table and bit 24 is the has-name flag (already tested on the line above). Masking with 16 bits drops bits 16-23, so in a string table of 256 KiB or more every name past that point would resolve at the wrong offset and be looked up as absent.This is latent, not a game bug: the shipped
Pack/ZsDic.pack.zs— the only file this reads — has a 56-byte name table whose largest name word offset is0xb, so the 16-bit mask never dropped a bit for the game. The change is format compliance and insurance against a large or repacked table, not a fix for an observable symptom.What changed: the mask is
0xffffff, with the same bounds, terminator and data-range checks as before.host/oot_heart_containers.c,heart_sarc_find; the test istests/test_heart_containers.py.Testing
Tested:
tests/test_heart_containers.pynow builds a SARC with 256 KiB of filler names first, sozs.zsdicandbcett.byml.zsdicsit at word offset0x10000(both byte orders). On main the new cases fail for exactly the masked bits:With
0xffffff:PASS: the pieces of heart in all add up ... either byte order, cut short or not;run_all --strict test_heart_containerspasses.In the game: Arch Linux, Hyprland, RTX 4070 Ti (NVIDIA 620.70.06), built as a pack over
8aa74983(since rebased onto1101b612, whose commits touch input, the renderer and tests, nothost/oot_heart_containers.c, so the run still holds) and played — Kokiri Forest (child), 20 s measured after warm-up: 1821 frames, 91.1 fps, median 11.04 ms, 0 cold frames (base8aa74983: 1832 frames, 91.6 fps, 10.91 ms). One run a side; the small difference is not attributable.Still to test:
Measurements
Nothing to measure: the lookup the fix changes is never reached by the shipped pack (its name table is 56 bytes, far below 256 KiB); the in-game smoke above is a boot/play check and shows no attributable difference.
Risks
A malformed name offset is still refused by the same bounds checks; a valid offset past 256 KiB now resolves instead of missing (the intended change). No switch; a revert is enough. Nothing changes for saves,
longshot_options.inior the caches.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).tests/run_all.py --strict: 811 passed, 109 failed, 18 skipped on bothmain @ 8aa74983and this branch; the failing check names (108 unique) are identical on both sides (empty comm diff) — main's known-red checks and test-side drift from today's merges, none caused here.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Kokiri Forest (child) under a pack over
8aa74983: 20 s after warm-up, 91.1 fps median 11.04 ms, 0 cold frames; game boots and plays. Arch Linux/Hyprland, RTX 4070 Ti, NVIDIA 620.70.06. Latent format fix; no observable change expected.933a1a3aaccf6fb40296Rebased onto
1101b612. The commits since the run (input, renderer, tests) do not touch host/oot_heart_containers.c, so the in-game smoke still holds; head iscf6fb402.@review
Recommendation: Approve. The code is ready: only testing is left. The synthetic test demonstrates the 24-bit offset fix, but the stated Windows build and startup check is still outstanding. The widened lookup can also accept a malformed name offset into file data. Recommend approval; not approved on the forge.
The change lets the Discord heart-count loader find dictionary names beyond 256 KiB in a SARC name table. The shipped pack does not need the fix; the added test covers the previously dropped offset bit in both byte orders.
@fixwill do (1)host/oot_heart_containers.c:46: The widened offset can point past the SFNT name table into the archive's file data, because it is checked against the whole buffer rather than the data start. (more on the line)Before merging: testing (1) (runs on the systems it can change; it doesn't hold the recommendation)
Checks: Still running:
CI / Conventional Commit title (pull_request),CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request),CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request),CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request),CI / Workflow lint (actionlint) (pull_request),CI / Website build and checks (pull_request),Guide screenshots / Guide images and local UI source review (pull_request),Third-party parts / As their notes say (pull_request),Third-party parts / The same as upstream (pull_request),Website / Website on Cloudflare (pull_request).More: does it help, other systems, switches, what was read
Does it help: Yes for the synthetic case: the author reports both lookups fail on the base and pass with the fix in both byte orders. There is no claimed improvement for the shipped pack, whose reported name table is 56 bytes.
Other systems: The lookup runs while loading the Discord heart-count data, on Windows and Linux, independently of GPU vendor. The author reports a Linux game smoke test; Windows llvm-mingw build and startup remain untested. Saves, rendering and input are not changed by the diff.
Switches: None.
Reviewed:
cf6fb40296against1101b6127e: Read AGENTS.md, CONTRIBUTING.md, the pull request template, docs/dev/standards.md, both changed files and the heart-containers header in full; read the commits, diff and relevant call-site references. Rechecked both changed files' diffs. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. Other caller files were searched, not read in full; no recorded runs or generated files were included in the diff.; nothing run (a code review).Checked and fine:
Testing: No code or tests were run during review. The author reports the new test fails on the base and passes on the change, plus a Linux game smoke test; CI remains in progress.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -44,3 +44,3 @@const uint32_t attr = rd(d, n, nodes + 16 * i + 4, 4, be);if (!(attr & 0x01000000)) continue;const size_t at = names + 4 * (size_t)(attr & 0xffff);const size_t at = names + 4 * (size_t)(attr & 0xffffff);L1 (minor): The widened offset can point past the SFNT name table into the archive's file data, because it is checked against the whole buffer rather than the data start. A malformed node whose high offset lands on a matching string in file data can now be accepted as that name and return an unrelated payload. Check that the complete name and terminator lie before the SARC data offset as well as within the buffer.