From c785b36e60ca75722693e6f93402c8c36b399c8c Mon Sep 17 00:00:00 2001 From: godpow Date: Sun, 19 Oct 2025 08:53:49 +0200 Subject: [PATCH] Update src/core/file_sys/fssystem/fssystem_aes_ctr_storage.cpp --- .../fssystem/fssystem_aes_ctr_storage.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/file_sys/fssystem/fssystem_aes_ctr_storage.cpp b/src/core/file_sys/fssystem/fssystem_aes_ctr_storage.cpp index 1e11d70d8d..6eb78c8255 100644 --- a/src/core/file_sys/fssystem/fssystem_aes_ctr_storage.cpp +++ b/src/core/file_sys/fssystem/fssystem_aes_ctr_storage.cpp @@ -86,18 +86,21 @@ size_t AesCtrStorage::Write(const u8* buffer, size_t size, size_t offset) { // Loop until all data is written using a pooled buffer residing on the stack (blocksize = 0x10) boost::container::static_vector pooled_buffer; - for (size_t remaining = size; remaining > 0; ) { - // Determine data we're writing and where. - auto const write_size = (std::min)(pooled_buffer.size(), remaining); - u8* write_buf = pooled_buffer.data(); + pooled_buffer.resize(BlockSize); + + const u8* cur = buffer; + size_t remaining = size; + size_t current_offset = offset; + + while (remaining > 0) { + const size_t write_size = std::min(pooled_buffer.size(), remaining); - // Encrypt the data and then write it. m_cipher->SetIV(ctr); - m_cipher->Transcode(buffer, write_size, write_buf, Core::Crypto::Op::Encrypt); - m_base_storage->Write(write_buf, write_size, offset); + m_cipher->Transcode(cur, write_size, pooled_buffer.data(), Core::Crypto::Op::Encrypt); + m_base_storage->Write(pooled_buffer.data(), write_size, current_offset); - // Advance next write chunk - offset += write_size; + cur += write_size; + current_offset += write_size; remaining -= write_size; if (remaining > 0) AddCounter(ctr.data(), IvSize, write_size / BlockSize);