From e5ad48368db69db002bcf076720b5912a724d835 Mon Sep 17 00:00:00 2001 From: kiwi4boy Date: Thu, 19 Nov 2026 21:34:54 -0500 Subject: [PATCH] ppt-binary: cap PowerPoint 95 masters lower than slides Each master becomes a copy of the caller's default master with its layouts, so a file listing many masters is held to 256 rather than the slides' 65,536. --- crates/ppt-binary/src/ppt95.rs | 5 ++++- crates/ppt-binary/src/ppt95/tests.rs | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/ppt-binary/src/ppt95.rs b/crates/ppt-binary/src/ppt95.rs index e1757aa95..f44fd5002 100644 --- a/crates/ppt-binary/src/ppt95.rs +++ b/crates/ppt-binary/src/ppt95.rs @@ -40,6 +40,9 @@ const NO_INSTANCE: u32 = 0xFFFF; /// Slides, and masters, read at most: beyond any real presentation, so a file of empty slide /// records can't make an unbounded presentation. const MAX_SLIDES: usize = 1 << 16; +/// Masters read at most. Each becomes a copy of the caller's default master with its layouts, so +/// the cap is lower than for slides; PowerPoint 95 writes one. +const MAX_MASTERS: usize = 256; /// The fill colour's fourth byte when the colour is the RGB given, not a scheme slot. const RGB_GIVEN: u8 = 0xFE; @@ -184,7 +187,7 @@ pub fn convert(document: &Rec, app: &dyn Defaults) -> Presentation { for r in list.children() { match r.kind { rt::SLIDE if slides.len() < MAX_SLIDES => slides.push(page(r)), - rt::MAIN_MASTER if masters.len() < MAX_SLIDES => masters.push(page(r)), + rt::MAIN_MASTER if masters.len() < MAX_MASTERS => masters.push(page(r)), _ => {} } } diff --git a/crates/ppt-binary/src/ppt95/tests.rs b/crates/ppt-binary/src/ppt95/tests.rs index 0a3bd8e0d..530241648 100644 --- a/crates/ppt-binary/src/ppt95/tests.rs +++ b/crates/ppt-binary/src/ppt95/tests.rs @@ -305,6 +305,10 @@ fn hostile_powerpoint_95_streams_never_panic() { let many = vec![empty; super::MAX_SLIDES + 5]; let p = import(&stream_of(document_atom(5760, 4320, 0), &many, &[])).unwrap(); assert_eq!(p.slides.len(), super::MAX_SLIDES); + // Many masters stop at their own, lower limit: each is a copy of the default master. + let masters = vec![master(MASTER, DEFAULT, [0, 0, 0, 0]); super::MAX_MASTERS + 5]; + let p = import(&stream_of(document_atom(5760, 4320, 0), &[], &masters)).unwrap(); + assert_eq!(p.masters.len(), super::MAX_MASTERS); } /// Real PowerPoint 95 files, when `CRAFT_PPT95_SAMPLES` names a directory of them (they are not in