Skip to content

Commit c9d58d8

Browse files
committed
add fuzzing and interop tests: they all pass
1 parent afac0f4 commit c9d58d8

16,284 files changed

Lines changed: 6963 additions & 60 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,4 @@ mruby
5858
.cache
5959
build_config.rb.lock
6060
compile_commands.json
61-
/test.rb
62-
test2.rb
63-
twitter.json
61+
findings

build_config.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ def for_windows?
1212
conf.cc.defines << 'MRB_UTF8_STRING'
1313
conf.cxx.defines << 'MRB_UTF8_STRING'
1414
conf.enable_test
15-
conf.gembox 'default'
15+
conf.gem core: 'mruby-bigint'
16+
conf.gem core: 'mruby-bin-mruby'
1617
#conf.cc.flags << '-O3' << '-march=native'
1718
#conf.cxx.flags << '-O3' << '-march=native'
1819
conf.gem github: 'Asmod4n/mruby-benchmark-plus', branch: "main"

fuzz/Rakefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'rake'
2+
require 'fileutils'
3+
4+
MRUBY_CONFIG_PATH = File.expand_path(ENV["MRUBY_CONFIG"] || "build_config.rb")
5+
6+
file :mruby do
7+
unless File.directory?('mruby')
8+
sh "git clone --depth=1 https://github.com/mruby/mruby.git"
9+
end
10+
end
11+
12+
desc "compile binary"
13+
task :compile => :mruby do
14+
Dir.chdir("mruby") do
15+
ENV["MRUBY_CONFIG"] = MRUBY_CONFIG_PATH
16+
sh "rake all"
17+
end
18+
end
19+
20+
desc "test"
21+
task :test => :mruby do
22+
Dir.chdir("mruby") do
23+
ENV["MRUBY_CONFIG"] = MRUBY_CONFIG_PATH
24+
sh "rake all test"
25+
end
26+
end
27+
28+
desc "cleanup"
29+
task :clean do
30+
Dir.chdir("mruby") do
31+
ENV["MRUBY_CONFIG"] = MRUBY_CONFIG_PATH
32+
sh "rake deep_clean"
33+
end
34+
end
35+
36+
task :default => :test

fuzz/bintest/mruby-cbor-fuzzer.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require 'open3'
2+
require 'fileutils'
3+
4+
GEM_ROOT = File.expand_path('../', __dir__)
5+
CORPUS_DIR = File.join(GEM_ROOT, 'corpus')
6+
DICT_FILE = File.join(GEM_ROOT, 'cbor.dict')
7+
8+
assert('mruby-cbor-fuzzer: no crashes in fuzzing run') do
9+
findings_dir = File.join(GEM_ROOT, 'findings')
10+
FileUtils.mkdir_p(findings_dir)
11+
12+
cmd = cmd_list('mruby-cbor-fuzzer') + [
13+
CORPUS_DIR,
14+
"-dict=#{DICT_FILE}",
15+
"-jobs=7",
16+
"-artifact_prefix=#{findings_dir}/",
17+
"-max_len=4096",
18+
"-ignore_ooms=0"
19+
]
20+
21+
Dir.chdir(findings_dir) do
22+
pid = Process.spawn(*cmd, out: '/dev/null', err: '/dev/null')
23+
Process.detach(pid)
24+
25+
# Kill fuzzer on Ctrl+C
26+
trap('INT') do
27+
puts "\nKilling fuzzer..."
28+
Process.kill(9, pid)
29+
exit(1)
30+
end
31+
end
32+
33+
sleep 0.1 until (0..6).all? { |n| File.exist?(File.join(findings_dir, "fuzz-#{n}.log")) }
34+
35+
threads = (0..6).map do |n|
36+
log = File.join(findings_dir, "fuzz-#{n}.log")
37+
Thread.new do
38+
File.open(log) do |f|
39+
loop do
40+
line = f.gets
41+
line ? $stderr.print("[#{n}] #{line}") : sleep(0.05)
42+
GC.start
43+
end
44+
end
45+
end
46+
end
47+
48+
loop do
49+
done = (0..6).count do |n|
50+
log = File.join(findings_dir, "fuzz-#{n}.log")
51+
File.exist?(log) && File.read(log) =~ /Done \d+|SUMMARY:/
52+
end
53+
break if done == 16
54+
sleep 5
55+
end
56+
57+
threads.each(&:kill)
58+
59+
crashes = (0..6).select do |n|
60+
log = File.join(findings_dir, "fuzz-#{n}.log")
61+
File.exist?(log) && File.read(log).include?('SUMMARY:')
62+
end
63+
64+
assert_true crashes.empty?,
65+
"crashes in workers: #{crashes.map { |n| "fuzz-#{n}.log" }.join(', ')}"
66+
end

