mirror of https://github.com/google/oss-fuzz.git
kafka-python: intial integration (#8017)
* kafka-python: intial integration Create fuzzers * Fix project initialization
This commit is contained in:
parent
e9c13b3c19
commit
e23701f9d5
|
@ -0,0 +1,29 @@
|
|||
# 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 -y && apt-get install wget
|
||||
RUN wget -qO - https://packages.confluent.io/deb/7.0/archive.key | apt-key add -
|
||||
RUN add-apt-repository "deb https://packages.confluent.io/clients/deb $(lsb_release -cs) main"
|
||||
RUN apt-get update -y && apt-get install librdkafka-dev software-properties-common lsb-release gcc make python3-dev libsasl2-modules-gssapi-mit krb5-user -y
|
||||
|
||||
RUN pip3 install --upgrade pip
|
||||
|
||||
RUN git clone --depth=1 https://github.com/confluentinc/confluent-kafka-python kafka
|
||||
WORKDIR kafka
|
||||
|
||||
COPY build.sh fuzz_*.py $SRC/
|
|
@ -0,0 +1,23 @@
|
|||
#!/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.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# Build and install project (using current CFLAGS, CXXFLAGS).
|
||||
pip3 install .
|
||||
|
||||
for fuzzer in $(find $SRC -name 'fuzz_*.py'); do
|
||||
compile_python_fuzzer $fuzzer
|
||||
done
|
|
@ -0,0 +1,59 @@
|
|||
#!/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.
|
||||
|
||||
import atheris
|
||||
import sys
|
||||
with atheris.instrument_imports():
|
||||
from confluent_kafka import Consumer, KafkaException
|
||||
|
||||
def TestInput(data):
|
||||
fdp = atheris.FuzzedDataProvider(data)
|
||||
|
||||
def dummy_callback(err, partitions):
|
||||
pass
|
||||
|
||||
c = Consumer({
|
||||
'group.id': fdp.ConsumeString(10),
|
||||
'socket.timeout.ms': fdp.ConsumeIntInRange(10,2000),
|
||||
'session.timeout.ms': fdp.ConsumeIntInRange(10,2000),
|
||||
'on_commit': dummy_callback})
|
||||
|
||||
try:
|
||||
c.subscribe([fdp.ConsumeString(10)], on_assign=dummy_callback, on_revoke=dummy_callback)
|
||||
c.unsubscribe()
|
||||
|
||||
msg = c.poll(timeout=0.001)
|
||||
msglist = c.consume(num_messages=fdp.ConsumeIntInRange(1,10), timeout=0.001)
|
||||
|
||||
partitions = list(map(lambda part: TopicPartition(fdp.ConsumeString(10), part), range(0, 100, 3)))
|
||||
c.assign(partitions)
|
||||
c.unassign()
|
||||
|
||||
c.commit(asynchronous=fdp.ConsumeBool())
|
||||
c.committed(partitions, timeout=0.001)
|
||||
|
||||
c.list_topics(timeout=0.2)
|
||||
c.list_topics(topic=fdp.ConsumeString(10), timeout=0.1)
|
||||
except KafkaException as e:
|
||||
pass
|
||||
|
||||
c.close()
|
||||
|
||||
def main():
|
||||
atheris.Setup(sys.argv, TestInput, enable_python_coverage=True)
|
||||
atheris.Fuzz()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -0,0 +1,60 @@
|
|||
#!/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.
|
||||
|
||||
import atheris
|
||||
import sys
|
||||
with atheris.instrument_imports():
|
||||
from confluent_kafka import Producer, KafkaException
|
||||
|
||||
def TestInput(data):
|
||||
fdp = atheris.FuzzedDataProvider(data)
|
||||
|
||||
p = Producer({
|
||||
'socket.timeout.ms': fdp.ConsumeIntInRange(10,2000),
|
||||
'message.timeout.ms': fdp.ConsumeIntInRange(10,2000)
|
||||
})
|
||||
|
||||
p.produce(fdp.ConsumeString(20))
|
||||
p.produce(
|
||||
fdp.ConsumeString(20),
|
||||
value=fdp.ConsumeString(20),
|
||||
key=fdp.ConsumeString(20)
|
||||
)
|
||||
|
||||
def on_delivery(err, msg):
|
||||
pass
|
||||
|
||||
p.produce(
|
||||
topic=fdp.ConsumeString(20),
|
||||
value=fdp.ConsumeString(20),
|
||||
partition=fdp.ConsumeIntInRange(1,10),
|
||||
callback=on_delivery
|
||||
)
|
||||
|
||||
p.poll(0.001)
|
||||
p.flush(0.002)
|
||||
p.flush()
|
||||
|
||||
try:
|
||||
p.list_topics(timeout=0.2)
|
||||
except KafkaException as e:
|
||||
pass
|
||||
|
||||
def main():
|
||||
atheris.Setup(sys.argv, TestInput, enable_python_coverage=True)
|
||||
atheris.Fuzz()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -0,0 +1,12 @@
|
|||
fuzzing_engines:
|
||||
- libfuzzer
|
||||
homepage: https://github.com/confluentinc/confluent-kafka-python
|
||||
language: python
|
||||
main_repo: https://github.com/confluentinc/confluent-kafka-python
|
||||
sanitizers:
|
||||
- address
|
||||
- undefined
|
||||
vendor_ccs:
|
||||
- david@adalogics.com
|
||||
- adam@adalogics.com
|
||||
- arthur.chan@adalogics.com
|
Loading…
Reference in New Issue