shithub: mp3dec

Download patch

ref: f6f8fec8f6f8745f22d73c3ffa178473e3f10483
parent: 2fd4f163a35456f41c2371236c3ad34f170fbad2
parent: e9977ffce0f7f5fd2fff783cb995fe33a649c09e
author: Lion <lieff@users.noreply.github.com>
date: Fri Feb 16 12:28:20 EST 2018

Merge pull request #12 from sagamusix/master
Add fuzzer infrastructure

diff: cannot open b/fuzzing//null: file does not exist: 'b/fuzzing//null'
--- /dev/null
+++ b/fuzzing/build.sh
@@ -1,0 +1,1 @@
+AFL_HARDEN=1 afl/afl-clang-fast fuzz.c -O2 -o fuzz
--- /dev/null
+++ b/fuzzing/fuzz.c
@@ -1,0 +1,29 @@
+#define MINIMP3_IMPLEMENTATION
+#include "../minimp3.h"
+#include <stdio.h>
+
+int main()
+{
+    static mp3dec_t mp3d;
+    mp3dec_frame_info_t info;
+    int nbuf = 0;
+    unsigned char buf[4096];
+
+    mp3dec_init(&mp3d);
+
+#ifdef __AFL_HAVE_MANUAL_CONTROL
+	__AFL_INIT();
+    while (__AFL_LOOP(1000))
+#endif
+	{
+		do
+	    {
+	        short pcm[MINIMP3_MAX_SAMPLES_PER_FRAME];
+        	nbuf += fread(buf + nbuf, 1, sizeof(buf) - nbuf, stdin);
+	        mp3dec_decode_frame(&mp3d, buf, nbuf, pcm, &info);
+			nbuf -= info.frame_bytes;
+	    } while (info.frame_bytes);
+	}
+
+    return 0;
+}
--- /dev/null
+++ b/fuzzing/fuzz.sh
@@ -1,0 +1,4 @@
+#!/usr/bin/env bash
+cd "${0%/*}"
+
+afl/afl-fuzz -m 50 -i- -o findings/ ./fuzz
--- /dev/null
+++ b/fuzzing/get-afl.sh
@@ -1,0 +1,14 @@
+#!/usr/bin/env bash
+cd "${0%/*}"
+rm afl-latest.tgz
+wget http://lcamtuf.coredump.cx/afl/releases/afl-latest.tgz || exit
+tar -xzvf afl-latest.tgz
+rm afl-latest.tgz
+cd afl-*
+make || exit
+cd llvm_mode
+# may need to prepend LLVM_CONFIG=/usr/bin/llvm-config-3.8 or similar, depending on the system
+make || exit
+cd ../..
+rm -rf afl
+mv afl-* afl
\ No newline at end of file