Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
Z
zstd
管理
动态
成员
标记
计划
议题
议题看板
里程碑
Wiki
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
构建
流水线
作业
流水线计划
产物
部署
发布
Package registry
Container registry
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
模型实验
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
Xayah
zstd
提交
188311dd
未验证
提交
188311dd
编辑于
5 years ago
作者:
Nick Terrell
提交者:
GitHub
5 years ago
浏览文件
操作
下载
差异文件
Merge pull request #1736 from terrelln/fuzz-fix
[fuzz] Improve fuzzer build script and docs
上级
69c875a0
3982935a
No related branches found
No related tags found
无相关合并请求
变更
3
隐藏空白变更内容
行内
左右并排
显示
3 个更改的文件
tests/fuzz/Makefile
+0
-9
0 个添加, 9 个删除
tests/fuzz/Makefile
tests/fuzz/README.md
+12
-7
12 个添加, 7 个删除
tests/fuzz/README.md
tests/fuzz/fuzz.py
+36
-17
36 个添加, 17 个删除
tests/fuzz/fuzz.py
有
48 个添加
和
33 个删除
tests/fuzz/Makefile
+
0
−
9
浏览文件 @
188311dd
...
...
@@ -113,15 +113,6 @@ zstd_frame_info: $(FUZZ_HEADERS) $(FUZZ_OBJ) zstd_frame_info.o
libregression.a
:
$(FUZZ_HEADERS) $(PRGDIR)/util.h $(PRGDIR)/util.c regression_driver.o
$(
AR
)
$(
FUZZ_ARFLAGS
)
$@
regression_driver.o
# Install libfuzzer (not usable for MSAN testing)
# Provided for convenience. To use this library run make libFuzzer and
# set LDFLAGS=-L.
.PHONY
:
libFuzzer
libFuzzer
:
@$(
RM
)
-rf
Fuzzer
@
git clone https://chromium.googlesource.com/chromium/llvm-project/compiler-rt/lib/fuzzer Fuzzer
@
cd
Fuzzer
&&
./build.sh
corpora/%_seed_corpus.zip
:
@
mkdir
-p
corpora
$(
DOWNLOAD
)
$@
$(
CORPORA_URL_PREFIX
)
$*
_seed_corpus.zip
...
...
此差异已折叠。
点击以展开。
tests/fuzz/README.md
+
12
−
7
浏览文件 @
188311dd
...
...
@@ -35,6 +35,8 @@ The environment variables can be overridden with the corresponding flags
`--cc`
,
`--cflags`
, etc.
The specific fuzzing engine is selected with
`LIB_FUZZING_ENGINE`
or
`--lib-fuzzing-engine`
, the default is
`libregression.a`
.
Alternatively, you can use Clang's built in fuzzing engine with
`--enable-fuzzer`
.
It has flags that can easily set up sanitizers
`--enable-{a,ub,m}san`
, and
coverage instrumentation
`--enable-coverage`
.
It sets sane defaults which can be overridden with flags
`--debug`
,
...
...
@@ -51,22 +53,25 @@ The command used to run the fuzzer is printed for debugging.
## LibFuzzer
```
# Build libfuzzer if necessary
make libFuzzer
# Build the fuzz targets
./fuzz.py build all --enable-
coverage
--enable-asan --enable-ubsan
--lib-fuzzing-engine Fuzzer/libFuzzer.a
--cc clang --cxx clang++
./fuzz.py build all --enable-
fuzzer
--enable-asan --enable-ubsan --cc clang --cxx clang++
# OR equivalently
CC=clang CXX=clang++
LIB_FUZZING_ENGINE=Fuzzer/libFuzzer.a
./fuzz.py build all --enable-
coverage
--enable-asan --enable-ubsan
CC=clang CXX=clang++ ./fuzz.py build all --enable-
fuzzer
--enable-asan --enable-ubsan
# Run the fuzzer
./fuzz.py libfuzzer TARGET
-max_len=8192
-jobs=4
./fuzz.py libfuzzer TARGET
<libfuzzer args like
-jobs=4
>
```
where
`TARGET`
could be
`simple_decompress`
,
`stream_round_trip`
, etc.
### MSAN
Fuzzing with
`libFuzzer`
and
`MSAN`
will require building a C++ standard library
and libFuzzer with MSAN.
Fuzzing with
`libFuzzer`
and
`MSAN`
is as easy as:
```
CC=clang CXX=clang++ ./fuzz.py build all --enable-fuzzer --enable-msan
./fuzz.py libfuzzer TARGET <libfuzzer args>
```
`fuzz.py`
respects the environment variables / flags
`MSAN_EXTRA_CPPFLAGS`
,
`MSAN_EXTRA_CFLAGS`
,
`MSAN_EXTRA_CXXFLAGS`
,
`MSAN_EXTRA_LDFLAGS`
to easily pass
the extra parameters only for MSAN.
...
...
此差异已折叠。
点击以展开。
tests/fuzz/fuzz.py
+
36
−
17
浏览文件 @
188311dd
...
...
@@ -24,21 +24,38 @@ def abs_join(a, *p):
return
os
.
path
.
abspath
(
os
.
path
.
join
(
a
,
*
p
))
class
InputType
(
object
):
RAW_DATA
=
1
COMPRESSED_DATA
=
2
class
FrameType
(
object
):
ZSTD
=
1
BLOCK
=
2
class
TargetInfo
(
object
):
def
__init__
(
self
,
input_type
,
frame_type
=
FrameType
.
ZSTD
):
self
.
input_type
=
input_type
self
.
frame_type
=
frame_type
# Constants
FUZZ_DIR
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
CORPORA_DIR
=
abs_join
(
FUZZ_DIR
,
'
corpora
'
)
TARGETS
=
[
'
simple_round_trip
'
,
'
stream_round_trip
'
,
'
block_round_trip
'
,
'
simple_decompress
'
,
'
stream_decompress
'
,
'
block_decompress
'
,
'
dictionary_round_trip
'
,
'
dictionary_decompress
'
,
'
zstd_frame_info
'
,
'
simple_compress
'
,
]
TARGET_INFO
=
{
'
simple_round_trip
'
:
TargetInfo
(
InputType
.
RAW_DATA
),
'
stream_round_trip
'
:
TargetInfo
(
InputType
.
RAW_DATA
),
'
block_round_trip
'
:
TargetInfo
(
InputType
.
RAW_DATA
,
FrameType
.
BLOCK
),
'
simple_decompress
'
:
TargetInfo
(
InputType
.
COMPRESSED_DATA
),
'
stream_decompress
'
:
TargetInfo
(
InputType
.
COMPRESSED_DATA
),
'
block_decompress
'
:
TargetInfo
(
InputType
.
COMPRESSED_DATA
,
FrameType
.
BLOCK
),
'
dictionary_round_trip
'
:
TargetInfo
(
InputType
.
RAW_DATA
),
'
dictionary_decompress
'
:
TargetInfo
(
InputType
.
COMPRESSED_DATA
),
'
zstd_frame_info
'
:
TargetInfo
(
InputType
.
COMPRESSED_DATA
),
'
simple_compress
'
:
TargetInfo
(
InputType
.
RAW_DATA
),
}
TARGETS
=
list
(
TARGET_INFO
.
keys
())
ALL_TARGETS
=
TARGETS
+
[
'
all
'
]
FUZZ_RNG_SEED_SIZE
=
4
...
...
@@ -67,7 +84,7 @@ MSAN_EXTRA_LDFLAGS = os.environ.get('MSAN_EXTRA_LDFLAGS', '')
def
create
(
r
):
d
=
os
.
path
.
abspath
(
r
)
if
not
os
.
path
.
isdir
(
d
):
os
.
m
k
dir
(
d
)
os
.
m
ake
dir
s
(
d
)
return
d
...
...
@@ -158,7 +175,7 @@ def compiler_version(cc, cxx):
assert
(
b
'
clang
'
in
cxx_version_bytes
)
compiler
=
'
clang
'
elif
b
'
gcc
'
in
cc_version_bytes
:
assert
(
b
'
gcc
'
in
cxx_version_bytes
)
assert
(
b
'
gcc
'
in
cxx_version_bytes
or
b
'
g++
'
in
cxx_version_bytes
)
compiler
=
'
gcc
'
if
compiler
is
not
None
:
version_regex
=
b
'
([0-9])+\.([0-9])+\.([0-9])+
'
...
...
@@ -699,7 +716,8 @@ def gen(args):
'
-o{}
'
.
format
(
decompressed
),
]
if
'
block_
'
in
args
.
TARGET
:
info
=
TARGET_INFO
[
args
.
TARGET
]
if
info
.
frame_type
==
FrameType
.
BLOCK
:
cmd
+=
[
'
--gen-blocks
'
,
'
--max-block-size-log={}
'
.
format
(
args
.
max_size_log
)
...
...
@@ -710,10 +728,11 @@ def gen(args):
print
(
'
'
.
join
(
cmd
))
subprocess
.
check_call
(
cmd
)
if
'
_round_trip
'
in
args
.
TARGET
:
if
info
.
input_type
==
InputType
.
RAW_DATA
:
print
(
'
using decompressed data in {}
'
.
format
(
decompressed
))
samples
=
decompressed
elif
'
_decompress
'
in
args
.
TARGET
:
else
:
assert
info
.
input_type
==
InputType
.
COMPRESSED_DATA
print
(
'
using compressed data in {}
'
.
format
(
compressed
))
samples
=
compressed
...
...
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录