Coverage Report

Created: 2026-08-13 06:49

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
1.71M
YGFlexDirection fuzzedFlexDirection(FuzzedDataProvider& fdp) {
13
1.71M
  return fdp.PickValueInArray({
14
1.71M
      YGFlexDirectionColumn,
15
1.71M
      YGFlexDirectionColumnReverse,
16
1.71M
      YGFlexDirectionRow,
17
1.71M
      YGFlexDirectionRowReverse,
18
1.71M
  });
19
1.71M
}
20
21
void fillFuzzedTree(
22
    FuzzedDataProvider& fdp,
23
    YGConfigConstRef config,
24
    YGNodeRef root,
25
1.71M
    size_t depth = 0) {
26
1.71M
  constexpr size_t kMaxDepth = 20;
27
1.71M
  constexpr size_t kMaxChildren = 20;
28
29
1.71M
  if (depth > kMaxDepth) {
30
1.30M
    return;
31
1.30M
  }
32
33
405k
  size_t children = fdp.ConsumeIntegralInRange<size_t>(0, kMaxChildren);
34
2.11M
  for (size_t i = 0; i < children; i++) {
35
1.71M
    YGNodeRef child = YGNodeNewWithConfig(config);
36
1.71M
    YGNodeStyleSetFlexDirection(root, fuzzedFlexDirection(fdp));
37
1.71M
    YGNodeStyleSetWidth(child, fdp.ConsumeFloatingPoint<float>());
38
1.71M
    YGNodeStyleSetGap(
39
1.71M
        child, YGGutterAll, fdp.ConsumeProbability<float>() * 100);
40
1.71M
    YGNodeStyleSetHeight(child, fdp.ConsumeFloatingPoint<float>());
41
1.71M
    YGNodeInsertChild(root, child, i);
42
1.71M
    fillFuzzedTree(fdp, config, child, depth + 1);
43
1.71M
  }
44
405k
}
45
46
792
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
47
792
  FuzzedDataProvider fdp(data, size);
48
792
  YGConfigRef config = YGConfigNew();
49
792
  YGNodeRef root = YGNodeNewWithConfig(config);
50
792
  fillFuzzedTree(fdp, config, root);
51
52
792
  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
53
54
792
  YGNodeFreeRecursive(root);
55
792
  YGConfigFree(config);
56
792
  return 0;
57
792
}