shithub: mp3dec

Download patch

ref: 285cba95a68175b3dccb22a43d024162d001ac30
parent: 2fd4f163a35456f41c2371236c3ad34f170fbad2
author: Saga Musix <sagamusix@users.noreply.github.com>
date: Fri Feb 16 10:00:05 EST 2018

Add minimal test program for fuzzing

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,16 @@
+#!/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 ../libdislocator
+make || exit
+cd ../..
+rm -rf afl
+mv afl-* afl
\ No newline at end of file