Skip to content

Fix MD5Sum hashing hostfs::File pointers instead of file contents (GGPO verification) - #2513

Merged
flyinghead merged 1 commit into
flyinghead:masterfrom
unjordi:fix/md5sum-hostfs-file
Oct 12, 2026
Merged

flyinghead merged 1 commit into
flyinghead:masterfrom
unjordi:fix/md5sum-hostfs-file

Conversation

@unjordi

@unjordi unjordi commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Problem

Since the file I/O indirection (#2299), several call sites pass a hostfs::File * to MD5Sum::add(). There is no overload for that type, so the call resolves to the generic add(const T&) template, which hashes the pointer value instead of the file contents:

  • nullDC.cpp dc_loadstate(): settings.network.md5.savestate (GGPO stateMD5 when a .state.net is used)
  • imgread/cdi.cpp, imgread/gdi.cpp, imgread/cue.cpp: disc digest (GGPO gameMD5)

The digests then depend on the heap address, so they differ between peers (and between runs on the same machine). As a result, GGPO netplay always fails with "Verification mismatch" / "Peer verification failed" when using a .state.net savestate, or when playing CDI, GDI or CUE images. CHD images are not affected (their digest comes from the CHD header).

Captured sync_request verification data, v2.7 flatpak, same .state.net on both peers:

gameMD5 stateMD5
peer A 984ac73c… ad9318c4… (changes every run)
peer B 984ac73c… 43b054c4… (changes every run)
with this fix, both 984ac73c… 628deb6c…

Fix

  • Add MD5Sum::add(hostfs::File *), which hashes the whole file content, with the same semantics as the existing std::FILE * overload (rewinds first).
  • Add a static_assert in the generic template that rejects pointer types, so this cannot silently happen again.

Tests

tests/src/util/Md5SumTest.cpp:

  • MD5Sum of a hostfs::File equals the MD5 of its content, independently of the current position, and matches the std::FILE overload.
  • The digest of test_cues/d/cs.cue returned by OpenDisc() equals the MD5 of its track data.

The three tests fail without the fix and pass with it. The rest of the suite is unchanged.

Also verified end-to-end: GGPO netplay of a GD-ROM game (CHD) with a shared .state.net between x86_64 ↔ x86_64 and x86_64 ↔ aarch64 Linux handhelds (flatpak v2.7 + this patch, both architectures), which always failed verification before. Also re-checked after rebooting both devices.

Since the switch to hostfs::File (flyinghead#2299), MD5Sum::add(hostfs::File *)
resolved to the generic add(const T&) template, which hashes the pointer
value. The resulting digests depend on the heap address, so they differ
between peers and between runs. This breaks GGPO peer verification when
a .state.net savestate is used (stateMD5), and with CDI, GDI and CUE
images (gameMD5).

Add an MD5Sum::add(hostfs::File *) overload that hashes the whole file
content, like the std::FILE overload, and reject pointer types in the
template with a static_assert so this cannot happen again silently.
@flyinghead

Copy link
Copy Markdown
Owner

Is this PR still a Draft or can it be merged?

Press5elect pushed a commit to Press5elect/PSFlycast that referenced this pull request Oct 7, 2026
…ast's open pull requests, release candidates in the updater, no Screenshot control

- Netplay: the checksum of a save state or of a CDI, GDI or CUE image is the
  file's, not its pointer's (flyinghead#2513).
- sh4: the FPSCR cause field is cleared when the guest writes FPSCR (flyinghead#2531).
- CHD: the track metadata's text fields are held to their buffers (flyinghead#2384).
- Input: absolute mouse motion rebased after relative input (flyinghead#2528); axis
  detection for triggers that report as buttons (flyinghead#2213).
- Checks of an ISO9660 directory record, RZIP chunk sizes, DNS answers,
  GGPO input packets and card events, and a Naomi LST's ranges (flyinghead#2414,
  flyinghead#2415, flyinghead#2416, flyinghead#2519, flyinghead#2520, flyinghead#2521).
- The updater ranks v1.1.0-rc1 under v1.1.0, and a release's build is not
  offered candidates.
- The quick menu's Screenshot row and control are gone: the console's
  Create button takes screenshots.
- Built with PS5_Vulkan 5b5e4fc, the payload SDK fork at b5efad5 and
  libsmb2 7e4ff97.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@flyinghead
flyinghead marked this pull request as ready for review October 12, 2026 07:33
@flyinghead
flyinghead merged commit e6d3365 into flyinghead:master Oct 12, 2026
17 of 21 checks passed
@unjordi
unjordi deleted the fix/md5sum-hostfs-file branch November 19, 2026 19:55
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.

2 participants