Исправить замечания ревью: битый JPEG, память nginx, 502 вместо 413

JPEG проверяется через djpeg -strict: обрезанный поток с дописанным EOI
теперь даёт 415. Память nginx больше не зависит от тел файлов: загрузка
идёт потоком до API, скачивание без временных файлов, воркеров 2. API не
закрывает соединение при недочитанном теле, что давало HTML 502; nginx
сам отклоняет тела больше лимитов API. Лимит памяти API поднят до 512 MiB
под проверку CMYK-JPEG на 40 Мпикс. Добавлен стресс-тест через LB.
This commit is contained in:
alenchha
2026-11-05 13:53:08 +03:00
parent 2152d0dcad
commit a856128b45
19 changed files with 470 additions and 86 deletions
+11
View File
@@ -3,6 +3,7 @@
import hashlib
import os
import struct
import subprocess
import sys
import uuid
import zlib
@@ -44,6 +45,16 @@ def main():
up(png(64, 64, corrupt_idat=True), "image/png", 415)
up(JPEG_STUB, "image/jpeg", 415)
print("ok truncated PNG, bad filter byte, broken IDAT, 27-byte JPEG stub -> 415")
real = subprocess.run(
["docker", "run", "--rm", "--entrypoint", "python", "mtusi-messenger:lab4", "-c",
"import io,os,sys;from PIL import Image;b=io.BytesIO();"
"Image.frombytes('RGB',(1000,750),os.urandom(2250000)).save(b,'JPEG',quality=90);"
"sys.stdout.buffer.write(b.getvalue())"], capture_output=True, check=True).stdout
whole = up(real, "image/jpeg", 201, name="real.jpg")["json"]
check(c.call("GET", "/api/v1/attachments/" + whole["id"] + "/content", actor=bob)["bytes"] == real, "JPEG bytes differ")
up(real[: len(real) // 2] + b"\xff\xd9", "image/jpeg", 415, name="cut.jpg")
up(real[: len(real) // 2], "image/jpeg", 415, name="cut.jpg")
print("ok real JPEG accepted; first half + EOI and first half alone -> 415")
up(png(3000, 2000, filter_byte=7), "image/png", 415)
up(png(3000, 2000, corrupt_idat=True, noise=True), "image/png", 415)
print("ok same defects in images above the full-decode threshold (6 Mpx) -> 415")