pdf: an inline image just under usize::MAX bytes doesn't overflow its end offset

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-16 17:36:11 +07:00
co-authored by Claude Opus 5.5
parent 5e18a7fd92
commit 183fe652e4
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -515,7 +515,7 @@ impl<'a> Interp<'a> {
&& (p + 2 == data.len() || crate::object::is_white(data[p + 2]))
};
let end = match crate::image::inline_len(self.file, &d, Some(res)) {
Some(len) => (start + len).min(data.len()),
Some(len) => start.saturating_add(len).min(data.len()),
None => {
let mut p = start;
while p + 1 < data.len() && !is_ei(p) {
+5
View File
@@ -276,6 +276,11 @@ fn inline_image_with_absurd_dimensions_falls_back_to_ei_scan() {
let doc = parse(&bytes).unwrap();
let _ = render(&doc);
assert!(!doc.skipped.is_empty());
// A length just under `usize::MAX` passes the row math; past byte 4096 of the content the
// caller's `start + len` would then overflow.
let content = format!("{}q 10 0 0 10 0 0 cm BI /W 2305843009213693440 /H 8 /CS /G /BPC 8 ID EI Q", " ".repeat(5000));
let doc = parse(&page_pdf(&content, "", vec![])).unwrap();
let _ = render(&doc);
}
#[test]