Skip to content

Commit

Permalink
Raise ValueError if color specifier is too long
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Sep 2, 2021
1 parent bd5cf7d commit 9e08eb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Tests/test_imagecolor.py
Expand Up @@ -191,3 +191,12 @@ def test_rounding_errors():
assert (255, 255) == ImageColor.getcolor("white", "LA")
assert (163, 33) == ImageColor.getcolor("rgba(0, 255, 115, 33)", "LA")
Image.new("LA", (1, 1), "white")


def test_color_too_long():
# Arrange
color_too_long = "hsl(" + "1" * 100 + ")"

# Act / Assert
with pytest.raises(ValueError):
ImageColor.getrgb(color_too_long)
2 changes: 2 additions & 0 deletions src/PIL/ImageColor.py
Expand Up @@ -32,6 +32,8 @@ def getrgb(color):
:param color: A color string
:return: ``(red, green, blue[, alpha])``
"""
if len(color) > 100:
raise ValueError("color specifier is too long")
color = color.lower()

rgb = colormap.get(color, None)
Expand Down

0 comments on commit 9e08eb8

Please sign in to comment.