Coverage Report

Created: 2025-08-29 06:45

/src/ttf-parser/fuzz/fuzz_targets/fuzz-outline.rs
Line
Count
Source
1
// Copyright 2025 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
// Transformed from ttf-parser/testing-tools/ttf-fuzz/src/fuzz-outline.rs
16
// for LibFuzzer and Cargo-Fuzz compatibility 
17
18
#![no_main]
19
20
use libfuzzer_sys::fuzz_target;
21
use ttf_parser::{Face, GlyphId, OutlineBuilder};
22
23
struct Builder(usize);
24
25
impl OutlineBuilder for Builder {
26
    #[inline]
27
124k
    fn move_to(&mut self, _: f32, _: f32) {
28
124k
        self.0 += 1;
29
124k
    }
30
31
    #[inline]
32
2.54M
    fn line_to(&mut self, _: f32, _: f32) {
33
2.54M
        self.0 += 1;
34
2.54M
    }
35
36
    #[inline]
37
622k
    fn quad_to(&mut self, _: f32, _: f32, _: f32, _: f32) {
38
622k
        self.0 += 2;
39
622k
    }
40
41
    #[inline]
42
296k
    fn curve_to(&mut self, _: f32, _: f32, _: f32, _: f32, _: f32, _: f32) {
43
296k
        self.0 += 3;
44
296k
    }
45
46
    #[inline]
47
76.0k
    fn close(&mut self) {
48
76.0k
        self.0 += 1;
49
76.0k
    }
50
}
51
52
fuzz_target!(|data: &[u8]| {
53
    if let Ok(face) = Face::parse(data, 0) {
54
        for id in 0..face.number_of_glyphs() {
55
            let _ = face.outline_glyph(GlyphId(id), &mut Builder(0));
56
        }
57
    }
58
});