-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fuzz creation of classes with various Unicode identifiers attrs has a critically score of 0.70292 according to https://www.googleapis.com/download/storage/v1/b/ossf-criticality-score/o/2024.12.25%2F224906%2Fall.csv?generation=1736309219475649&alt=media It has 5.4k stars on github and more than 11M of downloads per day based on https://pypistats.org/packages/attrs
- Loading branch information
1 parent
e007cb7
commit 8622aaa
Showing
4 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/python3 | ||
|
||
# Copyright 2025 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 git clone https://github.com/python-attrs/attrs.git | ||
COPY *.sh *py $SRC/ | ||
WORKDIR $SRC/attrs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash -eu | ||
|
||
# Copyright 2025 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. | ||
# | ||
########################################################################## | ||
pip3 install . | ||
for fuzzer in $(find $SRC -name 'fuzz_*.py'); do | ||
compile_python_fuzzer $fuzzer --hidden-import=html.parser | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/python3 | ||
|
||
# Copyright 2025 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 sys | ||
import atheris | ||
|
||
import attrs | ||
import ast | ||
from string import ascii_letters | ||
|
||
def consumeIdentifier(fdp): | ||
return fdp.ConsumeUnicode(8) | ||
|
||
@atheris.instrument_func | ||
def TestOneInput(data): | ||
fdp = atheris.FuzzedDataProvider(data) | ||
clsname = consumeIdentifier(fdp) | ||
attrcount = fdp.ConsumeIntInRange(0, 12) | ||
attrnames = [consumeIdentifier(fdp) | ||
for _ in range(attrcount)] | ||
attrvalues = [None] * attrcount | ||
|
||
# Create class from attrs.make_class | ||
try: | ||
C0 = attrs.make_class(clsname, attrnames) | ||
except Exception as e: | ||
if any(not name.isidentifier() for name in [clsname] + attrnames): | ||
return | ||
raise | ||
c0 = C0(**{k: v for k, v in zip(attrnames, attrvalues)}) | ||
d0 = attrs.asdict(c0) | ||
c0_p = C0(**d0) | ||
assert c0 == c0_p | ||
|
||
# Create class from attrs.define | ||
C1 = attrs.define(type(clsname, (), {f: attrs.field() for f in attrnames})) | ||
c1 = C1(**{k: v for k, v in zip(attrnames, attrvalues)}) | ||
d1 = attrs.asdict(c1) | ||
c1_p = C1(**d1) | ||
assert c1 == c1_p | ||
|
||
|
||
def main(): | ||
atheris.instrument_all() | ||
atheris.Setup(sys.argv, TestOneInput) | ||
atheris.Fuzz() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fuzzing_engines: | ||
- libfuzzer | ||
homepage: https://www.attrs.org | ||
language: python | ||
main_repo: https://github.com/python-attrs/attrs.git | ||
sanitizers: | ||
- address | ||
vendor_ccs: | ||
- [email protected] |