From 46405ae14aa1c730cd27a13b358fab5a4325d158 Mon Sep 17 00:00:00 2001 From: Matthew Stanley <1379tech@gmail.com> Date: Sat, 17 Oct 2026 14:43:47 -0700 Subject: [PATCH] Buffer file reads before hashing large disc images --- runtime/src/psx_sha256_file.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/src/psx_sha256_file.cpp b/runtime/src/psx_sha256_file.cpp index 578b3838..5f320678 100644 --- a/runtime/src/psx_sha256_file.cpp +++ b/runtime/src/psx_sha256_file.cpp @@ -86,7 +86,13 @@ bool try_native(std::ifstream& file, std::vector& buffer, template PsxFileHashResult hash_file(const std::filesystem::path& path, uint8_t out[32], Hash& native) { - std::ifstream file(path, std::ios::binary); + // Some filebuf implementations otherwise turn each 1 MiB read into many + // small CRT reads. Keep this separate buffer alive until after file closes. + std::vector file_buffer(1024 * 1024); + std::ifstream file; + file.rdbuf()->pubsetbuf(file_buffer.data(), + static_cast(file_buffer.size())); + file.open(path, std::ios::binary); if (!file) return PsxFileHashResult::OpenError; std::vector buffer(1024 * 1024); uint8_t digest[32];