fix(multimodal): return 400 for corrupt image inputs (#28131)
Signed-off-by: Ting Sun <suntcrick@gmail.com> Co-authored-by: Justin Tong <justintong0323@users.noreply.github.com> Co-authored-by: Xinyuan Tong <115166877+JustinTong0323@users.noreply.github.com>
This commit is contained in:
co-authored by
Justin Tong
Xinyuan Tong
parent
0154f72b48
commit
31b931edc3
@@ -1950,7 +1950,7 @@ def _load_image(
|
||||
)
|
||||
try:
|
||||
image = Image.open(BytesIO(image_bytes))
|
||||
except OSError as e:
|
||||
except (OSError, SyntaxError) as e:
|
||||
raise ValueError(f"Could not decode image: {e}") from e
|
||||
return _fully_load_pil_image(image)
|
||||
|
||||
@@ -1959,7 +1959,7 @@ def _fully_load_pil_image(image: Image.Image) -> Image.Image:
|
||||
"""Force PIL's lazy decode while malformed input is still request-local."""
|
||||
try:
|
||||
image.load()
|
||||
except OSError as e:
|
||||
except (OSError, SyntaxError) as e:
|
||||
raise ValueError(f"Could not decode image: {e}") from e
|
||||
return image
|
||||
|
||||
|
||||
Reference in New Issue
Block a user