Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bottleneck: initial integration #8303

Merged
merged 2 commits into from Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions projects/bottleneck/Dockerfile
@@ -0,0 +1,26 @@
# Copyright 2022 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 pip3 install cython
RUN git clone https://github.com/numpy/numpy && cd numpy && git submodule update --init
RUN cd $SRC/numpy && \
pip3 install . && \
python3 setup.py install
RUN git clone --depth 1 https://github.com/pydata/bottleneck
WORKDIR bottleneck
COPY build.sh *.py $SRC/
26 changes: 26 additions & 0 deletions projects/bottleneck/build.sh
@@ -0,0 +1,26 @@
#!/bin/bash -eu
# Copyright 2022 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/bottleneck
pip3 install .
python3 setup.py install

# Build fuzzers and put them in $OUT/
for fuzzer in $(find $SRC -name 'fuzz_*.py'); do
compile_python_fuzzer $fuzzer
done
93 changes: 93 additions & 0 deletions projects/bottleneck/fuzz_bn.py
@@ -0,0 +1,93 @@
#!/usr/bin/python3
# Copyright 2022 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.
"""Scalar equivalene checker"""

import os
import sys
import atheris

import numpy as np
from numpy.testing import assert_array_almost_equal
import bottleneck as bn


def gen_random_array(data, fdp = None):
if fdp is None:
fdp = atheris.FuzzedDataProvider(data)
l1 = list()
for i in range(fdp.ConsumeIntInRange(5, 3000)):
l1.append(fdp.ConsumeIntInRange(1,10000))
a = np.array(l1)
return a

def TestOneInput(data):
"""Tests scalar equivalence and also move operations"""
fdp = atheris.FuzzedDataProvider(data)
a = gen_random_array(data, fdp)

func_pairs = [
(bn.nansum, bn.slow.nansum),
(bn.nanmean, bn.slow.nanmean),
(bn.nanstd, bn.slow.nanstd),
(bn.nanvar, bn.slow.nanvar),
(bn.nanmin, bn.slow.nanmin),
(bn.median, bn.slow.median),
(bn.nanmedian, bn.slow.nanmedian),
(bn.ss, bn.slow.ss),
(bn.nanargmin, bn.slow.nanargmin),
(bn.nanargmax, bn.slow.nanargmax),
(bn.anynan, bn.slow.anynan),
(bn.allnan, bn.slow.allnan),
]

idx = 0
for func0, func1 in func_pairs:
idx = idx + 1
actual = func0(a)
desired = func1(a)
assert_array_almost_equal(
actual,
desired,
err_msg="Failed scalar equivalence"
)


# Test move operations
window = fdp.ConsumeIntInRange(2, 50)
min_count = fdp.ConsumeIntInRange(1, window)
actual = bn.move_median(
a,
window=window,
min_count = fdp.ConsumeIntInRange(1,100)
)
desired = bn.slow.move_median(
a,
window=window,
min_count=fdp.ConsumeIntInRange(1, 100)
)
assert_array_almost_equal(
actual,
desired,
err_msg="Failed move operation"
)


def main():
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
atheris.Fuzz()

if __name__ == "__main__":
main()
10 changes: 10 additions & 0 deletions projects/bottleneck/project.yaml
@@ -0,0 +1,10 @@
homepage: "https://github.com/pydata/bottleneck"
language: python
main_repo: "https://github.com/pydata/bottleneck"
fuzzing_engines:
- libfuzzer
sanitizers:
- address
- undefined
vendor_ccs:
- david@adalogics.com