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

Add a fuzzer for ImageCms.buildTransform #7792

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions Tests/oss-fuzz/fuzz_imagecms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/python3

# Copyright 2024 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 __future__ import annotations

import atheris

with atheris.instrument_imports():
import sys

import fuzzers

MODES = [
"1",
"L",
"P",
"RGB",
"RGBA",
"CMYK",
"YCbCr",
"LAB",
"HSV",
"I",
"F",
"LA",
"PA",
"RGBX",
"RGBa",
"La",
"I;16",
"I;16L",
"I;16B",
"I;16N",
"BGR;15",
"BGR;16",
"BGR;24",
]


def TestOneInput(data: bytes) -> None:
fdp = atheris.FuzzedDataProvider(data)

mode1 = fdp.PickValueInList(MODES)
mode2 = fdp.PickValueInList(MODES)
in_transform = fdp.PickValueInList(MODES)
out_transform = fdp.PickValueInList(MODES)

try:
fuzzers.fuzz_cms(mode1, mode2, in_transform, out_transform)
except Exception:
# We're catching all exceptions because Pillow's exceptions are
# directly inheriting from Exception.
pass


def main() -> None:
fuzzers.enable_decompressionbomb_error()
atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
fuzzers.disable_decompressionbomb_error()


if __name__ == "__main__":
main()
8 changes: 7 additions & 1 deletion Tests/oss-fuzz/fuzzers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io
import warnings

from PIL import Image, ImageDraw, ImageFile, ImageFilter, ImageFont
from PIL import Image, ImageCms, ImageDraw, ImageFile, ImageFilter, ImageFont


def enable_decompressionbomb_error() -> None:
Expand All @@ -26,6 +26,12 @@
im.save(io.BytesIO(), "BMP")


def fuzz_cms(profile1, profile2, trans1, trans2) -> None:
p1 = ImageCms.createProfile(profile1)
p2 = ImageCms.createProfile(profile2)
t = ImageCms.buildTransform(p1, p2, trans1, trans2)

Check warning on line 32 in Tests/oss-fuzz/fuzzers.py

View check run for this annotation

Codecov / codecov/patch

Tests/oss-fuzz/fuzzers.py#L30-L32

Added lines #L30 - L32 were not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
t = ImageCms.buildTransform(p1, p2, trans1, trans2)
ImageCms.buildTransform(p1, p2, trans1, trans2)

Lint fix.



def fuzz_font(data: bytes) -> None:
wrapper = io.BytesIO(data)
try:
Expand Down
Loading