From dcc5674018f4e77d50e39e7c16647350d5d6cd97 Mon Sep 17 00:00:00 2001 From: McKenna Date: Sat, 12 Aug 2023 15:47:59 -0400 Subject: [PATCH 01/12] Initial project skeleton for icalendar --- projects/icalendar/Dockerfile | 21 +++++++++++++++++++++ projects/icalendar/build.sh | 28 ++++++++++++++++++++++++++++ projects/icalendar/project.yaml | 10 ++++++++++ 3 files changed, 59 insertions(+) create mode 100644 projects/icalendar/Dockerfile create mode 100755 projects/icalendar/build.sh create mode 100644 projects/icalendar/project.yaml diff --git a/projects/icalendar/Dockerfile b/projects/icalendar/Dockerfile new file mode 100644 index 000000000000..d58000052b90 --- /dev/null +++ b/projects/icalendar/Dockerfile @@ -0,0 +1,21 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +FROM gcr.io/oss-fuzz-base/base-builder-python +RUN apt-get update && apt-get install -y make autoconf automake libtool +RUN git clone --depth 1 icalendar # or use other version control +WORKDIR icalendar +COPY build.sh $SRC/ diff --git a/projects/icalendar/build.sh b/projects/icalendar/build.sh new file mode 100755 index 000000000000..12a17a7fa397 --- /dev/null +++ b/projects/icalendar/build.sh @@ -0,0 +1,28 @@ +#!/bin/bash -eu +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +# build project +# e.g. +# ./autogen.sh +# ./configure +# make -j$(nproc) all + +# build fuzzers +# e.g. +# $CXX $CXXFLAGS -std=c++11 -Iinclude \ +# /path/to/name_of_fuzzer.cc -o $OUT/name_of_fuzzer \ +# $LIB_FUZZING_ENGINE /path/to/library.a diff --git a/projects/icalendar/project.yaml b/projects/icalendar/project.yaml new file mode 100644 index 000000000000..c2f8e3d191d0 --- /dev/null +++ b/projects/icalendar/project.yaml @@ -0,0 +1,10 @@ +homepage: "https://icalendar.readthedocs.io/en/latest/" +language: python +primary_contact: "johannes@raggam.co.at" +auto_ccs: + - "dallmeyerm@att.net" + - "maxm@mxm.dk" +sanitizers: + - address + - undefined +main_repo: "https://github.com/collective/icalendar" From 6f62906579025c98fcd7b2c58e0be706fe4873b0 Mon Sep 17 00:00:00 2001 From: McKenna Date: Sat, 12 Aug 2023 15:55:30 -0400 Subject: [PATCH 02/12] Initial project skeleton for icalendar --- projects/icalendar/project.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/icalendar/project.yaml b/projects/icalendar/project.yaml index c2f8e3d191d0..7adafeac3344 100644 --- a/projects/icalendar/project.yaml +++ b/projects/icalendar/project.yaml @@ -2,7 +2,7 @@ homepage: "https://icalendar.readthedocs.io/en/latest/" language: python primary_contact: "johannes@raggam.co.at" auto_ccs: - - "dallmeyerm@att.net" + - "ennamarie19@gmail.com" - "maxm@mxm.dk" sanitizers: - address From 3162e5934dbd1247bf9ca91a23ddc656169c4064 Mon Sep 17 00:00:00 2001 From: McKenna Date: Thu, 24 Aug 2023 15:49:25 -0400 Subject: [PATCH 03/12] Skeleton for OSS-Fuzz --- projects/icalendar/Dockerfile | 8 +-- projects/icalendar/build.sh | 16 ++--- projects/icalendar/enhanced_fdp.py | 111 +++++++++++++++++++++++++++++ projects/icalendar/ical_fuzzer.py | 42 +++++++++++ projects/icalendar/project.yaml | 4 +- 5 files changed, 166 insertions(+), 15 deletions(-) create mode 100644 projects/icalendar/enhanced_fdp.py create mode 100644 projects/icalendar/ical_fuzzer.py diff --git a/projects/icalendar/Dockerfile b/projects/icalendar/Dockerfile index d58000052b90..6fcbc780c960 100644 --- a/projects/icalendar/Dockerfile +++ b/projects/icalendar/Dockerfile @@ -15,7 +15,7 @@ ################################################################################ FROM gcr.io/oss-fuzz-base/base-builder-python -RUN apt-get update && apt-get install -y make autoconf automake libtool -RUN git clone --depth 1 icalendar # or use other version control -WORKDIR icalendar -COPY build.sh $SRC/ +RUN pip3 install --upgrade pip +RUN git clone --depth 1 https://github.com/collective/icalendar.git icalendar +COPY *.sh *.py $SRC/ +WORKDIR $SRC/icalendar diff --git a/projects/icalendar/build.sh b/projects/icalendar/build.sh index 12a17a7fa397..6a6a4279ed01 100755 --- a/projects/icalendar/build.sh +++ b/projects/icalendar/build.sh @@ -15,14 +15,10 @@ # ################################################################################ -# build project -# e.g. -# ./autogen.sh -# ./configure -# make -j$(nproc) all +cd "$SRC"/icalendar +pip3 install . -# build fuzzers -# e.g. -# $CXX $CXXFLAGS -std=c++11 -Iinclude \ -# /path/to/name_of_fuzzer.cc -o $OUT/name_of_fuzzer \ -# $LIB_FUZZING_ENGINE /path/to/library.a +# Build fuzzers in $OUT +for fuzzer in $(find $SRC -name '*_fuzzer.py');do + compile_python_fuzzer "$fuzzer" +done diff --git a/projects/icalendar/enhanced_fdp.py b/projects/icalendar/enhanced_fdp.py new file mode 100644 index 000000000000..3c5362beb4b5 --- /dev/null +++ b/projects/icalendar/enhanced_fdp.py @@ -0,0 +1,111 @@ +# Copyright 2021 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +""" +Defines the EnhancedFuzzedDataProvider +""" +from contextlib import contextmanager +from enum import Enum +from io import BytesIO, StringIO +from tempfile import NamedTemporaryFile +from typing import Optional, Union + +from atheris import FuzzedDataProvider + + +class EnhancedFuzzedDataProvider(FuzzedDataProvider): + """ + Extends the functionality of FuzzedDataProvider + """ + + def _consume_random_count(self) -> int: + """ + :return: A count of bytes that is strictly in range 0<=n<=remaining_bytes + """ + return self.ConsumeIntInRange(0, self.remaining_bytes()) + + def _consume_file_data(self, all_data: bool, as_bytes: bool) -> Union[bytes, str]: + """ + Consumes data for a file + :param all_data: Whether to consume all remaining bytes from the buffer + :param as_bytes: Consumed output is bytes if true, otherwise a string + :return: The consumed output + """ + if all_data: + file_data = self.ConsumeRemainingBytes() if as_bytes else self.ConsumeRemainingString() + else: + file_data = self.ConsumeRandomBytes() if as_bytes else self.ConsumeRandomString() + + return file_data + + def ConsumeRandomBytes(self) -> bytes: + """ + Consume a 'random' count of the remaining bytes + :return: 0<=n<=remaining_bytes bytes + """ + return self.ConsumeBytes(self._consume_random_count()) + + def ConsumeRemainingBytes(self) -> bytes: + """ + :return: The remaining buffer + """ + return self.ConsumeBytes(self.remaining_bytes()) + + def ConsumeRandomString(self) -> str: + """ + Consume a 'random' length string, excluding surrogates + :return: The string + """ + return self.ConsumeUnicodeNoSurrogates(self._consume_random_count()) + + def ConsumeRemainingString(self) -> str: + """ + :return: The remaining buffer, as a string without surrogates + """ + return self.ConsumeUnicodeNoSurrogates(self.remaining_bytes()) + + def PickValueInEnum(self, enum): + return self.PickValueInList([e.value for e in enum]) + + @contextmanager + def ConsumeMemoryFile(self, all_data: bool, as_bytes: bool) -> Union[BytesIO, StringIO]: + """ + Consumes a file-like object, that resides entirely in memory + :param all_data: Whether to populate the file with all remaining data or not + :param as_bytes: Whether the file should hold bytes or strings + :return: The in-memory file + """ + file_data = self._consume_file_data(all_data, as_bytes) + file = BytesIO(file_data) if as_bytes else StringIO(file_data) + yield file + file.close() + + @contextmanager + def ConsumeTemporaryFile(self, all_data: bool, as_bytes: bool, suffix: Optional[str] = None) -> str: + """ + Consumes a temporary file, handling its deletion + :param all_data: Whether to populate the file with all remaining data or not + :param as_bytes: Whether the file should hold bytes or strings + :param suffix: A suffix to use for the generated file, e.g. 'txt' + :return: The path to the temporary file + """ + file_data = self._consume_file_data(all_data, as_bytes) + mode = 'w+b' if as_bytes else 'w+' + tfile = NamedTemporaryFile(mode=mode, suffix=suffix) + tfile.write(file_data) + tfile.seek(0) + tfile.flush() + yield tfile.name + tfile.close() diff --git a/projects/icalendar/ical_fuzzer.py b/projects/icalendar/ical_fuzzer.py new file mode 100644 index 000000000000..2367cdc4a193 --- /dev/null +++ b/projects/icalendar/ical_fuzzer.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +import atheris +import sys + +with atheris.instrument_imports(include=['icalendar']): + from icalendar import Calendar + +from enhanced_fdp import EnhancedFuzzedDataProvider + + +def TestOneInput(data): + fdp = EnhancedFuzzedDataProvider(data) + try: + Calendar.from_ical(fdp.ConsumeRemainingString()) + except ValueError as e: + if "component" in str(e) or "parse" in str(e): + return -1 + raise e + + +def main(): + atheris.Setup(sys.argv, TestOneInput) + atheris.Fuzz() + + +if __name__ == "__main__": + main() diff --git a/projects/icalendar/project.yaml b/projects/icalendar/project.yaml index 7adafeac3344..205d89a921e0 100644 --- a/projects/icalendar/project.yaml +++ b/projects/icalendar/project.yaml @@ -4,7 +4,9 @@ primary_contact: "johannes@raggam.co.at" auto_ccs: - "ennamarie19@gmail.com" - "maxm@mxm.dk" +fuzzing_engines: + - libfuzzer sanitizers: - address - undefined -main_repo: "https://github.com/collective/icalendar" +main_repo: "https://github.com/collective/icalendar.git" From 55733d5b64fc5ef3f65be787fbc0286e563873bf Mon Sep 17 00:00:00 2001 From: McKenna Date: Sat, 26 Aug 2023 18:23:25 -0400 Subject: [PATCH 04/12] Working integration for icalendar From 7dc51647cf56e735f18b566ea675e5fcb6f311a1 Mon Sep 17 00:00:00 2001 From: McKenna Date: Sat, 26 Aug 2023 18:24:55 -0400 Subject: [PATCH 05/12] Working integration for icalendar From 2f22be2bdf85d04d3b2cc488c2ba13d60aed10a8 Mon Sep 17 00:00:00 2001 From: McKenna Date: Sat, 26 Aug 2023 18:26:32 -0400 Subject: [PATCH 06/12] Working integration for icalendar From 2d7ee8841a1113fea0caa5b7d6fc67a7584d3030 Mon Sep 17 00:00:00 2001 From: McKenna Date: Sat, 26 Aug 2023 18:51:51 -0400 Subject: [PATCH 07/12] Added corpus --- projects/icalendar/Dockerfile | 4 +++- projects/icalendar/build.sh | 1 + projects/icalendar/corpus/calendar_with_unicode.ics | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 projects/icalendar/corpus/calendar_with_unicode.ics diff --git a/projects/icalendar/Dockerfile b/projects/icalendar/Dockerfile index 6fcbc780c960..6546d7c97908 100644 --- a/projects/icalendar/Dockerfile +++ b/projects/icalendar/Dockerfile @@ -17,5 +17,7 @@ FROM gcr.io/oss-fuzz-base/base-builder-python RUN pip3 install --upgrade pip RUN git clone --depth 1 https://github.com/collective/icalendar.git icalendar -COPY *.sh *.py $SRC/ +COPY *.sh *.py $SRC/ +COPY corpus $SRC/corpus WORKDIR $SRC/icalendar + diff --git a/projects/icalendar/build.sh b/projects/icalendar/build.sh index 6a6a4279ed01..2b40cca9b770 100755 --- a/projects/icalendar/build.sh +++ b/projects/icalendar/build.sh @@ -22,3 +22,4 @@ pip3 install . for fuzzer in $(find $SRC -name '*_fuzzer.py');do compile_python_fuzzer "$fuzzer" done +zip -q $OUT/ical_fuzzer_seed_corpus.zip $SRC/corpus/* diff --git a/projects/icalendar/corpus/calendar_with_unicode.ics b/projects/icalendar/corpus/calendar_with_unicode.ics new file mode 100644 index 000000000000..e5e2f4160fef --- /dev/null +++ b/projects/icalendar/corpus/calendar_with_unicode.ics @@ -0,0 +1,7 @@ +BEGIN:VCALENDAR +PRODID:-//Plönë.org//NONSGML plone.app.event//EN +VERSION:2.0 +X-WR-CALNAME:äöü ÄÖÜ € +X-WR-CALDESC:test non ascii: äöü ÄÖÜ € +X-WR-RELCALID:12345 +END:VCALENDAR From 51ad35b8f9bd860ea0268b6b273b5b7f462217fb Mon Sep 17 00:00:00 2001 From: McKenna Date: Sun, 24 Sep 2023 09:42:17 -0400 Subject: [PATCH 08/12] Initial Project Skeleton for ja3 --- projects/ja3/Dockerfile | 21 +++++++++++++++++++++ projects/ja3/build.sh | 28 ++++++++++++++++++++++++++++ projects/ja3/project.yaml | 11 +++++++++++ 3 files changed, 60 insertions(+) create mode 100644 projects/ja3/Dockerfile create mode 100755 projects/ja3/build.sh create mode 100644 projects/ja3/project.yaml diff --git a/projects/ja3/Dockerfile b/projects/ja3/Dockerfile new file mode 100644 index 000000000000..fd9b5781c95b --- /dev/null +++ b/projects/ja3/Dockerfile @@ -0,0 +1,21 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +FROM gcr.io/oss-fuzz-base/base-builder-python +RUN apt-get update && apt-get install -y make autoconf automake libtool +RUN git clone --depth 1 ja3 # or use other version control +WORKDIR ja3 +COPY build.sh $SRC/ diff --git a/projects/ja3/build.sh b/projects/ja3/build.sh new file mode 100755 index 000000000000..12a17a7fa397 --- /dev/null +++ b/projects/ja3/build.sh @@ -0,0 +1,28 @@ +#!/bin/bash -eu +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ + +# build project +# e.g. +# ./autogen.sh +# ./configure +# make -j$(nproc) all + +# build fuzzers +# e.g. +# $CXX $CXXFLAGS -std=c++11 -Iinclude \ +# /path/to/name_of_fuzzer.cc -o $OUT/name_of_fuzzer \ +# $LIB_FUZZING_ENGINE /path/to/library.a diff --git a/projects/ja3/project.yaml b/projects/ja3/project.yaml new file mode 100644 index 000000000000..1b814868d39f --- /dev/null +++ b/projects/ja3/project.yaml @@ -0,0 +1,11 @@ +homepage: "https://engineering.salesforce.com/tls-fingerprinting-with-ja3-and-ja3s-247362855967/" +language: python +primary_contact: "jalthouse@salesforce.com" +auto_ccs: + - "ennamarie19@gmail.com" +fuzzing_engines: + - libfuzzer +sanitizers: + - address + - undefined +main_repo: "https://github.com/salesforce/ja3.git" From 497754177fb31b595e18691c873db57bead14f9a Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Wed, 27 Sep 2023 11:06:29 -0400 Subject: [PATCH 09/12] Delete projects/ja3/Dockerfile --- projects/ja3/Dockerfile | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 projects/ja3/Dockerfile diff --git a/projects/ja3/Dockerfile b/projects/ja3/Dockerfile deleted file mode 100644 index fd9b5781c95b..000000000000 --- a/projects/ja3/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ - -FROM gcr.io/oss-fuzz-base/base-builder-python -RUN apt-get update && apt-get install -y make autoconf automake libtool -RUN git clone --depth 1 ja3 # or use other version control -WORKDIR ja3 -COPY build.sh $SRC/ From ff169444173618163e35faa7d8bf227f51dc0f7f Mon Sep 17 00:00:00 2001 From: jonathanmetzman <31354670+jonathanmetzman@users.noreply.github.com> Date: Wed, 27 Sep 2023 11:06:40 -0400 Subject: [PATCH 10/12] Delete projects/ja3/build.sh --- projects/ja3/build.sh | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100755 projects/ja3/build.sh diff --git a/projects/ja3/build.sh b/projects/ja3/build.sh deleted file mode 100755 index 12a17a7fa397..000000000000 --- a/projects/ja3/build.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -eu -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ - -# build project -# e.g. -# ./autogen.sh -# ./configure -# make -j$(nproc) all - -# build fuzzers -# e.g. -# $CXX $CXXFLAGS -std=c++11 -Iinclude \ -# /path/to/name_of_fuzzer.cc -o $OUT/name_of_fuzzer \ -# $LIB_FUZZING_ENGINE /path/to/library.a From 07cc0ecdae8f4eb2849422b88a12c93b723f8011 Mon Sep 17 00:00:00 2001 From: bcapuano Date: Fri, 27 Oct 2023 21:55:00 -0400 Subject: [PATCH 11/12] Migrated harness code to upstream and updated Dockerfile to reflect these changes --- projects/icalendar/Dockerfile | 8 +-- projects/icalendar/build.sh | 25 ------- projects/icalendar/enhanced_fdp.py | 111 ----------------------------- projects/icalendar/ical_fuzzer.py | 42 ----------- 4 files changed, 4 insertions(+), 182 deletions(-) delete mode 100755 projects/icalendar/build.sh delete mode 100644 projects/icalendar/enhanced_fdp.py delete mode 100644 projects/icalendar/ical_fuzzer.py diff --git a/projects/icalendar/Dockerfile b/projects/icalendar/Dockerfile index 6546d7c97908..c3001f2e3db1 100644 --- a/projects/icalendar/Dockerfile +++ b/projects/icalendar/Dockerfile @@ -15,9 +15,9 @@ ################################################################################ FROM gcr.io/oss-fuzz-base/base-builder-python -RUN pip3 install --upgrade pip -RUN git clone --depth 1 https://github.com/collective/icalendar.git icalendar -COPY *.sh *.py $SRC/ +RUN pip3 install --upgrade pip +RUN git clone --depth 1 https://github.com/collective/icalendar.git icalendar \ + && cp icalendar/src/icalendar/fuzzing/build.sh $SRC/ COPY corpus $SRC/corpus -WORKDIR $SRC/icalendar +WORKDIR $SRC/icalendar diff --git a/projects/icalendar/build.sh b/projects/icalendar/build.sh deleted file mode 100755 index 2b40cca9b770..000000000000 --- a/projects/icalendar/build.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -eu -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ - -cd "$SRC"/icalendar -pip3 install . - -# Build fuzzers in $OUT -for fuzzer in $(find $SRC -name '*_fuzzer.py');do - compile_python_fuzzer "$fuzzer" -done -zip -q $OUT/ical_fuzzer_seed_corpus.zip $SRC/corpus/* diff --git a/projects/icalendar/enhanced_fdp.py b/projects/icalendar/enhanced_fdp.py deleted file mode 100644 index 3c5362beb4b5..000000000000 --- a/projects/icalendar/enhanced_fdp.py +++ /dev/null @@ -1,111 +0,0 @@ -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -""" -Defines the EnhancedFuzzedDataProvider -""" -from contextlib import contextmanager -from enum import Enum -from io import BytesIO, StringIO -from tempfile import NamedTemporaryFile -from typing import Optional, Union - -from atheris import FuzzedDataProvider - - -class EnhancedFuzzedDataProvider(FuzzedDataProvider): - """ - Extends the functionality of FuzzedDataProvider - """ - - def _consume_random_count(self) -> int: - """ - :return: A count of bytes that is strictly in range 0<=n<=remaining_bytes - """ - return self.ConsumeIntInRange(0, self.remaining_bytes()) - - def _consume_file_data(self, all_data: bool, as_bytes: bool) -> Union[bytes, str]: - """ - Consumes data for a file - :param all_data: Whether to consume all remaining bytes from the buffer - :param as_bytes: Consumed output is bytes if true, otherwise a string - :return: The consumed output - """ - if all_data: - file_data = self.ConsumeRemainingBytes() if as_bytes else self.ConsumeRemainingString() - else: - file_data = self.ConsumeRandomBytes() if as_bytes else self.ConsumeRandomString() - - return file_data - - def ConsumeRandomBytes(self) -> bytes: - """ - Consume a 'random' count of the remaining bytes - :return: 0<=n<=remaining_bytes bytes - """ - return self.ConsumeBytes(self._consume_random_count()) - - def ConsumeRemainingBytes(self) -> bytes: - """ - :return: The remaining buffer - """ - return self.ConsumeBytes(self.remaining_bytes()) - - def ConsumeRandomString(self) -> str: - """ - Consume a 'random' length string, excluding surrogates - :return: The string - """ - return self.ConsumeUnicodeNoSurrogates(self._consume_random_count()) - - def ConsumeRemainingString(self) -> str: - """ - :return: The remaining buffer, as a string without surrogates - """ - return self.ConsumeUnicodeNoSurrogates(self.remaining_bytes()) - - def PickValueInEnum(self, enum): - return self.PickValueInList([e.value for e in enum]) - - @contextmanager - def ConsumeMemoryFile(self, all_data: bool, as_bytes: bool) -> Union[BytesIO, StringIO]: - """ - Consumes a file-like object, that resides entirely in memory - :param all_data: Whether to populate the file with all remaining data or not - :param as_bytes: Whether the file should hold bytes or strings - :return: The in-memory file - """ - file_data = self._consume_file_data(all_data, as_bytes) - file = BytesIO(file_data) if as_bytes else StringIO(file_data) - yield file - file.close() - - @contextmanager - def ConsumeTemporaryFile(self, all_data: bool, as_bytes: bool, suffix: Optional[str] = None) -> str: - """ - Consumes a temporary file, handling its deletion - :param all_data: Whether to populate the file with all remaining data or not - :param as_bytes: Whether the file should hold bytes or strings - :param suffix: A suffix to use for the generated file, e.g. 'txt' - :return: The path to the temporary file - """ - file_data = self._consume_file_data(all_data, as_bytes) - mode = 'w+b' if as_bytes else 'w+' - tfile = NamedTemporaryFile(mode=mode, suffix=suffix) - tfile.write(file_data) - tfile.seek(0) - tfile.flush() - yield tfile.name - tfile.close() diff --git a/projects/icalendar/ical_fuzzer.py b/projects/icalendar/ical_fuzzer.py deleted file mode 100644 index 2367cdc4a193..000000000000 --- a/projects/icalendar/ical_fuzzer.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python3 -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -import atheris -import sys - -with atheris.instrument_imports(include=['icalendar']): - from icalendar import Calendar - -from enhanced_fdp import EnhancedFuzzedDataProvider - - -def TestOneInput(data): - fdp = EnhancedFuzzedDataProvider(data) - try: - Calendar.from_ical(fdp.ConsumeRemainingString()) - except ValueError as e: - if "component" in str(e) or "parse" in str(e): - return -1 - raise e - - -def main(): - atheris.Setup(sys.argv, TestOneInput) - atheris.Fuzz() - - -if __name__ == "__main__": - main() From 1184a5fa75d770376c9ea778671dfdaa51b99429 Mon Sep 17 00:00:00 2001 From: McKenna Date: Mon, 6 Nov 2023 20:10:10 -0500 Subject: [PATCH 12/12] Initial integration project.yaml --- projects/dateparser/project.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 projects/dateparser/project.yaml diff --git a/projects/dateparser/project.yaml b/projects/dateparser/project.yaml new file mode 100644 index 000000000000..6dd32b9a49a7 --- /dev/null +++ b/projects/dateparser/project.yaml @@ -0,0 +1,11 @@ +homepage: "https://dateparser.readthedocs.io/en/latest/" +language: python +primary_contact: "opensource@zyte.com" +auto_ccs: + - "ennamarie19@gmail.com" +fuzzing_engines: + - libfuzzer +sanitizers: + - address + - undefined +main_repo: "https://github.com/scrapinghub/dateparser.git"