Coverage Report

Created: 2025-07-18 06:52

/src/ttf-parser/fuzz/fuzz_targets/fuzz-variable-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-variable-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, Tag};
22
23
struct Builder(usize);
24
25
impl OutlineBuilder for Builder {
26
    #[inline]
27
69.5k
    fn move_to(&mut self, _: f32, _: f32) {
28
69.5k
        self.0 += 1;
29
69.5k
    }
30
31
    #[inline]
32
1.52M
    fn line_to(&mut self, _: f32, _: f32) {
33
1.52M
        self.0 += 1;
34
1.52M
    }
35
36
    #[inline]
37
1.54M
    fn quad_to(&mut self, _: f32, _: f32, _: f32, _: f32) {
38
1.54M
        self.0 += 2;
39
1.54M
    }
40
41
    #[inline]
42
67.6k
    fn curve_to(&mut self, _: f32, _: f32, _: f32, _: f32, _: f32, _: f32) {
43
67.6k
        self.0 += 3;
44
67.6k
    }
45
46
    #[inline]
47
47.9k
    fn close(&mut self) {
48
47.9k
        self.0 += 1;
49
47.9k
    }
50
}
51
52
fuzz_target!(|data: &[u8]| {
53
    if let Ok(mut face) = Face::parse(data, 0) {
54
        if face.set_variation(Tag::from_bytes(b"wght"), 500.0).is_some() {
55
            for id in 0..face.number_of_glyphs() {
56
                let _ = face.outline_glyph(GlyphId(id), &mut Builder(0));
57
            }
58
        }
59
    }
60
});