Skip to content

Commit 9e08eb8

Browse files
committed
Raise ValueError if color specifier is too long
1 parent bd5cf7d commit 9e08eb8

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Tests/test_imagecolor.py

+9
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,12 @@ def test_rounding_errors():
191191
assert (255, 255) == ImageColor.getcolor("white", "LA")
192192
assert (163, 33) == ImageColor.getcolor("rgba(0, 255, 115, 33)", "LA")
193193
Image.new("LA", (1, 1), "white")
194+
195+
196+
def test_color_too_long():
197+
# Arrange
198+
color_too_long = "hsl(" + "1" * 100 + ")"
199+
200+
# Act / Assert
201+
with pytest.raises(ValueError):
202+
ImageColor.getrgb(color_too_long)

src/PIL/ImageColor.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def getrgb(color):
3232
:param color: A color string
3333
:return: ``(red, green, blue[, alpha])``
3434
"""
35+
if len(color) > 100:
36+
raise ValueError("color specifier is too long")
3537
color = color.lower()
3638

3739
rgb = colormap.get(color, None)

0 commit comments

Comments
 (0)