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];