| 1 | #![no_main] |
| 2 | |
| 3 | use canvas::{ |
| 4 | document::TextDocument, |
| 5 | editor::{CanvasEditor, Clip}, |
| 6 | layout::TextEngine, |
| 7 | }; |
| 8 | use libfuzzer_sys::fuzz_target; |
| 9 | use onestore::{document::Format, page::text::Paragraph}; |
| 10 | use std::cell::RefCell; |
| 11 | |
| 12 | thread_local! { |
| 13 | static ENGINE: RefCell<TextEngine> = RefCell::new(TextEngine::default()); |
| 14 | } |
| 15 | |
| 16 | fuzz_target!(|bytes: &[u8]| { |
| 17 | if let Ok(text) = serde_json::from_slice::<Paragraph>(bytes) { |
| 18 | let _ = text.project(); |
| 19 | let _ = text.format_at(0); |
| 20 | } |
| 21 | if let Ok(json) = std::str::from_utf8(bytes) |
| 22 | && let Some(clip) = Clip::decode(json) |
| 23 | { |
| 24 | let _ = clip.text(); |
| 25 | ENGINE.with_borrow_mut(|engine| { |
| 26 | let document = |
| 27 | TextDocument::new(vec![Paragraph::new(String::new(), Format::default())]).unwrap(); |
| 28 | let mut editor = CanvasEditor::new(engine, document, 400.0).unwrap(); |
| 29 | let _ = editor.paste_clip(engine, clip); |
| 30 | }); |
| 31 | } |
| 32 | }); |