Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_file/tests/hostile_docx.rs

1.3 KiB, 1 run

created by r1403719401:77639, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! A DOCX list nested past Word's levels. In its own test binary, because before the fix it overflows
2//! the stack and aborts whatever binary it runs in.
3
4use oxedyne_fe2o3_file::{
5 office::docx,
6 zip::{
7 Method,
8 Zip,
9 },
10};
11
12use oxedyne_fe2o3_core::prelude::*;
13use oxedyne_fe2o3_text::doc::{
14 markdown,
15 Block,
16};
17
18fn list_depth(blocks: &[Block]) -> usize {
19 blocks.iter().map(|b| match b {
20 Block::List { items, .. } => 1 + items.iter().map(|i| list_depth(i)).max().unwrap_or(0),
21 _ => 0,
22 }).max().unwrap_or(0)
23}
24
25#[test]
26fn docx_list_level_clamped_to_words_nine() -> Outcome<()> {
27 let (bytes, _) = res!(docx::write(&res!(markdown::parse("x\n"))));
28 let mut body = String::new();
29 for lvl in 0..100_000 {
30 body.push_str(&fmt!("<w:p><w:pPr><w:numPr><w:ilvl w:val=\"{}\"/><w:numId w:val=\"1\"/>\
31 </w:numPr></w:pPr><w:r><w:t>x</w:t></w:r></w:p>", lvl));
32 }
33 let mut zip = res!(Zip::read(bytes));
34 zip.set("word/document.xml", fmt!(
35 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><w:document \
36 xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:body>{}\
37 </w:body></w:document>", body).into_bytes(), Method::Deflate);
38 let doc = res!(docx::read(&res!(zip.write()))).doc;
39 let depth = list_depth(&doc.blocks);
40 assert!(depth <= 9, "a list nested {} deep, past Word's nine levels", depth);
41 Ok(())
42}