Reject corrupt PNG pixels with bounded stream validation

This commit is contained in:
Artyom
2026-11-06 12:57:32 +03:00
parent f0521fa1e0
commit 9387c3d82a
9 changed files with 420 additions and 6 deletions
@@ -6,6 +6,7 @@ from PIL import Image
from messenger.attachments.domain.errors import PayloadTooLarge, UnsupportedImage
from messenger.attachments.domain.values import ImageInfo, ImageKind
from messenger.attachments.infrastructure.png import verify_png_pixels
KINDS = {"PNG": ImageKind.PNG, "JPEG": ImageKind.JPEG}
BOMBS = (Image.DecompressionBombError, Image.DecompressionBombWarning)
@@ -44,6 +45,7 @@ class PillowImageInspector:
image.load()
else:
image.verify()
verify_png_pixels(data)
except Exception as error:
raise UnsupportedImage("изображение повреждено или обрезано") from error
return ImageInfo(kind, width, height)