From e84840b4732d6ab08b659b3a18e434b049373784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20B=C3=ACnh=20An?= <111893501+brianhuster@users.noreply.github.com> Date: Tue, 14 Jul 2026 21:00:13 +0700 Subject: [PATCH] fix(css-parser): don't save unusable rules to RAM (#2604) --- lib/Epub/Epub/css/CssParser.cpp | 5 +++++ lib/Epub/Epub/css/CssParser.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Epub/Epub/css/CssParser.cpp b/lib/Epub/Epub/css/CssParser.cpp index 77ee8e77..64939fc8 100644 --- a/lib/Epub/Epub/css/CssParser.cpp +++ b/lib/Epub/Epub/css/CssParser.cpp @@ -431,6 +431,11 @@ CssStyle CssParser::parseDeclarations(std::string_view declBlock) { // Rule processing void CssParser::processRuleBlockWithStyle(std::string_view selectorGroup, const CssStyle& style) { + // Skip rules that don't define any supported properties to save RAM. + if (!style.defined.anySet()) { + return; + } + // Check if we've reached the rule limit before processing if (rulesBySelector_.size() >= MAX_RULES) { LOG_DBG("CSS", "Reached max rules limit (%zu), stopping CSS parsing", MAX_RULES); diff --git a/lib/Epub/Epub/css/CssParser.h b/lib/Epub/Epub/css/CssParser.h index 41797fd3..892216b3 100644 --- a/lib/Epub/Epub/css/CssParser.h +++ b/lib/Epub/Epub/css/CssParser.h @@ -33,7 +33,7 @@ class CssParser { public: // Bump when CSS cache format or rules change; section caches are invalidated when this changes - static constexpr uint8_t CSS_CACHE_VERSION = 7; + static constexpr uint8_t CSS_CACHE_VERSION = 8; explicit CssParser(std::string cachePath) : cachePath(std::move(cachePath)) {} ~CssParser() = default;