diff --git a/rpcs3/util/serialization_ext.cpp b/rpcs3/util/serialization_ext.cpp index 527192f100..dced9ebc90 100644 --- a/rpcs3/util/serialization_ext.cpp +++ b/rpcs3/util/serialization_ext.cpp @@ -420,7 +420,15 @@ bool compressed_serialization_file_handler::handle_file_op(utils::serial& ar, us const usz old_size = ar.data.size(); // Try to prefetch data by reading more than requested - ar.data.resize(std::min(read_limit, std::max({ ar.data.capacity(), ar.data.size() + read_past_buffer * 3 / 2, ar.expect_little_data() ? usz{4096} : usz{0x10'0000} }))); + const usz new_size = std::min(read_limit, std::max({ ar.data.capacity(), ar.data.size() + read_past_buffer * 3 / 2, ar.expect_little_data() ? usz{4096} : usz{0x10'0000} })); + + if (new_size < old_size) + { + // Read limit forbids further reads at this point + return true; + } + + ar.data.resize(new_size); ar.data.resize(this->read_at(ar, old_size + ar.data_offset, data ? const_cast(data) : ar.data.data() + old_size, ar.data.size() - old_size) + old_size); } @@ -652,9 +660,18 @@ void compressed_serialization_file_handler::stream_data_prepare_thread_op() } while (m_zs.avail_out == 0 || m_zs.avail_in != 0); + if (m_errored) + { + return; + } + + if (!buffer_offset) + { + continue; + } + // Forward for file write const usz queued_size = data.size(); - ensure(buffer_offset); const usz size_diff = buffer_offset - queued_size; const usz new_val = m_pending_bytes.add_fetch(size_diff);