From 674b05322b28cb82c1967998b6eab6f0b5aef362 Mon Sep 17 00:00:00 2001 From: chubei Date: Mon, 21 Sep 2020 14:47:33 +0800 Subject: [PATCH] Bugfix: Wrong buffer length passed to lz4 decompressor --- conanfile.py | 2 +- src/CMakeLists.txt | 2 +- src/src/PagedFile.cpp | 2 +- src/src/main.cpp | 7 +++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/conanfile.py b/conanfile.py index 433afe1..2030048 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,7 +3,7 @@ class PagedfileConan(ConanFile): name = "pagedfile" - version = "1.3.1" + version = "1.3.2" license = "MIT" author = "Fangyang Shen dev@shenfy.com" url = "https://github.com/shenfy/pagedfile" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index efed348..42b3645 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.17) -project(pfar VERSION 1.3.0 LANGUAGES CXX) +project(pfar VERSION 1.3.2 LANGUAGES CXX) if (EXISTS ${CMAKE_BINARY_DIR}/conan_paths.cmake) include(${CMAKE_BINARY_DIR}/conan_paths.cmake) diff --git a/src/src/PagedFile.cpp b/src/src/PagedFile.cpp index 1cb4842..6123d07 100644 --- a/src/src/PagedFile.cpp +++ b/src/src/PagedFile.cpp @@ -447,7 +447,7 @@ uint64_t PagedFile::ReadPage(uint32_t idx, char *buffer, size_t buffer_size) { // loop until src buffer is exhausted or frame end size_t dst_consumed = 0; - size_t src_left = comp_buffer_.size(); + size_t src_left = desc->length; char *src_buffer = comp_buffer_.data(); while (src_left > 0) { size_t dst_size = buffer_size - dst_consumed; diff --git a/src/src/main.cpp b/src/src/main.cpp index 4afaa7a..f8cda7e 100644 --- a/src/src/main.cpp +++ b/src/src/main.cpp @@ -230,7 +230,10 @@ class PFArchiver { if (max_size > input_buffer.size()) { input_buffer.resize(max_size); } - pf.ReadPage(idx, &input_buffer[0], max_size); + if (!pf.ReadPage(idx, &input_buffer[0], max_size)) { + std::cerr << "Error: failed to read page " << output_path.string() << std::endl; + continue; + } output_length = uncompressed_length; } else { if (page_length > input_buffer.size()) { @@ -456,4 +459,4 @@ int main(int argc, char *argv[]) { std::cout << "No action requested!" << std::endl << visible << std::endl; return 0; -} \ No newline at end of file +}