Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9e08eb8

Browse filesBrowse files
committed
Raise ValueError if color specifier is too long
1 parent bd5cf7d commit 9e08eb8
Copy full SHA for 9e08eb8

File tree

Expand file treeCollapse file tree

2 files changed

+11
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+11
-0
lines changed
Open diff view settings
Collapse file

‎Tests/test_imagecolor.py‎

Copy file name to clipboardExpand all lines: Tests/test_imagecolor.py
+9Lines changed: 9 additions & 0 deletions
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)
Collapse file

‎src/PIL/ImageColor.py‎

Copy file name to clipboardExpand all lines: src/PIL/ImageColor.py
+2Lines changed: 2 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.