This commit is contained in:
Матвей
2026-11-05 21:17:50 +03:00
parent 470d9d6f1e
commit 66026d3ec9
62 changed files with 5351 additions and 4 deletions
+27
View File
@@ -0,0 +1,27 @@
"""Isolated image renderer. Parent enforces wall time and kills this process."""
import os
import pickle
import sys
def main():
if sys.platform == 'linux':
import resource
limit = int(os.environ.get('RENDER_MEMORY_MB', '768')) * 1024 * 1024
resource.setrlimit(resource.RLIMIT_AS, (limit, limit))
from .worker import variants
from PIL import UnidentifiedImageError, Image
try:
data = sys.stdin.buffer.read(10485761)
if len(data) > 10485760:
raise ValueError('bytes limit')
result = variants(data, int(os.environ.get('MAX_IMAGE_PIXELS', '40000000')))
pickle.dump(result, sys.stdout.buffer)
except MemoryError:
sys.exit(21)
except (ValueError, OSError, SyntaxError, UnidentifiedImageError, Image.DecompressionBombError):
sys.exit(20)
if __name__ == '__main__':
main()