From 1ddb079b3352a52b73d37a8a06f6103aae10cc86 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Sun, 24 May 2026 20:38:35 +0200 Subject: [PATCH 1/2] Fix pagelist retrieval oom --- lib/Epub/Epub/parsers/PageListSink.cpp | 50 ++++++++++++++++++++++++ lib/Epub/Epub/parsers/PageListSink.h | 52 +++++++++++++++++++++++++ lib/Epub/Epub/parsers/PageMapParser.cpp | 6 ++- lib/Epub/Epub/parsers/PageMapParser.h | 20 ++++------ lib/Epub/Epub/parsers/TocNavParser.cpp | 9 +++-- lib/Epub/Epub/parsers/TocNavParser.h | 23 ++++------- lib/Epub/Epub/parsers/TocNcxParser.cpp | 5 ++- lib/Epub/Epub/parsers/TocNcxParser.h | 21 ++++------ 8 files changed, 135 insertions(+), 51 deletions(-) create mode 100644 lib/Epub/Epub/parsers/PageListSink.cpp create mode 100644 lib/Epub/Epub/parsers/PageListSink.h diff --git a/lib/Epub/Epub/parsers/PageListSink.cpp b/lib/Epub/Epub/parsers/PageListSink.cpp new file mode 100644 index 00000000..263ccc8f --- /dev/null +++ b/lib/Epub/Epub/parsers/PageListSink.cpp @@ -0,0 +1,50 @@ +#include "PageListSink.h" + +#include +#include + +PageListSink::PageListSink(const std::string& cachePath) : path(cachePath + "/pagelist.bin") { + if (!Storage.openFileForWrite("EBP", path, file)) { + LOG_ERR("EBP", "PageListSink: could not open pagelist.bin for writing"); + return; + } + // Placeholder count; patched in finalize(). + serialization::writePod(file, static_cast(0)); +} + +PageListSink::~PageListSink() { + if (!finalized) { + finalize(); + } +} + +void PageListSink::addEntry(const std::string& href, const std::string& anchor, const std::string& label) { + if (!file.isOpen() || finalized) return; + serialization::writeString(file, href); + serialization::writeString(file, anchor); + serialization::writeString(file, label); + count++; +} + +void PageListSink::finalize() { + if (finalized) return; + finalized = true; + if (!file.isOpen()) return; + + if (count == 0) { + file.close(); + Storage.remove(path.c_str()); + return; + } + + file.flush(); + if (!file.seek(0)) { + LOG_ERR("EBP", "PageListSink: could not seek to patch count"); + file.close(); + return; + } + serialization::writePod(file, count); + file.flush(); + file.close(); + LOG_DBG("EBP", "Wrote pagelist.bin with %u entries", static_cast(count)); +} diff --git a/lib/Epub/Epub/parsers/PageListSink.h b/lib/Epub/Epub/parsers/PageListSink.h new file mode 100644 index 00000000..dea52ac3 --- /dev/null +++ b/lib/Epub/Epub/parsers/PageListSink.h @@ -0,0 +1,52 @@ +#pragma once + +#include + +#include + +// Streams printed-page entries (href, anchor, label) directly to pagelist.bin +// instead of buffering them in a std::vector. Buffering blows the X3 heap on +// books with long EPUB 3