"vscode:/vscode.git/clone" did not exist on "ea0899d0572c45e0440893e55cdd1a7524624736"
Unverified Commit b8fefa6b authored by Leo Tronchon's avatar Leo Tronchon Committed by GitHub
Browse files

raise exception on invalid images (#999)



# What does this PR do?
This PR is meant to handle cases in which the images provided are
invalid.

## Who can review?

Anyone in the community is free to review the PR once the tests have
passed. Feel free to tag
members/contributors who may be interested in your PR.

@Narsil

---------
Co-authored-by: default avatarNicolas Patry <patry.nicolas@protonmail.com>
parent bd998d87
......@@ -194,9 +194,14 @@ class IdeficsImageProcessor(BaseImageProcessor):
if isinstance(image_url_or_urls, list):
return [self.fetch_images(x) for x in image_url_or_urls]
elif isinstance(image_url_or_urls, str):
response = requests.get(image_url_or_urls, stream=True, headers=headers)
response = requests.get(image_url_or_urls, stream=True, headers=headers, timeout=(1, 5))
response.raise_for_status()
return Image.open(BytesIO(response.content))
try:
image = Image.open(BytesIO(response.content))
image.verify()
except Exception:
raise ValueError(f"Could not load image from url {image_url_or_urls}")
return image
else:
raise ValueError(
f"only a single or a list of entries is supported but got type={type(image_url_or_urls)}"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment