From b88c58b94ca028d12dbe453e1c1fa0e46f704b03 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Tue, 4 Apr 2023 18:43:24 +0200 Subject: [PATCH] AK+LibCompress: Break when seekback copying to a full CircularBuffer Otherwise, we just end up infinitely looping while waiting for more space in the destination. --- AK/CircularBuffer.cpp | 3 +++ Userland/Libraries/LibCompress/Deflate.cpp | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AK/CircularBuffer.cpp b/AK/CircularBuffer.cpp index 884bad0f345..becef3c58fc 100644 --- a/AK/CircularBuffer.cpp +++ b/AK/CircularBuffer.cpp @@ -213,6 +213,9 @@ ErrorOr CircularBuffer::copy_from_seekback(size_t distance, size_t lengt auto remaining_length = length; while (remaining_length > 0) { + if (empty_space() == 0) + break; + auto next_span = next_read_span_with_seekback(distance); if (next_span.size() == 0) break; diff --git a/Userland/Libraries/LibCompress/Deflate.cpp b/Userland/Libraries/LibCompress/Deflate.cpp index fe46d1d8092..4f9587229a7 100644 --- a/Userland/Libraries/LibCompress/Deflate.cpp +++ b/Userland/Libraries/LibCompress/Deflate.cpp @@ -208,7 +208,10 @@ ErrorOr DeflateDecompressor::CompressedBlock::try_read_more() m_decompressor.m_output_buffer.write({ &byte, sizeof(byte) }); } } else { - TRY(m_decompressor.m_output_buffer.copy_from_seekback(distance, length)); + auto copied_length = TRY(m_decompressor.m_output_buffer.copy_from_seekback(distance, length)); + + // TODO: What should we do if the output buffer is full? + VERIFY(copied_length == length); } return true;