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
@@ -15,7 +15,7 @@ import httpx
import pytest
from httpx import AsyncClient, Response
from pictures import GIF, JPEG, SAMPLE, WEBP, png
from pictures import BROKEN_PNG, GIF, JPEG, SAMPLE, WEBP, png
from stand import BASE_URL, bearer, compose, enroll, lb_up, psql, waited
pytestmark = pytest.mark.stack
@@ -310,6 +310,7 @@ async def test_user_errors_never_become_500(http: AsyncClient) -> None:
)
expect("PNG 8001×5000", await upload(http, alice, chat, png(8001, 5000, rows=False)), 413)
for label, content, kind in (
("PNG с корректными CRC и битым IDAT", BROKEN_PNG, "image/png"),
("обрезанный PNG", SAMPLE[: len(SAMPLE) // 2], "image/png"),
("обрезанный JPEG", JPEG[: len(JPEG) // 2], "image/jpeg"),
("JPEG как image/png", JPEG, "image/png"),