Skip to content

Commit d0e2744

Browse files
committed
generate a fuzzing corpus by extracting code from testrunner
1 parent a53c164 commit d0e2744

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

.github/workflows/corpus.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions
2+
# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners
3+
name: corpus
4+
5+
on:
6+
schedule:
7+
- cron: '0 0 * * 0'
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
corpus:
15+
runs-on: ubuntu-22.04
16+
if: ${{ github.repository_owner == 'danmar' }}
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
22+
23+
- name: ccache
24+
uses: hendrikmuhs/ccache-action@v1.2
25+
with:
26+
key: ${{ github.workflow }}-${{ runner.os }}
27+
28+
- name: Install missing software on ubuntu
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y fdupes
32+
33+
- name: build testrunner
34+
run: |
35+
store_dir=$(pwd)/store
36+
mkdir $store_dir
37+
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
38+
make -s -j$(nproc) CXXFLAGS="-w -DSTORE_INPUT_DIR=\"\\\"$store_dir\\\"\"" testrunner
39+
40+
- name: run testrunner
41+
run: |
42+
./testrunner -q
43+
44+
- name: de-duplicate files
45+
run: |
46+
ls -l ./store | wc -l
47+
echo "removing duplicates"
48+
fdupes -qdN ./store > /dev/null
49+
ls -l ./store | wc -l
50+
# print biggest size
51+
ls -l ./store | cut -d' ' -f5 | sort -u -n -r | head -n1
52+
53+
# TODO: dedup with fuzzer?
54+
55+
- uses: actions/upload-artifact@v4
56+
if: success()
57+
with:
58+
name: corpus
59+
path: ./store

lib/tokenlist.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,28 @@ bool TokenList::createTokensFromBuffer(const uint8_t* data, size_t size)
328328

329329
//---------------------------------------------------------------------------
330330

331+
#define STORE_INPUT_DIR "/zsr/"
332+
333+
#ifdef STORE_INPUT_DIR
334+
#include <atomic>
335+
#include <fstream>
336+
337+
static void storeInput(const uint8_t* data, size_t size)
338+
{
339+
static std::atomic_uint64_t num(0);
340+
{
341+
std::ofstream out(STORE_INPUT_DIR "/" + std::to_string(num++));
342+
out.write(reinterpret_cast<const char*>(data), size);
343+
}
344+
}
345+
#endif
346+
331347
bool TokenList::createTokensFromBufferInternal(const uint8_t* data, size_t size, const std::string& file0)
332348
{
349+
#ifdef STORE_INPUT_DIR
350+
storeInput(data, size);
351+
#endif
352+
333353
simplecpp::OutputList outputList;
334354
simplecpp::TokenList tokens(data, size, mFiles, file0, &outputList);
335355

0 commit comments

Comments
 (0)