From f32e7e18a62594f93ae4c1c557c9ff0f344b8f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BB=D1=8C=D0=B5=D0=B2=20=D0=9D?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Fri, 6 Nov 2026 19:12:03 +0300 Subject: [PATCH] docs: verify full-range image validation and record bounded-memory receipts --- REPORT.md | 15 +++- evidence/contract-image-fix-final.txt | 4 + evidence/image-validation-after.txt | 2 + evidence/image-validation-before.txt | 82 +++++++++++++++++++ .../image-validation-memory-single-api.json | 23 ++++++ evidence/image-validation-memory.json | 63 ++++++++++++++ evidence/lint-image-fix-final.txt | 1 + evidence/smoke-image-fix-final.txt | 1 + evidence/tests-image-fix-final.txt | 4 + evidence/validation-process-final.txt | 2 + src/messenger/attachments.py | 4 + 11 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 evidence/contract-image-fix-final.txt create mode 100644 evidence/image-validation-after.txt create mode 100644 evidence/image-validation-before.txt create mode 100644 evidence/image-validation-memory-single-api.json create mode 100644 evidence/image-validation-memory.json create mode 100644 evidence/lint-image-fix-final.txt create mode 100644 evidence/smoke-image-fix-final.txt create mode 100644 evidence/tests-image-fix-final.txt create mode 100644 evidence/validation-process-final.txt diff --git a/REPORT.md b/REPORT.md index 5d8319e4..33be65d5 100644 --- a/REPORT.md +++ b/REPORT.md @@ -114,18 +114,27 @@ docker compose run --rm --no-deps research ### Результат десяти конкурентных upload +`upload-memory-final.json` — исходный снимок до поздних исправлений валидатора. Его данные и hashes не переписаны. Отдельная новая image-validation проверка ниже проверяет текущий short-lived child на больших файлах; это другой сценарий, не подмена старого эксперимента. + + После рестарта API с сохранением старого токена проверены PNG 788100 и 8683594 байт. На каждом размере десять клиентов начали одновременно; **2 получили 201, 8 — контролируемый 429**, затем readiness200. У API и LB `oom=0`, `oom_kill=0`, процессы остались живы. Cgroup lifetime peaks: API 122773504 и122679296 байт, LB19656704 байт. Лимиты соответственно512/512/128MiB. Before/after peaks не выросли: начальная загрузка приложения/Argon2 уже создала больший high-water. Поэтому опыт доказывает ограниченное поведение выбранной нагрузки без OOM, но не выделяет точную память одной загрузки и не доказывает экономию RAM самим spool. +### Поздняя проверка полного диапазона изображений + +Повторное изучение замечаний обнаружило допустимый36M progressiveRGBJPEG, который прежний nativebudget192MiB отклонял, и APNG с повреждённым вторым кадром. Регрессия на отдельном Docker project до правки:3 failed/1 passed. После правки проверены большие RGB/CMYK progressiveJPEG, маленькиеCMYK baseline/progressive, полный APNG decode, повреждённый later frame, rawacTL0/forgedcount, default image,40M cumulative boundary и50M rejection. Последовательность APNG40M→CMYK40M→RGB36M→обычныйPNG возвращает201 с неизменными original bytes при API512MiB и безOOM. Пик/счётчики и текущие source hashes сохранены в отдельном receipt. + +Полный собственный набор после основной правки:155 passed; child timeout/crash boundary дополнительно проверена пятью unit-тестами. Финальные smoke/schema/lint и целевые image-регрессии находятся в новых evidence с суффиксом image-fix. + ## Проверки и доказательства | Критерий | Сценарий | Доказательство | |---|---|---| | Контракт и схема | make check validate | evidence/contract-checks.txt | -| Обязательный API, PNG/ACL/checksum/idempotency | make test | evidence/smoke-final.txt | -| Негативные/параллельные/Unicode/вложения/cursor | make student-test | evidence/tests-final.txt | -| Повреждённый JPEG с поддельным EOI | regression до исправления и полный тест после djpeg | evidence/attachments-before-strict-jpeg.txt; evidence/tests-final.txt | +| Обязательный API, PNG/ACL/checksum/idempotency | make test | evidence/smoke-image-fix-final.txt | +| Негативные/параллельные/Unicode/вложения/cursor | make student-test | evidence/tests-image-fix-final.txt | +| Повреждённый JPEG с поддельным EOI | regression до исправления и полный тест после djpeg | evidence/attachments-before-strict-jpeg.txt; evidence/tests-image-fix-final.txt | | Независимая проверка реального HTTP | root external regression | Отдельная итоговая проверка общего пакета | | Десять одновременных upload | research/upload_memory.py | evidence/upload-memory-final.json | | Reconciler/fault-injection/стоимость | tools profile research | evidence/reconcile-study.json | diff --git a/evidence/contract-image-fix-final.txt b/evidence/contract-image-fix-final.txt new file mode 100644 index 00000000..ed9cd475 --- /dev/null +++ b/evidence/contract-image-fix-final.txt @@ -0,0 +1,4 @@ +.venv/bin/python scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. +.venv/bin/python scripts/validate_openapi.py +PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested. diff --git a/evidence/image-validation-after.txt b/evidence/image-validation-after.txt new file mode 100644 index 00000000..eca467c7 --- /dev/null +++ b/evidence/image-validation-after.txt @@ -0,0 +1,2 @@ +...................... [100%] +22 passed in 13.29s diff --git a/evidence/image-validation-before.txt b/evidence/image-validation-before.txt new file mode 100644 index 00000000..7f6b893d --- /dev/null +++ b/evidence/image-validation-before.txt @@ -0,0 +1,82 @@ +FF.F [100%] +=================================== FAILURES =================================== +_______________ test_36m_progressive_jpeg_is_valid_and_unchanged _______________ + +scenario = (, {'id': 'ef1e6ee9-739a-4dfe-8b05-78bef274c542', 'user': {'id': 'ef1e6ee9-739a-4...-06T15:51:51.913231Z', 'member_ids': ['ef1e6ee9-739a-4dfe-8b05-78bef274c542', '830c471d-1354-43d3-9241-ef98ffc87c7c']}) + + def test_36m_progressive_jpeg_is_valid_and_unchanged(scenario): + data = progressive_jpeg() +> attachment = upload(scenario, data, "image/jpeg", 201)["json"] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +student-tests/test_image_edges.py:73: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +student-tests/test_image_edges.py:21: in upload + return c.call( +tests/client.py:132: in call + check(status in allowed, method + ' ' + path.split('?')[0] + ': expected ' + str(allowed) + ', received ' + str(status)) +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +condition = False +message = 'POST /api/v1/chats/e9b3f246-cba5-470b-b88f-35da5340b635/attachments: expected [201], received 415' + + def check(condition, message): + if not condition: +> raise Failure(message) +E client.Failure: POST /api/v1/chats/e9b3f246-cba5-470b-b88f-35da5340b635/attachments: expected [201], received 415 + +tests/client.py:24: Failure +__________________ test_apng_corrupt_later_frame_is_rejected ___________________ + +scenario = (, {'id': 'ef1e6ee9-739a-4dfe-8b05-78bef274c542', 'user': {'id': 'ef1e6ee9-739a-4...-06T15:51:51.913231Z', 'member_ids': ['ef1e6ee9-739a-4dfe-8b05-78bef274c542', '830c471d-1354-43d3-9241-ef98ffc87c7c']}) + + def test_apng_corrupt_later_frame_is_rejected(scenario): +> upload(scenario, broken_later_frame(apng()), "image/png", 415) + +student-tests/test_image_edges.py:81: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +student-tests/test_image_edges.py:21: in upload + return c.call( +tests/client.py:132: in call + check(status in allowed, method + ' ' + path.split('?')[0] + ': expected ' + str(allowed) + ', received ' + str(status)) +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +condition = False +message = 'POST /api/v1/chats/e9b3f246-cba5-470b-b88f-35da5340b635/attachments: expected [415], received 201' + + def check(condition, message): + if not condition: +> raise Failure(message) +E client.Failure: POST /api/v1/chats/e9b3f246-cba5-470b-b88f-35da5340b635/attachments: expected [415], received 201 + +tests/client.py:24: Failure +______________________ test_apng_cumulative_canvas_limit _______________________ + +scenario = (, {'id': 'ef1e6ee9-739a-4dfe-8b05-78bef274c542', 'user': {'id': 'ef1e6ee9-739a-4...-06T15:51:51.913231Z', 'member_ids': ['ef1e6ee9-739a-4dfe-8b05-78bef274c542', '830c471d-1354-43d3-9241-ef98ffc87c7c']}) + + def test_apng_cumulative_canvas_limit(scenario): + # Two 25M-pixel canvases exceed the total 40M decode budget. +> upload(scenario, apng((5000, 5000)), "image/png", 413) + +student-tests/test_image_edges.py:95: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +student-tests/test_image_edges.py:21: in upload + return c.call( +tests/client.py:132: in call + check(status in allowed, method + ' ' + path.split('?')[0] + ': expected ' + str(allowed) + ', received ' + str(status)) +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +condition = False +message = 'POST /api/v1/chats/e9b3f246-cba5-470b-b88f-35da5340b635/attachments: expected [413], received 201' + + def check(condition, message): + if not condition: +> raise Failure(message) +E client.Failure: POST /api/v1/chats/e9b3f246-cba5-470b-b88f-35da5340b635/attachments: expected [413], received 201 + +tests/client.py:24: Failure +=========================== short test summary info ============================ +FAILED student-tests/test_image_edges.py::test_36m_progressive_jpeg_is_valid_and_unchanged +FAILED student-tests/test_image_edges.py::test_apng_corrupt_later_frame_is_rejected +FAILED student-tests/test_image_edges.py::test_apng_cumulative_canvas_limit +3 failed, 1 passed in 2.41s diff --git a/evidence/image-validation-memory-single-api.json b/evidence/image-validation-memory-single-api.json new file mode 100644 index 00000000..153b2e40 --- /dev/null +++ b/evidence/image-validation-memory-single-api.json @@ -0,0 +1,23 @@ +{ + "scenario": "APNG40M\u2192CMYK40M\u2192RGB36M\u2192ordinaryPNG, plus malformed frames/JPEG and repeated cases", + "api_limit_bytes": 536870912, + "containers": [ + { + "id": "7b1331ef2f48894e180f55aa43a7fc926ebdb8119b70c6b12e6154ddd7718c41", + "image": "sha256:0f1975a55bf57b7a413815f678e29d500924f18a1485e2e3000aa9b09c2e23ae", + "current_bytes": 88059904, + "peak_bytes": 426946560, + "events": { + "low": 0, + "high": 0, + "max": 0, + "oom": 0, + "oom_kill": 0, + "oom_group_kill": 0 + }, + "running": true, + "oom_killed": false, + "limit_bytes": 536870912 + } + ] +} diff --git a/evidence/image-validation-memory.json b/evidence/image-validation-memory.json new file mode 100644 index 00000000..2e804be9 --- /dev/null +++ b/evidence/image-validation-memory.json @@ -0,0 +1,63 @@ +{ + "api_limit_bytes": 536870912, + "native_budget_mib": 384, + "child_linux_as_mib": 512, + "child_cpu_seconds": 4, + "parent_wall_seconds": 5, + "scenario": "APNG40M\u2192CMYK40M\u2192RGB36M\u2192ordinaryPNG plus malformed/full-range cases", + "targeted_result": "22 passed in 13.29s", + "full_suite_result": "155 passed in 50.44s", + "final_source_hashes": { + "src/messenger/__init__.py": "9a72a49106367ca514cc6147d0e727e62c4d33fefd61572d209a5c9494551a2c", + "src/messenger/__main__.py": "ba9a59ad44ee8884cd65cf88d5ea15cbd7051b10f7c729043ddd44ca2f34defe", + "src/messenger/app.py": "bea8bc70db73e99cb26a794db9549ff6d5ffc51951e587c44c36ea2656410e54", + "src/messenger/attachments.py": "fb8735c19140c96b16ecdc7b643c175c8e418bfa9683a986d5c9c92617dc8082", + "src/messenger/config.py": "e4d4aaf674ede8b5abdc361f77c7793ee94d8d7856030c28834eb7c95291b193", + "src/messenger/domain.py": "7bf6f177ab5bdeea09b303dc886160335d348f64f47912b9bba45355db378bef", + "src/messenger/image_validation.py": "d9aa8db65edaab88c9a76cf2e5459ad3028ba808579311aeb0d8c4f01f875720", + "src/messenger/migrate.py": "eb5cad7ac6abe38dd40b2db307d298b297abe9543b3928c36bab8ef06283664e", + "src/messenger/models.py": "c43769d2d4ba0369129a86bf80364a626ab91442f9b9020e6bc904e363a39665", + "src/messenger/postgres.py": "8a9c0cd275bbb04604d94c1a0155176e9f0348d1e05abe2120c74b0b83f36f6c", + "src/messenger/reconcile.py": "792e21f50e777458df367069694e5ff751817fff4dbec4276e4d73e9c64a2fd7", + "src/messenger/storage.py": "70b0fb157b285b674a7388a2bfe5c5a7feb8149a9266ac7ad035961d769008a5", + "src/messenger/storage_bootstrap.py": "b29a2a1f8864ec3425a7499b1752688f69d8f402f3881957e790ed4522d35589" + }, + "containers": [ + { + "id": "beb1633f31867054f0f1d251df15769de8c8a7a8ee955fb1c5a4df75b0a7fb88", + "image": "sha256:362e7406d132beae97a8824381832939f98de42b02ac914367b0a6edf8549ce6", + "current_bytes": 83705856, + "peak_bytes": 422154240, + "events": { + "low": 0, + "high": 0, + "max": 0, + "oom": 0, + "oom_kill": 0, + "oom_group_kill": 0 + }, + "running": true, + "oom_killed": false, + "limit_bytes": 536870912, + "runtime_source_matches": true + }, + { + "id": "8368fe5482e93bba9a337f21aca3e7e72c6a3844bb2ecd451878c66bbb07aa33", + "image": "sha256:362e7406d132beae97a8824381832939f98de42b02ac914367b0a6edf8549ce6", + "current_bytes": 83824640, + "peak_bytes": 422637568, + "events": { + "low": 0, + "high": 0, + "max": 0, + "oom": 0, + "oom_kill": 0, + "oom_group_kill": 0 + }, + "running": true, + "oom_killed": false, + "limit_bytes": 536870912, + "runtime_source_matches": true + } + ] +} diff --git a/evidence/lint-image-fix-final.txt b/evidence/lint-image-fix-final.txt new file mode 100644 index 00000000..1f5f344d --- /dev/null +++ b/evidence/lint-image-fix-final.txt @@ -0,0 +1 @@ +All checks passed! diff --git a/evidence/smoke-image-fix-final.txt b/evidence/smoke-image-fix-final.txt new file mode 100644 index 00000000..c554fd6f --- /dev/null +++ b/evidence/smoke-image-fix-final.txt @@ -0,0 +1 @@ +PASS: lab4 public API scenario; infrastructure and grading evidence remain separate. diff --git a/evidence/tests-image-fix-final.txt b/evidence/tests-image-fix-final.txt new file mode 100644 index 00000000..bdd6655d --- /dev/null +++ b/evidence/tests-image-fix-final.txt @@ -0,0 +1,4 @@ +........................................................................ [ 46%] +........................................................................ [ 92%] +........... [100%] +155 passed in 50.44s diff --git a/evidence/validation-process-final.txt b/evidence/validation-process-final.txt new file mode 100644 index 00000000..d506421d --- /dev/null +++ b/evidence/validation-process-final.txt @@ -0,0 +1,2 @@ +..... [100%] +5 passed in 0.14s diff --git a/src/messenger/attachments.py b/src/messenger/attachments.py index cb6fcff4..3036db07 100644 --- a/src/messenger/attachments.py +++ b/src/messenger/attachments.py @@ -70,6 +70,10 @@ def validate_image(fileobj, declared_type): process.communicate() raise Failure(415, "Изображение не прошло ограниченную проверку") from None if process.returncode: + try: + os.killpg(process.pid, signal.SIGKILL) + except ProcessLookupError: + pass raise Failure(415, "Изображение не прошло ограниченную проверку") except OSError: raise Failure(503, "Проверка изображения временно недоступна") from None