Skip to content

Commit

Permalink
python-multipart: test target
Browse files Browse the repository at this point in the history
  • Loading branch information
manunio committed Feb 23, 2025
1 parent 9ece30f commit 999e7d2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions projects/python-multipart/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ RUN apt-get update && apt-get install -y make autoconf automake libtool
RUN git clone --depth 1 https://github.com/Kludex/python-multipart python-multipart
RUN python3 -m pip install --upgrade pip
WORKDIR python-multipart
COPY *.patch $SRC/python-multipart
COPY build.sh *.options $SRC/
1 change: 1 addition & 0 deletions projects/python-multipart/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
################################################################################

git apply $SRC/python-multipart/*.patch
python3 -m pip install '.[dev]'
for fuzzer in $(find $SRC -name "fuzz_*.py"); do
compile_python_fuzzer $fuzzer
Expand Down
13 changes: 13 additions & 0 deletions projects/python-multipart/fuzz_form.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/fuzz/fuzz_form.py b/fuzz/fuzz_form.py
index 9a3d854..fbc6ad9 100644
--- a/fuzz/fuzz_form.py
+++ b/fuzz/fuzz_form.py
@@ -29,7 +29,7 @@ def parse_form_urlencoded(fdp: EnhancedDataProvider) -> None:


def parse_multipart_form_data(fdp: EnhancedDataProvider) -> None:
- boundary = "boundary"
+ boundary = fdp.ConsumeRandomStringOfSize(16) or "boundary"
header = {"Content-Type": f"multipart/form-data; boundary={boundary}"}
body = (
f"--{boundary}\r\n"
17 changes: 17 additions & 0 deletions projects/python-multipart/helpers.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/fuzz/helpers.py b/fuzz/helpers.py
index 7fcd45c..d107cc1 100644
--- a/fuzz/helpers.py
+++ b/fuzz/helpers.py
@@ -1,9 +1,11 @@
import atheris

-
class EnhancedDataProvider(atheris.FuzzedDataProvider):
def ConsumeRandomBytes(self) -> bytes:
return self.ConsumeBytes(self.ConsumeIntInRange(0, self.remaining_bytes()))

def ConsumeRandomString(self) -> str:
return self.ConsumeUnicodeNoSurrogates(self.ConsumeIntInRange(0, self.remaining_bytes()))
+
+ def ConsumeRandomStringOfSize(self, val: int) -> str:
+ return self.ConsumeUnicodeNoSurrogates(self.ConsumeIntInRange(0, val))

0 comments on commit 999e7d2

Please sign in to comment.