fuzz/build_config.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
MRuby::Build.new do |conf|
2+
conf.toolchain :clang
3+
4+
conf.enable_sanitizer "address,undefined"
5+
6+
conf.enable_debug
7+
conf.enable_bintest
8+
conf.cc.defines << 'MRB_UTF8_STRING' << 'MRB_PROFILE_HIGH'
9+
conf.cxx.defines << 'MRB_UTF8_STRING' << 'MRB_PROFILE_HIGH'
10+
conf.gem '../'
11+
conf.gem File.expand_path(__dir__)
12+
end

fuzz/cbor.dict

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
"\x00"
2+
"\x01"
3+
"\x17"
4+
"\x18\x00"
5+
"\x18\xff"
6+
"\x19\x00\x00"
7+
"\x19\xff\xff"
8+
"\x1a\x00\x00\x00\x00"
9+
"\x1a\xff\xff\xff\xff"
10+
"\x1b\x00\x00\x00\x00\x00\x00\x00\x00"
11+
"\x1b\xff\xff\xff\xff\xff\xff\xff\xff"
12+
13+
"\x20"
14+
"\x37"
15+
"\x38\x00"
16+
"\x38\xff"
17+
"\x39\x00\x00"
18+
"\x39\xff\xff"
19+
"\x3a\x00\x00\x00\x00"
20+
"\x3a\xff\xff\xff\xff"
21+
"\x3b\x00\x00\x00\x00\x00\x00\x00\x00"
22+
"\x3b\xff\xff\xff\xff\xff\xff\xff\xff"
23+
24+
"\x40"
25+
"\x41"
26+
"\x57"
27+
"\x58\x00"
28+
"\x58\x18"
29+
"\x58\xff"
30+
"\x59\x00\x00"
31+
"\x5a\x00\x00\x00\x00"
32+
"\x5b\x00\x00\x00\x00\x00\x00\x00\x00"
33+
34+
"\x60"
35+
"\x61"
36+
"\x77"
37+
"\x78\x00"
38+
"\x78\xff"
39+
"\x79\x00\x00"
40+
"\x7a\x00\x00\x00\x00"
41+
"\x7b\x00\x00\x00\x00\x00\x00\x00\x00"
42+
43+
"\x80"
44+
"\x81"
45+
"\x97"
46+
"\x98\x00"
47+
"\x98\xff"
48+
"\x99\x00\x00"
49+
"\x9a\x00\x00\x00\x00"
50+
"\x9b\x00\x00\x00\x00\x00\x00\x00\x00"
51+
52+
"\xa0"
53+
"\xa1"
54+
"\xb7"
55+
"\xb8\x00"
56+
"\xb8\xff"
57+
"\xb9\x00\x00"
58+
"\xba\x00\x00\x00\x00"
59+
"\xbb\x00\x00\x00\x00\x00\x00\x00\x00"
60+
61+
"\xc0"
62+
"\xc1"
63+
"\xc2"
64+
"\xc3"
65+
"\xc4"
66+
"\xc5"
67+
"\xc6"
68+
"\xc7"
69+
"\xc8"
70+
"\xc9"
71+
"\xca"
72+
"\xd5"
73+
"\xd6"
74+
"\xd7"
75+
"\xd8\x18"
76+
"\xd8\x1c"
77+
"\xd8\x1d"
78+
"\xd8\x20"
79+
"\xd8\x21"
80+
"\xd8\x22"
81+
"\xd8\x23"
82+
"\xd8\x24"
83+
"\xd9\x00\x00"
84+
"\xda\x00\x00\x00\x00"
85+
"\xdb\x00\x00\x00\x00\x00\x00\x00\x00"
86+
87+
"\xf4"
88+
"\xf5"
89+
"\xf6"
90+
"\xf7"
91+
"\xf8\x00"
92+
"\xf8\x10"
93+
"\xf8\xff"
94+
"\xf9\x00\x00"
95+
"\xf9\x7c\x00"
96+
"\xf9\x7e\x00"
97+
"\xf9\xfc\x00"
98+
"\xf9\x80\x00"
99+
"\xfa\x00\x00\x00\x00"
100+
"\xfa\x3f\x80\x00\x00"
101+
"\xfa\x7f\x80\x00\x00"
102+
"\xfa\x7f\xc0\x00\x00"
103+
"\xfa\xff\x80\x00\x00"
104+
"\xfb\x00\x00\x00\x00\x00\x00\x00\x00"
105+
"\xfb\x3f\xf0\x00\x00\x00\x00\x00\x00"
106+
"\xfb\x7f\xf0\x00\x00\x00\x00\x00\x00"
107+
"\xfb\x7f\xf8\x00\x00\x00\x00\x00\x00"
108+
"\xfb\xff\xf0\x00\x00\x00\x00\x00\x00"
109+
"\xfb\x80\x00\x00\x00\x00\x00\x00\x00"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
����
724 Bytes
Binary file not shown.
1.17 KB
Binary file not shown.
54 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)