aboutsummaryrefslogtreecommitdiff
path: root/fuzz/fuzz_targets/instruction_text_buffer_size_ok.rs
blob: 2c88424ec6357d010ea9958c8ee60557de0ec07d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate yaxpeax_x86;
extern crate yaxpeax_arch;

use std::fmt::Write;

fuzz_target!(|data: &[u8]| {
    let x86_64_decoder = yaxpeax_x86::long_mode::InstDecoder::default();
    let x86_32_decoder = yaxpeax_x86::protected_mode::InstDecoder::default();
    let x86_16_decoder = yaxpeax_x86::real_mode::InstDecoder::default();

    if let Ok(inst) = x86_64_decoder.decode_slice(data) {
        use yaxpeax_x86::long_mode::DisplayStyle;

        let mut s = String::new();
        write!(s, "{}", inst.display_with(DisplayStyle::Intel)).expect("can write");
        // MAX_INSTRUCTION_LEN is not a public crate item yet...
        assert!(s.len() < 512);
        s.clear();
        write!(s, "{}", inst.display_with(DisplayStyle::C)).expect("can write");
        // MAX_INSTRUCTION_LEN is not a public crate item yet...
        assert!(s.len() < 512);
    };

    if let Ok(inst) = x86_32_decoder.decode_slice(data) {
        use yaxpeax_x86::protected_mode::DisplayStyle;

        let mut s = String::new();
        write!(s, "{}", inst.display_with(DisplayStyle::Intel)).expect("can write");
        // MAX_INSTRUCTION_LEN is not a public crate item yet...
        assert!(s.len() < 512);
        s.clear();
        write!(s, "{}", inst.display_with(DisplayStyle::C)).expect("can write");
        // MAX_INSTRUCTION_LEN is not a public crate item yet...
        assert!(s.len() < 512);
    };

    if let Ok(inst) = x86_16_decoder.decode_slice(data) {
        use yaxpeax_x86::real_mode::DisplayStyle;

        let mut s = String::new();
        write!(s, "{}", inst.display_with(DisplayStyle::Intel)).expect("can write");
        // MAX_INSTRUCTION_LEN is not a public crate item yet...
        assert!(s.len() < 512);
        s.clear();
        write!(s, "{}", inst.display_with(DisplayStyle::C)).expect("can write");
        // MAX_INSTRUCTION_LEN is not a public crate item yet...
        assert!(s.len() < 512);
    };
});