fix: address attachments verify findings

- keep one upload body in memory: BytesIO + getvalue() without copy,
  fixed glibc mmap threshold in the image (no realloc copy on growth)
- stop PNG inflate at expected size + 1 byte
- reject filename that is not valid UTF-8 after percent-decoding (400)
- failure stand: env limit variables do not change attachment limits;
  history with attachment_ids while S3 is stopped
- drop dead constants; restate "old image on new schema" scenario

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 02:16:49 +03:00
co-authored by Claude Opus 5.5
parent 8dc925e8ca
commit dba40bc325
23 changed files with 398 additions and 47 deletions
+39 -1
View File
@@ -15,7 +15,7 @@ from typing import Any
import pytest
import images
from api_client import Actor, Api
from api_client import API, Actor, Api
from contract import (
BEARER_CHALLENGE,
assert_content,
@@ -351,6 +351,44 @@ def test_dangerous_filename(
)
@pytest.mark.spec("attachments", "Имя не в UTF-8")
def test_filename_not_utf8(
api: Api,
alice: Actor,
chat: dict[str, Any],
) -> None:
"""Процент-коды `filename` идут в строке запроса как есть: httpx их
не перекодирует. Без строгого разбора `a%FFb.png` давал 201 с U+FFFD
в имени вместо байта."""
data = images.sample_png()
path = f"{API}/chats/{chat['id']}/attachments"
def upload(query: str) -> Any:
return api.request(
"POST",
f"{path}?{query}",
actor=alice,
headers={"Content-Type": "image/png"},
content=data,
)
assert_errors(
{
"invalid byte": upload("filename=a%FFb.png"),
"truncated sequence": upload("filename=a%C3.png"),
"encoded surrogate": upload("filename=a%ED%A0%80b.png"),
},
400,
)
# верный UTF-8 в процент-кодах — то же имя, что прислано
attachment = assert_ok(
upload("filename=%C3%A9t%C3%A9.png"),
201,
"Attachment",
)
assert attachment["filename"] == "été.png"
def assert_name_kept(
api: Api,
actor: Actor,