Coverage Report

Created: 2026-01-07 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/yoga/fuzz/FuzzLayout.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 *
4
 * This source code is licensed under the MIT license found in the
5
 * LICENSE file in the root directory of this source tree.
6
 */
7
8
#include <fuzzer/FuzzedDataProvider.h>
9
#include <yoga/Yoga.h>
10
#include <cstdint>
11
12
3.11M
YGFlexDirection fuzzedFlexDirection(FuzzedDataProvider& fdp) {
13
3.11M
  return fdp.PickValueInArray({
14
3.11M
      YGFlexDirectionColumn,
15
3.11M
      YGFlexDirectionColumnReverse,
16
3.11M
      YGFlexDirectionRow,
17
3.11M
      YGFlexDirectionRowReverse,
18
3.11M
  });
19
3.11M
}
20
21
void fillFuzzedTree(
22
    FuzzedDataProvider& fdp,
23
    YGConfigConstRef config,
24
    YGNodeRef root,
25
3.11M
    size_t depth = 0) {
26
3.11M
  constexpr size_t kMaxDepth = 20;
27
3.11M
  constexpr size_t kMaxChildren = 20;
28
29
3.11M
  if (depth > kMaxDepth) {
30
2.56M
    return;
31
2.56M
  }
32
33
549k
  size_t children = fdp.ConsumeIntegralInRange<size_t>(0, kMaxChildren);
34
3.66M
  for (size_t i = 0; i < children; i++) {
35
3.11M
    YGNodeRef child = YGNodeNewWithConfig(config);
36
3.11M
    YGNodeStyleSetFlexDirection(root, fuzzedFlexDirection(fdp));
37
3.11M
    YGNodeStyleSetWidth(child, fdp.ConsumeFloatingPoint<float>());
38
3.11M
    YGNodeStyleSetGap(
39
3.11M
        child, YGGutterAll, fdp.ConsumeProbability<float>() * 100);
40
3.11M
    YGNodeStyleSetHeight(child, fdp.ConsumeFloatingPoint<float>());
41
3.11M
    YGNodeInsertChild(root, child, i);
42
3.11M
    fillFuzzedTree(fdp, config, child, depth + 1);
43
3.11M
  }
44
549k
}
45
46
1.03k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
47
1.03k
  FuzzedDataProvider fdp(data, size);
48
1.03k
  YGConfigRef config = YGConfigNew();
49
1.03k
  YGNodeRef root = YGNodeNewWithConfig(config);
50
1.03k
  fillFuzzedTree(fdp, config, root);
51
52
1.03k
  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
53
54
1.03k
  YGNodeFreeRecursive(root);
55
1.03k
  YGConfigFree(config);
56
1.03k
  return 0;
57
1.03k
}