Skip to content

Commit cf688d4

Browse files
authored
Merge branch 'master' into fix-compile-native-go-fuzzer-v2-multiple-matches
2 parents c2219f0 + 88d8897 commit cf688d4

File tree

464 files changed

+3258
-2150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

464 files changed

+3258
-2150
lines changed

AGENTS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* Use python3 infra/helper.py to build projects and run fuzzers.
2+
* If doing development on infra/ you should use a venv and if it doesn't already exist, install deps from infra/ci/requirements.txt build/functions/requirements.txt with pip.
3+
* If doing development on infra/ run python infra/presubmit.py to format, lint and run tests.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ the one above, the
2727

2828
### Requesting a review
2929
PRs should be reviewed within a few days by the OSS-Fuzz oncall. There is no need to add anyone to review your code.
30-
If for some reason this does not happen for a few days, feel free to add @jonathanmetzman or email oss-fuzz-team@google.com
30+
If for some reason this does not happen for a few days, feel free to add a team member or email oss-fuzz-team@google.com
3131
about your PR.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ execution environment and reporting tool.
3232
[ClusterFuzz]: https://github.com/google/clusterfuzz
3333
[ClusterFuzzLite]: https://google.github.io/clusterfuzzlite/
3434

35-
Currently, OSS-Fuzz supports C/C++, Rust, Go, Python, Java/JVM, and JavaScript code. Other languages
35+
Currently, OSS-Fuzz supports C/C++, Rust, Go, Python, Java/JVM, JavaScript and Lua code. Other languages
3636
supported by [LLVM] may work too. OSS-Fuzz supports fuzzing x86_64 and i386
3737
builds.
3838

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
---
2+
layout: default
3+
title: Integrating a Lua project
4+
parent: Setting up a new project
5+
grand_parent: Getting started
6+
nav_order: 4
7+
permalink: /getting-started/new-project-guide/lua-lang/
8+
---
9+
10+
# Integrating a Lua project
11+
{: .no_toc}
12+
13+
- TOC
14+
{:toc}
15+
---
16+
17+
The process of integrating a project written in Lua with OSS-Fuzz
18+
is similar to the general [Setting up a new project]({{ site.baseurl
19+
}}/getting-started/new-project-guide/) process. The key specifics of
20+
integrating a Lua project are outlined below.
21+
22+
## luzer
23+
24+
Lua fuzzing in OSS-Fuzz is powered by
25+
[luzer](https://github.com/ligurio/luzer). As luzer operates
26+
directly on the Lua source code level, it can be applied to any
27+
project written in a language that can be transpiled into Lua,
28+
such as [MoonScript](https://moonscript.org/),
29+
[TypeScriptToLua](https://typescripttolua.github.io/),
30+
[Fennel](https://fennel-lang.org/), and [Urn](https://urn-lang.com/).
31+
Also, it supports fuzzing C/C++ extensions written for Lua. When
32+
fuzzing native code, luzer can be used in combination with
33+
Address Sanitizer or Undefined Behavior Sanitizer to catch extra bugs.
34+
35+
## Project files
36+
37+
### Example project
38+
39+
We recommend viewing
40+
[lua-example](https://github.com/google/oss-fuzz/tree/master/projects/lua-example)
41+
as an example of a simple Lua fuzzing project. This example also
42+
demonstrates how to use luzer's Fuzzed Data Provider.
43+
44+
### project.yaml
45+
46+
The `language` attribute must be specified as follows:
47+
48+
```yaml
49+
language: c
50+
```
51+
52+
The only supported fuzzing engine is libFuzzer (`libfuzzer`).
53+
54+
```yaml
55+
fuzzing_engines:
56+
- libfuzzer
57+
sanitizers:
58+
- none
59+
```
60+
61+
There is nothing special for sanitizer support in OSS-Fuzz
62+
infrastructure. luzer builds its own DSO with libFuzzer and
63+
sanitizer and `compile_lua_fuzzer` (also managed by project) sets
64+
it to `LD_PRELOAD` if required.
65+
66+
### Dockerfile
67+
68+
The Dockerfile should start by `FROM gcr.io/oss-fuzz-base/base-builder`.
69+
70+
The OSS-Fuzz base Docker images come without any pre-installed
71+
components required for Lua fuzzing. Apart from that, you should
72+
usually need to build or install a Lua runtime, luzer module,
73+
clone the project, set a `WORKDIR`, and copy any necessary files,
74+
or install any project-specific dependencies here as you normally would.
75+
76+
### Fuzzers
77+
78+
In the simplest case, every fuzzer consists of a single Lua file that defines
79+
a function `TestOneInput` and executes a function named `luzer.Fuzz()`.
80+
An example fuzz target could thus be a file `fuzz_basic.lua` with contents:
81+
82+
```lua
83+
local parser = require("src.luacheck.parser")
84+
local decoder = require("luacheck.decoder")
85+
local luzer = require("luzer")
86+
87+
local function TestOneInput(buf)
88+
parser.parse(decoder.decode(buf))
89+
end
90+
91+
local args = {
92+
print_final_stats = 1,
93+
}
94+
luzer.Fuzz(TestOneInput, nil, args)
95+
```
96+
97+
### compile_lua_fuzzer
98+
99+
Unlike projects for other languages, the base image does not
100+
include a script that generates a wrapper script that can be used
101+
as a drop-in replacement for libFuzzer.
102+
103+
Therefore, you need to add such a script yourself. This script
104+
sets a relative path to Lua runtime that will be used for running
105+
tests and the necessary environment variables (for example, `LUA_PATH`,
106+
`LUA_CPATH` and `LD_PRELOAD`) and specifies the path directly to
107+
the `.lua` file containing the test implementation. The script
108+
`compile_lua_fuzzer` must accept the same command line flags as
109+
libFuzzer-based tests.
110+
111+
Note, the resulting wrapper scripts must contain the word "luarocks"
112+
to pass checks by `bad_build_check` in continuous integration.
113+
114+
Then, you can use the script `compile_lua_fuzzer` to build the fuzzers.
115+
A usage example from the `lua-example` project is
116+
117+
```shell
118+
compile_lua_fuzzer lua fuzz_basic.lua
119+
```
120+
121+
Arguments are:
122+
123+
* a relative path to a Lua runtime name
124+
* a relative path to the fuzzing test inside the OSS Fuzz project directory
125+
126+
The `lua-example` projects includes an
127+
[example](https://github.com/google/oss-fuzz/blob/master/projects/lua-example/compile_lua_fuzzer)
128+
of such script.
129+
130+
### build.sh
131+
132+
The script is executed within the image built from your [Dockerfile](#Dockerfile).
133+
134+
In general, this script should do the following:
135+
136+
- Set up or build a Lua runtime.
137+
- Set up or build required dependencies for your tests.
138+
- Generate wrapper scripts for your tests using [compile_lua_fuzzer](#compile_lua_fuzzer).
139+
140+
Resulting binaries, tests and their wrapper scripts, and a
141+
directory with Luarocks dependencies should be placed in `$OUT`.
142+
143+
Beware, when installing the luzer module, you need to set the
144+
environment variable `OSS_FUZZ` to non-empty value, otherwise the
145+
build may fail.
146+
147+
The [lua-example](https://github.com/google/oss-fuzz/blob/master/projects/lua-example/build.sh)
148+
project contains an example of a `build.sh` for a Lua projects.
149+
150+
## FuzzedDataProvider
151+
152+
luzer provides a Fuzzed Data Provider that is helpful for splitting
153+
a fuzz input into multiple parts of various Lua types. Its
154+
functionality is similar to
155+
[Fuzzed Data Provider](https://github.com/google/fuzzing/blob/master/docs/split-inputs.md#fuzzed-data-provider)
156+
available in LLVM. Learn about methods, provided by FDP in luzer,
157+
in [documentation](https://github.com/ligurio/luzer/blob/master/docs/api.md#structure-aware-fuzzing).
158+
159+
A fuzz target using the `FuzzedDataProvider` would look as follows:
160+
161+
```lua
162+
local luzer = require("luzer")
163+
164+
local function TestOneInput(buf)
165+
local fdp = luzer.FuzzedDataProvider(buf)
166+
local str = fdp:consume_string(4)
167+
168+
local b = {}
169+
str:gsub(".", function(c) table.insert(b, c) end)
170+
local count = 0
171+
if b[1] == "o" then count = count + 1 end
172+
if b[2] == "o" then count = count + 1 end
173+
if b[3] == "p" then count = count + 1 end
174+
if b[4] == "s" then count = count + 1 end
175+
176+
if count == 4 then assert(nil) end
177+
end
178+
179+
local args = {
180+
only_ascii = 1,
181+
print_pcs = 1,
182+
}
183+
184+
luzer.Fuzz(TestOneInput, nil, args)
185+
```

docs/getting-started/new_project_guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Programming language the project is written in. Values you can specify include:
102102
* [`jvm` (Java, Kotlin, Scala and other JVM-based languages)]({{ site.baseurl }}//getting-started/new-project-guide/jvm-lang/)
103103
* [`swift`]({{ site.baseurl }}//getting-started/new-project-guide/swift-lang/)
104104
* [`javascript`]({{ site.baseurl }}//getting-started/new-project-guide/javascript-lang/)
105+
* [`lua`]({{ site.baseurl }}//getting-started/new-project-guide/lua-lang/)
105106

106107
### primary_contact, auto_ccs {#primary}
107108
The primary contact and list of other contacts to be CCed. Each person listed gets access to ClusterFuzz, including crash reports and fuzzer statistics, and are auto-cced on new bugs filed in the OSS-Fuzz

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ execution environment and reporting tool.
4242
[ClusterFuzz]: https://github.com/google/clusterfuzz
4343
[ClusterFuzzLite]: https://google.github.io/clusterfuzzlite/
4444

45-
Currently, OSS-Fuzz supports C/C++, Rust, Go, Python and Java/JVM code. Other
46-
languages supported by [LLVM] may work too. OSS-Fuzz supports fuzzing x86_64
45+
Currently, OSS-Fuzz supports C/C++, Rust, Go, Python, Java/JVM code, JavaScript
46+
and Lua. Other languages supported by [LLVM] may work too. OSS-Fuzz supports fuzzing x86_64
4747
and i386 builds.
4848

4949
[LLVM]: https://llvm.org

infra/base-images/base-builder-swift/llvmsymbol.diff

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ diff --git a/llvm/lib/DebugInfo/Symbolize/CMakeLists.txt b/llvm/lib/DebugInfo/Sy
22
index acfb3bd0e..a499ee2e0 100644
33
--- a/llvm/lib/DebugInfo/Symbolize/CMakeLists.txt
44
+++ b/llvm/lib/DebugInfo/Symbolize/CMakeLists.txt
5-
@@ -12,4 +12,11 @@ add_llvm_component_library(LLVMSymbolize
5+
@@ -12,4 +12,8 @@ add_llvm_component_library(LLVMSymbolize
66
Object
77
Support
88
Demangle
99
- )
1010
+
1111
+ LINK_LIBS
1212
+ /usr/lib/swift_static/linux/libswiftCore.a
13-
+ /usr/lib/swift_static/linux/libicui18nswift.a
14-
+ /usr/lib/swift_static/linux/libicuucswift.a
15-
+ /usr/lib/swift_static/linux/libicudataswift.a
1613
+ /usr/lib/x86_64-linux-gnu/libstdc++.so.6
1714
+)
1815
diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp

infra/base-images/base-builder-swift/ubuntu-20-04.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616

1717
FROM gcr.io/oss-fuzz-base/base-builder:ubuntu-20-04
1818

19-
RUN install_swift_ubuntu_20_04.sh
19+
RUN install_swift_ubuntu-20-04.sh
2020

2121
COPY precompile_swift /usr/local/bin/

infra/base-images/base-builder-swift/ubuntu-24-04.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
FROM gcr.io/oss-fuzz-base/base-builder:ubuntu-24-04
1818

1919
COPY llvmsymbol.diff /src/
20-
RUN install_swift_ubuntu_24_04.sh
20+
RUN install_swift_ubuntu-24-04.sh
2121

2222
COPY precompile_swift /usr/local/bin/

infra/base-images/base-builder/indexer/clang_wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ def load_cdbs(directory: Path) -> Iterator[tuple[Path, dict[str, Any]]]:
540540
if output_path in existing_output_files:
541541
# Remove existing entry for the output file.
542542
os.unlink(existing_output_files[output_path])
543+
del existing_output_files[output_path]
543544

544545
shutil.copy2(file, merged_cdb_path / file.name)
545546

0 commit comments

Comments
 (0)