瀏覽代碼

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.
Tim Schumacher 2 年之前
父節點
當前提交
b88c58b94c
共有 2 個文件被更改,包括 7 次插入1 次删除
  1. 3 0
      AK/CircularBuffer.cpp
  2. 4 1
      Userland/Libraries/LibCompress/Deflate.cpp

+ 3 - 0
AK/CircularBuffer.cpp

@@ -213,6 +213,9 @@ ErrorOr<size_t> CircularBuffer::copy_from_seekback(size_t distance, size_t lengt
 
 
     auto remaining_length = length;
     auto remaining_length = length;
     while (remaining_length > 0) {
     while (remaining_length > 0) {
+        if (empty_space() == 0)
+            break;
+
         auto next_span = next_read_span_with_seekback(distance);
         auto next_span = next_read_span_with_seekback(distance);
         if (next_span.size() == 0)
         if (next_span.size() == 0)
             break;
             break;

+ 4 - 1
Userland/Libraries/LibCompress/Deflate.cpp

@@ -208,7 +208,10 @@ ErrorOr<bool> DeflateDecompressor::CompressedBlock::try_read_more()
             m_decompressor.m_output_buffer.write({ &byte, sizeof(byte) });
             m_decompressor.m_output_buffer.write({ &byte, sizeof(byte) });
         }
         }
     } else {
     } 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;
     return true;