From db0645c1502dc9dc6e8a5f3ea2d16d27ebc0cf11 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 4 Nov 2026 01:47:59 +0000 Subject: [PATCH] address review: check the charge against the remaining ActualText budget --- crates/render/src/text/device.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/render/src/text/device.rs b/crates/render/src/text/device.rs index 457059f68a..57b40620a9 100644 --- a/crates/render/src/text/device.rs +++ b/crates/render/src/text/device.rs @@ -374,7 +374,13 @@ impl<'a> Device<'a> for TextDevice { let raw = text.len(); let text = pdfcraft_cos::PdfString::literal(text).to_text(); // The raw bytes read, or the two copies kept, whichever is more (and never nothing). - self.actual_budget = self.actual_budget.saturating_sub(raw.max(text.len().saturating_mul(2)).max(1)); + let charge = raw.max(text.len().saturating_mul(2)).max(1); + if charge > self.actual_budget { + // too much for what is left: no replacement is opened, and the bytes read are still spent + self.actual_budget = self.actual_budget.saturating_sub(raw.max(1)); + return; + } + self.actual_budget -= charge; self.actual = Some((self.depth, text, Vec::new())); } }