Skip to content

Commit faf5c73

Browse files
committed
harness-suite: add freetype2, zlib, stb
1 parent ac17ec0 commit faf5c73

12 files changed

+389
-24
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
set -e +x
3+
source set-buildflags.sh
4+
5+
cd "$PROJECT/freetype"
6+
7+
./autogen.sh
8+
./configure $CONFIGUREFLAGS --enable-static --disable-shared
9+
make -j8
10+
11+
cd "$PROJECT/libarchive"
12+
13+
cmake . -DWASI_SDK_PREFIX="${WASI_SDK_PREFIX}" \
14+
-DBUILD_SHARED_LIBS=OFF \
15+
-DENABLE_WERROR=OFF \
16+
-DDONT_FAIL_ON_CRC_ERROR=1
17+
make -j8 archive_static
18+
19+
cd "$PROJECT/freetype2-testing"
20+
21+
$CXX $CXXFLAGS -std=c++11 \
22+
-I "$PROJECT/libarchive/libarchive/" -I "$PROJECT/freetype/include/" \
23+
./fuzzing/src/legacy/ftfuzzer.cc \
24+
-o /out/freetype2-ftfuzzer.wasm \
25+
$LIB_FUZZING_ENGINE -lz \
26+
"$PROJECT/freetype/objs/.libs/libfreetype.a" \
27+
"$PROJECT/libarchive/libarchive/libarchive.a"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
diff --git a/include/freetype/config/ftstdlib.h b/include/freetype/config/ftstdlib.h
2+
index a6812ae..aeb4ac2 100644
3+
--- a/include/freetype/config/ftstdlib.h
4+
+++ b/include/freetype/config/ftstdlib.h
5+
@@ -163,6 +163,8 @@
6+
*/
7+
8+
9+
+#ifndef __wasi__
10+
+
11+
#include <setjmp.h>
12+
13+
#define ft_jmp_buf jmp_buf /* note: this cannot be a typedef since */
14+
@@ -172,6 +174,18 @@
15+
#define ft_longjmp longjmp
16+
#define ft_setjmp( b ) setjmp( *(ft_jmp_buf*) &(b) ) /* same thing here */
17+
18+
+#else
19+
+
20+
+void wasmfuzz_exit_testcase(void)
21+
+ __attribute__((__noreturn__))
22+
+ __attribute__((__import_module__("wasmfuzz"), __import_name__("exit_testcase")));
23+
+
24+
+#define ft_jmp_buf int
25+
+#define ft_longjmp( a, b ) (void)a, (void)b, wasmfuzz_exit_testcase()
26+
+#define ft_setjmp( b ) (void)b, 0
27+
+
28+
+#endif
29+
+
30+
31+
/* The following is only used for debugging purposes, i.e., if */
32+
/* `FT_DEBUG_LEVEL_ERROR` or `FT_DEBUG_LEVEL_TRACE` are defined. */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
diff --git a/libarchive/archive_read_disk_posix.c b/libarchive/archive_read_disk_posix.c
2+
index 76a4fa44..ec6d2c79 100644
3+
--- a/libarchive/archive_read_disk_posix.c
4+
+++ b/libarchive/archive_read_disk_posix.c
5+
@@ -97,8 +97,11 @@
6+
#include "archive_private.h"
7+
#include "archive_read_disk_private.h"
8+
9+
+static int dup(int oldfd) { abort(); }
10+
+static int fchdir(int fd) { abort(); }
11+
+
12+
#ifndef HAVE_FCHDIR
13+
-#error fchdir function required.
14+
+// #error fchdir function required.
15+
#endif
16+
#ifndef O_BINARY
17+
#define O_BINARY 0
18+
diff --git a/libarchive/archive_read_disk_set_standard_lookup.c b/libarchive/archive_read_disk_set_standard_lookup.c
19+
index 3512d343..6ff685f9 100644
20+
--- a/libarchive/archive_read_disk_set_standard_lookup.c
21+
+++ b/libarchive/archive_read_disk_set_standard_lookup.c
22+
@@ -230,15 +230,7 @@ lookup_uname_helper(struct name_cache *cache, id_t id)
23+
static const char *
24+
lookup_uname_helper(struct name_cache *cache, id_t id)
25+
{
26+
- struct passwd *result;
27+
- (void)cache; /* UNUSED */
28+
-
29+
- result = getpwuid((uid_t)id);
30+
-
31+
- if (result == NULL)
32+
- return (NULL);
33+
-
34+
- return strdup(result->pw_name);
35+
+ return (NULL);
36+
}
37+
#endif
38+
39+
@@ -297,15 +289,7 @@ lookup_gname_helper(struct name_cache *cache, id_t id)
40+
static const char *
41+
lookup_gname_helper(struct name_cache *cache, id_t id)
42+
{
43+
- struct group *result;
44+
- (void)cache; /* UNUSED */
45+
-
46+
- result = getgrgid((gid_t)id);
47+
-
48+
- if (result == NULL)
49+
- return (NULL);
50+
-
51+
- return strdup(result->gr_name);
52+
+ return (NULL);
53+
}
54+
#endif
55+
56+
diff --git a/libarchive/archive_read_support_filter_program.c b/libarchive/archive_read_support_filter_program.c
57+
index 0482c57c..5efd17d2 100644
58+
--- a/libarchive/archive_read_support_filter_program.c
59+
+++ b/libarchive/archive_read_support_filter_program.c
60+
@@ -226,6 +226,7 @@ program_bidder_bid(struct archive_read_filter_bidder *self,
61+
static int
62+
child_stop(struct archive_read_filter *self, struct program_filter *state)
63+
{
64+
+#if !defined(__wasi__)
65+
/* Close our side of the I/O with the child. */
66+
if (state->child_stdin != -1) {
67+
close(state->child_stdin);
68+
@@ -284,7 +285,7 @@ child_stop(struct archive_read_filter *self, struct program_filter *state)
69+
WEXITSTATUS(state->exit_status));
70+
return (ARCHIVE_WARN);
71+
}
72+
-
73+
+#endif
74+
return (ARCHIVE_WARN);
75+
}
76+
77+
@@ -390,6 +391,10 @@ program_reader_vtable = {
78+
int
79+
__archive_read_program(struct archive_read_filter *self, const char *cmd)
80+
{
81+
+ #if defined(__wasi__)
82+
+ // We can't run programs but don't want this to fail our whole thing.
83+
+ return (ARCHIVE_WARN);
84+
+ #endif
85+
struct program_filter *state;
86+
static const size_t out_buf_len = 65536;
87+
char *out_buf;
88+
diff --git a/libarchive/archive_write_add_filter_program.c b/libarchive/archive_write_add_filter_program.c
89+
index c661cc7f..bca03921 100644
90+
--- a/libarchive/archive_write_add_filter_program.c
91+
+++ b/libarchive/archive_write_add_filter_program.c
92+
@@ -329,6 +329,7 @@ int
93+
__archive_write_program_close(struct archive_write_filter *f,
94+
struct archive_write_program_data *data)
95+
{
96+
+#if !defined(__wasi__)
97+
int ret, status;
98+
ssize_t bytes_read;
99+
100+
@@ -386,5 +387,7 @@ cleanup:
101+
ret = ARCHIVE_FATAL;
102+
}
103+
return ret;
104+
+#endif
105+
+ return ARCHIVE_WARN;
106+
}
107+
108+
diff --git a/libarchive/archive_write_disk_posix.c b/libarchive/archive_write_disk_posix.c
109+
index bac906d2..9d6a1029 100644
110+
--- a/libarchive/archive_write_disk_posix.c
111+
+++ b/libarchive/archive_write_disk_posix.c
112+
@@ -637,7 +637,7 @@ _archive_write_disk_header(struct archive *_a, struct archive_entry *entry)
113+
* user edits their umask during the extraction for some
114+
* reason.
115+
*/
116+
- umask(a->user_umask = umask(0));
117+
+ a->user_umask = 0; // umask(a->user_umask = umask(0));
118+
119+
/* Figure out what we need to do for this entry. */
120+
a->todo = TODO_MODE_BASE;
121+
@@ -2000,7 +2000,8 @@ archive_write_disk_new(void)
122+
a->archive.vtable = &archive_write_disk_vtable;
123+
a->start_time = time(NULL);
124+
/* Query and restore the umask. */
125+
- umask(a->user_umask = umask(0));
126+
+ // umask(a->user_umask = umask(0));
127+
+ a->user_umask = 0;
128+
#ifdef HAVE_GETEUID
129+
a->user_uid = geteuid();
130+
#endif /* HAVE_GETEUID */
131+
diff --git a/libarchive/archive_write_disk_set_standard_lookup.c b/libarchive/archive_write_disk_set_standard_lookup.c
132+
index 96416989..fc2c1eb4 100644
133+
--- a/libarchive/archive_write_disk_set_standard_lookup.c
134+
+++ b/libarchive/archive_write_disk_set_standard_lookup.c
135+
@@ -157,7 +157,7 @@ lookup_gid(void *private_data, const char *gname, int64_t gid)
136+
#elif defined(_WIN32) && !defined(__CYGWIN__)
137+
/* TODO: do a gname->gid lookup for Windows. */
138+
#else
139+
- #error No way to perform gid lookups on this platform
140+
+ // #error No way to perform gid lookups on this platform
141+
#endif
142+
b->id = (gid_t)gid;
143+
144+
@@ -226,7 +226,7 @@ lookup_uid(void *private_data, const char *uname, int64_t uid)
145+
#elif defined(_WIN32) && !defined(__CYGWIN__)
146+
/* TODO: do a uname->uid lookup for Windows. */
147+
#else
148+
- #error No way to look up uids on this platform
149+
+ // #error No way to look up uids on this platform
150+
#endif
151+
b->id = (uid_t)uid;
152+
153+
diff --git a/libarchive/archive_write_set_format_iso9660.c b/libarchive/archive_write_set_format_iso9660.c
154+
index 2a3ae07f..d4c427fe 100644
155+
--- a/libarchive/archive_write_set_format_iso9660.c
156+
+++ b/libarchive/archive_write_set_format_iso9660.c
157+
@@ -2524,7 +2524,7 @@ get_tmfromtime(struct tm *tm, time_t *t)
158+
#if HAVE_LOCALTIME_S
159+
localtime_s(tm, t);
160+
#elif HAVE_LOCALTIME_R
161+
- tzset();
162+
+ // tzset();
163+
localtime_r(t, tm);
164+
#else
165+
memcpy(tm, localtime(t), sizeof(*tm));
166+
@@ -5193,8 +5193,8 @@ isoent_create_virtual_dir(struct archive_write *a, struct iso9660 *iso9660, cons
167+
archive_entry_unset_mtime(file->entry);
168+
archive_entry_unset_atime(file->entry);
169+
archive_entry_unset_ctime(file->entry);
170+
- archive_entry_set_uid(file->entry, getuid());
171+
- archive_entry_set_gid(file->entry, getgid());
172+
+ // archive_entry_set_uid(file->entry, getuid());
173+
+ // archive_entry_set_gid(file->entry, getgid());
174+
archive_entry_set_mode(file->entry, 0555 | AE_IFDIR);
175+
archive_entry_set_nlink(file->entry, 2);
176+
if (isofile_gen_utility_names(a, file) < ARCHIVE_WARN) {
177+
@@ -7123,8 +7123,8 @@ isoent_create_boot_catalog(struct archive_write *a, struct isoent *rootent)
178+
archive_entry_set_mtime(file->entry, iso9660->birth_time, 0);
179+
archive_entry_set_atime(file->entry, iso9660->birth_time, 0);
180+
archive_entry_set_ctime(file->entry, iso9660->birth_time, 0);
181+
- archive_entry_set_uid(file->entry, getuid());
182+
- archive_entry_set_gid(file->entry, getgid());
183+
+ // archive_entry_set_uid(file->entry, getuid());
184+
+ // archive_entry_set_gid(file->entry, getgid());
185+
archive_entry_set_mode(file->entry, AE_IFREG | 0444);
186+
archive_entry_set_nlink(file->entry, 1);
187+
188+
diff --git a/libarchive/filter_fork_posix.c b/libarchive/filter_fork_posix.c
189+
index c895c08e..8bf73365 100644
190+
--- a/libarchive/filter_fork_posix.c
191+
+++ b/libarchive/filter_fork_posix.c
192+
@@ -26,6 +26,20 @@
193+
194+
#include "archive_platform.h"
195+
196+
+#if defined(__wasi__)
197+
+int
198+
+__archive_create_child(const char *cmd, int *child_stdin, int *child_stdout,
199+
+ void *out_child)
200+
+{
201+
+ return -1;
202+
+}
203+
+
204+
+void
205+
+__archive_check_child(int in, int out)
206+
+{
207+
+}
208+
+#endif
209+
+
210+
/* This capability is only available on POSIX systems. */
211+
#if defined(HAVE_PIPE) && defined(HAVE_FCNTL) && \
212+
(defined(HAVE_FORK) || defined(HAVE_VFORK) || defined(HAVE_POSIX_SPAWNP))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set -e
2+
git clone-rev.sh https://gitlab.freedesktop.org/freetype/freetype.git "$PROJECT/freetype" 94cb3a2eb96b3f17a1a3bd0e6f7da97c0e1d8f57
3+
git clone-rev.sh https://github.com/freetype/freetype2-testing.git "$PROJECT/freetype2-testing" 57d875f1c45b5c9b83bf2e99cedc150108a2b28c
4+
git clone-rev.sh https://github.com/libarchive/libarchive.git "$PROJECT/libarchive" 40ff837717b89e9a5d2c735758f503d124d17b72
5+
6+
git -C freetype apply ../freetype2-testing/fuzzing/settings/freetype2/ftoption.patch
7+
git -C freetype apply ../freetype-stub-sjlj.patch
8+
git -C libarchive apply ../libarchive-stubs.patch
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e +x
3+
source set-buildflags.sh
4+
5+
cd "$PROJECT/repo"
6+
7+
$CC $CFLAGS -I. -DSTBI_ONLY_PNG \
8+
./tests/stbi_read_fuzzer.c \
9+
-o /out/stb-png_read_fuzzer.wasm $LIB_FUZZING_ENGINE
10+
11+
$CC $CFLAGS -I. \
12+
./tests/stbi_read_fuzzer.c \
13+
-o /out/stb-stbi_read_fuzzer.wasm $LIB_FUZZING_ENGINE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set -e
2+
git clone-rev.sh https://github.com/nothings/stb.git "$PROJECT/repo" 2e2bef463a5b53ddf8bb788e25da6b8506314c08
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
set -e +x
3+
source set-buildflags.sh
4+
5+
cd "$PROJECT/repo"
6+
export SRC="$PROJECT/repo"
7+
8+
9+
##################################################################
10+
11+
12+
./configure \
13+
--enable-shared=no \
14+
--with-wasi-sdk="$WASI_SDK_PREFIX" \
15+
$CONFIGUREFLAGS
16+
17+
make -j"$(nproc)"
18+
19+
$CC $CFLAGS -I. ../zlib_uncompress_fuzzer.c \
20+
-o /out/zlib-uncompress.wasm \
21+
$LIB_FUZZING_ENGINE ./libz.a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
set -e
2+
git clone --depth 1 https://github.com/madler/zlib.git "$PROJECT/repo"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <stddef.h>
2+
#include <stdint.h>
3+
4+
#include "zlib.h"
5+
6+
static Bytef buffer[256 * 1024] = { 0 };
7+
8+
int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
9+
uLongf buffer_length = sizeof(buffer);
10+
if (Z_OK != uncompress(buffer, &buffer_length, data, size)) {
11+
return 0;
12+
}
13+
return 0;
14+
}
15+

0 commit comments

Comments
 (0)