diff --git a/crates/graphicle/src/documents.rs b/crates/graphicle/src/documents.rs index db4ace2..a711ca2 100644 --- a/crates/graphicle/src/documents.rs +++ b/crates/graphicle/src/documents.rs @@ -96,6 +96,10 @@ fn bounded(text: String) -> Result { "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 { @@ -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:?}"); + } +}