aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Mandic <mandic00@live.com>2023-01-23 17:11:22 -0500
committerGitHub <noreply@github.com>2023-01-23 17:11:22 -0500
commit45e270dfc853216b2c413f915946f0f2842e57a4 (patch)
tree879bb01702ca86eef994bcb0bd5931e33dd85c50
parent5c1cb9263f980641007088a37360fcab01761d37 (diff)
add image decod exception handling
-rw-r--r--modules/api/api.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/modules/api/api.py b/modules/api/api.py
index b1dd14cc..e6e31e41 100644
--- a/modules/api/api.py
+++ b/modules/api/api.py
@@ -53,7 +53,11 @@ def setUpscalers(req: dict):
def decode_base64_to_image(encoding):
if encoding.startswith("data:image/"):
encoding = encoding.split(";")[1].split(",")[1]
- return Image.open(BytesIO(base64.b64decode(encoding)))
+ try:
+ image = Image.open(BytesIO(base64.b64decode(encoding)))
+ return image
+ except Exception as err:
+ raise HTTPException(status_code=500, detail="Invalid encoded image")
def encode_pil_to_base64(image):
with io.BytesIO() as output_bytes: