-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[pillow] Pillow fuzzers #2626
Merged
Merged
[pillow] Pillow fuzzers #2626
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,24 @@ | ||
# Copyright 2019 Google Inc. | ||
# | ||
# 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 | ||
MAINTAINER guidovranken@gmail.com | ||
RUN apt-get update && apt-get install -y make autoconf automake build-essential libbz2-dev libc6-dev libffi-dev libfreetype6-dev libgdbm-dev libjpeg-turbo8-dev liblcms2-dev libncursesw5-dev libreadline-dev libsqlite3-dev libssl-dev libtiff5-dev libtool libwebp-dev make python python-dev python-setuptools tk-dev wget zlib1g-dev | ||
RUN wget https://github.com/python/cpython/archive/v3.8.0b2.tar.gz | ||
RUN git clone --depth 1 https://github.com/python-pillow/Pillow.git pillow | ||
RUN git clone --depth 1 https://github.com/guidovranken/oss-fuzz-fuzzers | ||
WORKDIR pillow | ||
COPY build.sh $SRC/ |
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,109 @@ | ||
#!/bin/bash -eu | ||
# Copyright 2019 Google Inc. | ||
# | ||
# 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. | ||
# | ||
################################################################################ | ||
|
||
# Because Pillow's "./setup.py build_ext --inplace" does not work with custom CC and CFLAGS, | ||
# it is necessary to build in the following manner: | ||
# | ||
# Build CPython without instrumentation/sanitization | ||
# Build Pillow in a virtualenv based on uninstrumented and unsanitized CPython. Log the build steps to build.sh | ||
# Build CPython with instrumentation/sanitization | ||
# Rewrite build.sh to compile Pillow based on CPython with instrumentation/sanitization | ||
# | ||
# Why not build Pillow directly with a virtualenv based on instrumented CPython? | ||
# Because the virtualenv will inherit CC and CFLAGS of the instrumented CPython, and that will fail. | ||
|
||
cd $SRC/ | ||
tar zxf v3.8.0b2.tar.gz | ||
cd cpython-3.8.0b2/ | ||
|
||
# Ignore memory leaks from python scripts invoked in the build | ||
export ASAN_OPTIONS="detect_leaks=0" | ||
export MSAN_OPTIONS="halt_on_error=0:exitcode=0:report_umrs=0" | ||
|
||
# Remove -pthread from CFLAGS, this trips up ./configure | ||
# which thinks pthreads are available without any CLI flags | ||
CFLAGS=${CFLAGS//"-pthread"/} | ||
|
||
FLAGS=() | ||
case $SANITIZER in | ||
address) | ||
FLAGS+=("--with-address-sanitizer") | ||
;; | ||
memory) | ||
FLAGS+=("--with-memory-sanitizer") | ||
# installing ensurepip takes a while with MSAN instrumentation, so | ||
# we disable it here | ||
FLAGS+=("--without-ensurepip") | ||
# -msan-keep-going is needed to allow MSAN's halt_on_error to function | ||
FLAGS+=("CFLAGS=-mllvm -msan-keep-going=1") | ||
;; | ||
undefined) | ||
FLAGS+=("--with-undefined-behavior-sanitizer") | ||
;; | ||
esac | ||
|
||
export CPYTHON_INSTALL_PATH=$OUT/cpython-install | ||
rm -rf $CPYTHON_INSTALL_PATH | ||
mkdir $CPYTHON_INSTALL_PATH | ||
|
||
export CPYTHON_UNINSTRUMENTED_INSTALL_PATH=$OUT/cpython-install | ||
rm -rf $CPYTHON_UNINSTRUMENTED_INSTALL_PATH | ||
mkdir $CPYTHON_UNINSTRUMENTED_INSTALL_PATH | ||
|
||
cd $SRC/ | ||
tar zxf v3.8.0b2.tar.gz | ||
|
||
# Compile uninstrumented CPython | ||
cp -R $SRC/cpython-3.8.0b2/ $SRC/cpython-3.8.0b2-uninstrumented | ||
cd $SRC/cpython-3.8.0b2-uninstrumented | ||
CFLAGS="" CXXFLAGS="" ./configure --prefix=$CPYTHON_UNINSTRUMENTED_INSTALL_PATH | ||
CFLAGS="" CXXFLAGS="" make -j$(nproc) | ||
CFLAGS="" CXXFLAGS="" make install | ||
|
||
# Compile instrumented CPython | ||
cd $SRC/cpython-3.8.0b2/ | ||
cp $SRC/oss-fuzz-fuzzers/pillow/python_coverage.h Python/ | ||
|
||
# Patch the interpreter to record code coverage | ||
sed -i '1 s/^.*$/#include "python_coverage.h"/g' Python/ceval.c | ||
sed -i 's/case TARGET\(.*\): {/\0\nfuzzer_record_code_coverage(f->f_code, f->f_lasti);/g' Python/ceval.c | ||
|
||
./configure "${FLAGS[@]}" --prefix=$CPYTHON_INSTALL_PATH | ||
make -j$(nproc) | ||
make install | ||
|
||
# Compile Pillow fuzzers | ||
cd $SRC/oss-fuzz-fuzzers/pillow | ||
rm $CPYTHON_INSTALL_PATH/lib/python3.8/lib-dynload/_tkinter*.so | ||
make | ||
cp $SRC/oss-fuzz-fuzzers/pillow/fuzzer-loadimg $OUT/ | ||
cp $SRC/oss-fuzz-fuzzers/pillow/loadimg.py $OUT/ | ||
|
||
# Create venv for Pillow compilation | ||
$CPYTHON_UNINSTRUMENTED_INSTALL_PATH/bin/python3 -m venv $SRC/venv | ||
source $SRC/venv/bin/activate | ||
|
||
# Compile Pillow | ||
cd $SRC/pillow | ||
CFLAGS="" CXXFLAGS="" ./setup.py build_ext --inplace >build.sh | ||
grep "^\(gcc\|x86_64-linux-gnu-gcc\|clang\) " build.sh | sed 's/^\(gcc\|x86_64-linux-gnu-gcc\|clang\) /$CC $CFLAGS /g' | sed 's/-DPILLOW_VERSION="\([^"]\+\)"/-DPILLOW_VERSION="\\"\1\\""/g' >build2.sh | ||
bash build2.sh | ||
find | ||
cp -R $SRC/pillow $OUT/ | ||
cp /usr/lib/x86_64-linux-gnu/libjpeg.so.8 $OUT/ | ||
cp /usr/lib/x86_64-linux-gnu/libtiff.so.5 $OUT/ | ||
cp /usr/lib/x86_64-linux-gnu/libjbig.so.0 $OUT/ |
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 @@ | ||
homepage: "https://python-pillow.org/" | ||
primary_contact: "guidovranken@gmail.com" | ||
auto_ccs: | ||
- "security@python-pillow.org" | ||
sanitizers: | ||
- address | ||
- undefined | ||
architectures: | ||
- x86_64 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you also like to cc someone at Pillow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally got around to this. Please write 1 or more Pillow CC's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
security@python-pillow.org thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this address linked to a Google account, or can you do that? If not, you will get e-mail notifications, but cannot see bug report contents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you'd like this to be merged, then we can at least get the e-mail notifications with that address, and can return to it later if we so choose. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.