Record final validation and boundary PNG memory failure

This commit is contained in:
Artyom
2026-11-07 00:30:38 +03:00
parent b30e2f6a84
commit 8b84ebf6d6
57 changed files with 4620 additions and 20 deletions
@@ -0,0 +1,42 @@
import hashlib
import json
import resource
import traceback
import gc
import struct
from pathlib import Path
from messenger.attachments.infrastructure.images import RenderLimits, render_variants
import messenger.worker
resource.setrlimit(resource.RLIMIT_AS, (448 << 20, 448 << 20))
def without_trns(data):
result = data[:8]
offset = 8
while offset < len(data):
size = struct.unpack('>I', data[offset:offset + 4])[0] + 12
if data[offset + 4:offset + 8] != b'tRNS':
result += data[offset:offset + size]
offset += size
return result
def probe(path, data, transparency):
row = {'file': path.name, 'transparency': transparency, 'input_sha256': hashlib.sha256(data).hexdigest(), 'limit_bytes': 448 << 20}
try:
row['variants'] = [r.name for r in render_variants(data, RenderLimits(10485760, 40000000))]
row['result'] = 'ready'
except Exception as error:
row['error_type'] = type(error).__name__
row['frames'] = [{'function': f.name, 'file': Path(f.filename).name, 'line': f.lineno} for f in traceback.extract_tb(error.__traceback__)]
row['max_rss_kib'] = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
print(json.dumps(row), flush=True)
for path in sorted(Path('/tmp/validation-fixtures').glob('*.png')):
data = path.read_bytes()
probe(path, data, True)
gc.collect()
probe(path, without_trns(data), False)
gc.collect()