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
+5
View File
@@ -29,9 +29,14 @@ RUN groupadd --system --gid 10001 app \
&& useradd --system --uid 10001 --gid app --no-create-home \
--home-dir /nonexistent --shell /usr/sbin/nologin app
# MALLOC_MMAP_THRESHOLD_: блоки от 128 KiB всегда в mmap, и буфер тела
# загрузки растёт через mremap без копии. Без него glibc после первой
# загрузки поднимает порог, буфер растёт в куче, и realloc на миг держит
# два тела (design change `attachments`, решение 6)
ENV PATH=/app/.venv/bin:$PATH \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
MALLOC_MMAP_THRESHOLD_=131072 \
APP__RUN_MODE=docker
WORKDIR /app