[AZ-175] Restore image validation for corrupt/oversized uploads in /detect endpoint

Made-with: Cursor
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-03-31 06:46:34 +03:00
parent da32c2e6bd
commit 948b50ae3a
+5
View File
@@ -361,6 +361,11 @@ async def detect_image(
orig_name = file.filename or "upload"
kind, ext = _detect_upload_kind(orig_name, image_bytes)
if kind == "image":
arr = np.frombuffer(image_bytes, dtype=np.uint8)
if cv2.imdecode(arr, cv2.IMREAD_COLOR) is None:
raise HTTPException(status_code=400, detail="Invalid image data")
config_dict = {}
if config:
config_dict = json.loads(config)