forked from mtusi2026/mtusi2026lab4
lab4: исправления второго ревью (40 Мп в tmpfs, таймауты S3, параллельный complete, auth до Content-Type, лимит на пользователя, бюджет памяти декода)
This commit is contained in:
@@ -48,3 +48,31 @@ def noise_png(size: int, seed: int = 0) -> bytes:
|
||||
raise ValueError("size is too small")
|
||||
continue
|
||||
return pad_png(png, size)
|
||||
|
||||
|
||||
ADAM7 = [(0, 0, 8, 8), (4, 0, 8, 8), (0, 4, 4, 8), (2, 0, 4, 4), (0, 2, 2, 4), (1, 0, 2, 2), (0, 1, 1, 2)]
|
||||
|
||||
|
||||
def worst_decode_png(size: int = 10_485_760, width: int = 8000, height: int = 5000) -> bytes:
|
||||
"""The heaviest valid upload to decode: 40 MP RGBA 16-bit, Adam7-interlaced
|
||||
(the decoder must hold the whole image), padded to exactly `size` bytes."""
|
||||
compressor = zlib.compressobj(1)
|
||||
parts = []
|
||||
for x0, y0, dx, dy in ADAM7:
|
||||
pass_width = (width - x0 + dx - 1) // dx if width > x0 else 0
|
||||
pass_height = (height - y0 + dy - 1) // dy if height > y0 else 0
|
||||
if pass_width == 0 or pass_height == 0:
|
||||
continue
|
||||
row = bytes(1 + pass_width * 8)
|
||||
for _ in range(pass_height):
|
||||
parts.append(compressor.compress(row))
|
||||
parts.append(compressor.flush())
|
||||
ihdr = struct.pack(">IIBBBBB", width, height, 16, 6, 0, 0, 1)
|
||||
png = SIGNATURE + chunk(b"IHDR", ihdr) + chunk(b"IDAT", b"".join(parts)) + chunk(b"IEND", b"")
|
||||
return pad_png(png, size)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
sys.stdout.buffer.write(worst_decode_png())
|
||||
|
||||
Reference in New Issue
Block a user