Skip to content
Merged
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
15 changes: 15 additions & 0 deletions crates/graphicle/src/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ fn bounded(text: String) -> Result<String> {
"No readable text was extracted; OCR may be required",
));
}
// A converter emits a NUL for a glyph with no Unicode mapping; the store refuses text with one.
if text.contains('\0') {
return Err(Error::bad("Extracted text contains a NUL character"));
}
Ok(text)
}
pub fn xml_text(bytes: &[u8]) -> Result<String> {
Expand Down Expand Up @@ -712,3 +716,14 @@ impl Store {
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn extracted_text_with_a_nul_is_refused() {
let error = bounded("before\u{0}after".to_string()).unwrap_err();
assert!(error.message.contains("NUL"), "{error:?}");
}
}
Loading