Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 52 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ repository = "https://github.com/easy-4-rust/easydoc-rust"
[workspace.dependencies]
base64 = "0.23"
chrono = { version = "0.4.45", default-features = false, features = ["std"] }
docx-rs = "0.4"
office_oxide = "0.1"
# Upstream zip 9 compatibility fix; crates.io 0.4.22 still requires vulnerable zip 8.
docx-rs = { git = "https://github.com/bokuweb/docx-rs.git", rev = "ad7fede6a7f3b61a097c28d0c39dd04626e44701" }
office_oxide = "0.1.16"
proc-macro-crate = "3.5.0"
proc-macro2 = "1.0.107"
quote = "1.0.47"
Expand All @@ -34,7 +35,7 @@ syn = { version = "3.0.3", features = ["full"] }
tempfile = "3.27.0"
thiserror = "2.0.18"
uuid = { version = "1.24.0", features = ["v4"] }
zip = { version = "8.6.0", default-features = false, features = ["deflate"] }
zip = { version = "9.0.4", default-features = false, features = ["deflate"] }
quick-xml = "0.42"
anyhow = "1"
tracing = "0.1"
Expand Down
6 changes: 3 additions & 3 deletions crates/easydoc-ooxml/src/package_rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl PackageRewriter {
let mut writer = zip::ZipWriter::new(file);
for index in 0..archive.len() {
let mut entry = archive.by_index(index)?;
let name = entry.name().to_owned();
let name = entry.name()?.into_owned();
let options = entry_options(&entry);
if entry.is_dir() {
writer.add_directory(name, options)?;
Expand Down Expand Up @@ -77,7 +77,7 @@ impl PackageRewriter {
if size > self.limits.max_entry_bytes {
return Err(DocError::Format(format!(
"OOXML entry '{}' expands to {size} bytes, limit is {}",
entry.name(),
entry.name()?,
self.limits.max_entry_bytes
)));
}
Expand All @@ -94,7 +94,7 @@ impl PackageRewriter {
if compressed > 0 && size / compressed.max(1) > self.limits.max_compression_ratio {
return Err(DocError::Format(format!(
"OOXML entry '{}' exceeds compression ratio limit {}",
entry.name(),
entry.name()?,
self.limits.max_compression_ratio
)));
}
Expand Down
26 changes: 24 additions & 2 deletions crates/easydoc-reader/src/extractor/sax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ impl<R: Read> DocxSaxReader<R> {
// bytes for every event (start tags, text, end tags, etc.).
if in_math {
match &event {
Event::Eof => {
return Err(DocError::Format(
"unexpected EOF inside OMML math element".to_owned(),
));
}
Event::Start(start) => {
let name = start.name();
let name_bytes = name.as_ref();
Expand Down Expand Up @@ -1546,8 +1551,9 @@ fn find_word_document_xml(archive: &mut zip::ZipArchive<File>) -> Result<String>
let entry = archive
.by_index(i)
.map_err(|e| DocError::Zip(e.to_string()))?;
if entry.name().to_lowercase() == "word/document.xml" {
return Ok(entry.name().to_owned());
let name = entry.name().map_err(|e| DocError::Zip(e.to_string()))?;
if name.eq_ignore_ascii_case("word/document.xml") {
return Ok(name.into_owned());
}
}
Err(DocError::Format(
Expand Down Expand Up @@ -2577,6 +2583,22 @@ mod tests {
// OMML math tests
// -----------------------------------------------------------------------

#[test]
fn truncated_math_returns_error() {
// The third input is the 139-byte timeout artifact from fuzz_docx_xml
// run 41032275317 (SHA-256 f1652dd030e76af6d8f5d2892574cbd28b5fc74f4b780b10).
for xml in [
&b"<m:oMath><m:r>"[..],
&b"<m:oMathPara><m:oMath><m:r/>"[..],
&include_bytes!(
"../../tests/fixtures/timeout-cfd00ebb9a65446aa85f3d4a8185c3a800afdc4e"
)[..],
] {
let mut reader = DocxSaxReader::from_reader(xml);
assert!(reader.read_blocks().is_err());
}
}

#[test]
fn inline_math_in_paragraph() {
// Single <m:oMath> inside a <w:p> with surrounding text.
Expand Down
2 changes: 1 addition & 1 deletion crates/easydoc-reader/src/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl PackageLimits {

for i in 0..len {
let entry = archive.by_index(i).map_err(|e| e.to_string())?;
let name = entry.name();
let name = entry.name().map_err(|e| e.to_string())?;

if name.len() > self.max_filename_len {
return Err(format!(
Expand Down
Binary file not shown.
4 changes: 3 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ skip-tree = []
unknown-registry = "deny"
unknown-git = "deny"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
allow-git = []
# docx-rs has the zip 9 fix upstream, but no crates.io release yet. Cargo.toml
# pins the exact upstream commit; no other Git dependency is allowed.
allow-git = ["https://github.com/bokuweb/docx-rs.git"]
Loading
Loading