Skip to content

Commit f15f0d4

Browse files
committed
cfl: support luzer-based tests
See also google/oss-fuzz#14656 See also google/oss-fuzz#14859 See also tarantool/tarantool#11250
1 parent af2bc03 commit f15f0d4

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

.clusterfuzzlite/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ COPY . $SRC/lunapark
1414
WORKDIR $SRC/lunapark
1515
RUN git clone --depth 1 --branch cfl https://github.com/ligurio/lunapark-corpus corpus
1616
COPY .clusterfuzzlite/build.sh $SRC/
17+
COPY .clusterfuzzlite/compile_lua_fuzzer $SRC/

.clusterfuzzlite/build.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ esac
2929
cmake_args=(
3030
-DUSE_LUAJIT=ON
3131
-DOSS_FUZZ=ON
32+
-DENABLE_LAPI_TESTS=ON
3233
$SANITIZERS_ARGS
3334

3435
# C compiler
@@ -87,3 +88,55 @@ do
8788
zip -urj $OUT/"$name"_seed_corpus.zip "$options_path"
8889
fi
8990
done
91+
92+
# Code coverage is not supported.
93+
if [[ "$SANITIZER" == "coverage" ]]; then
94+
exit
95+
fi
96+
97+
LUA_RUNTIME_NAME=luajit
98+
LUAJIT_PATH=build/luajit-v2.1/source/src/$LUA_RUNTIME_NAME
99+
LUA_MODULES_DIR=lua_modules
100+
101+
apt install -y luarocks liblua5.1-0 liblua5.1-0-dev liblua5.1-0-dbg lua5.1
102+
103+
# Required by luzer installed using luarocks.
104+
export OSS_FUZZ=1
105+
luarocks install --lua-version 5.1 --server=https://luarocks.org/dev --tree=$LUA_MODULES_DIR luzer
106+
unset OSS_FUZZ
107+
108+
cp tests/lapi/lib.lua $OUT
109+
110+
LUZER_TESTS_DIR="tests/lapi/"
111+
# Generating test wrappers for luzer-based tests.
112+
for test_path in $(find $LUZER_TESTS_DIR -name "*_test.lua" -type f);
113+
do
114+
test_file=$(basename $test_path);
115+
test_name_we="${test_file%.*}";
116+
# The following tests made for the functions that unsupported by
117+
# LuaJIT.
118+
if [[ $test_name_we == "math_tointeger_test" ||
119+
$test_name_we == "math_ult_test" ||
120+
$test_name_we == "string_pack_test" ||
121+
$test_name_we == "string_packsize_test" ||
122+
$test_name_we == "string_unpack_test" ||
123+
$test_name_we == "table_pack_test" ||
124+
$test_name_we == "utf8_char_test" ||
125+
$test_name_we == "utf8_codepoint_test" ||
126+
$test_name_we == "utf8_codes_test" ||
127+
$test_name_we == "utf8_len_test" ||
128+
$test_name_we == "utf8_offset_test" ]]; then
129+
continue
130+
fi
131+
module_name=$(echo $test_name_we | sed 's/_test//' )
132+
"$SRC/compile_lua_fuzzer" "$LUA_RUNTIME_NAME" $test_file
133+
cp "$test_path" "$OUT/"
134+
corpus_dir="corpus/corpus/$test_name_we"
135+
if [ -e "$corpus_dir" ]; then
136+
zip -j $OUT/"$test_name_we"_seed_corpus.zip $corpus_dir/*
137+
echo "Build corpus '$OUT/"$test_name_we"_seed_corpus.zip' for the test '$test_name_we'"
138+
fi
139+
done
140+
141+
cp $LUAJIT_PATH "$OUT/$LUA_RUNTIME_NAME"
142+
cp -R $LUA_MODULES_DIR "$OUT/"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash -eu
2+
# Copyright 2026 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
################################################################################
17+
18+
# The Lua runtime name.
19+
lua_runtime=$1
20+
# Path to the fuzz target source file relative to the project's root.
21+
fuzz_target=$2
22+
23+
fuzzer_basename=$(basename -s .lua "$fuzz_target")
24+
25+
# Create an execution wrapper that executes luzer with the correct
26+
# arguments.
27+
echo "#!/bin/bash
28+
29+
set -eu
30+
31+
# LLVMFuzzerTestOneInput so that the wrapper script is recognized
32+
# as a fuzz target for 'check_build'.
33+
project_dir=\$(dirname \$(realpath \"\$0\"))
34+
eval \$(luarocks --lua-version 5.1 --tree \$project_dir/lua_modules path)
35+
export LUA_PATH=\"\$project_dir/?.lua;\$LUA_PATH\"
36+
ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$project_dir/llvm-symbolizer:detect_leaks=0 \
37+
\$project_dir/$lua_runtime \$project_dir/$fuzz_target \$@" > "$OUT/$fuzzer_basename"
38+
39+
chmod +x "$OUT/$fuzzer_basename"

0 commit comments

Comments
 (0)