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.
This commit is contained in:
kiwi4boy
2026-11-19 21:34:54 -05:00
parent 7ce48c367d
commit e5ad48368d
2 changed files with 8 additions and 1 deletions
+4 -1
View File
@@ -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)),
_ => {}
}
}
+4
View File
@@ -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