lab5: закрытие остаточных замечаний
Validate tRNS semantics and bind PLTE entry count to the IHDR bit depth so malformed PNGs are rejected with 415 instead of failing in the worker. Refuse replay of an older failed version while a newer pipeline job exists, preventing loss of the shared staging source, and retire version-stale queued jobs as superseded instead of republishing them forever.
This commit is contained in:
@@ -33,10 +33,19 @@ def png_chunk(ctype, payload):
|
||||
|
||||
def crafted_png(width, height, interlace, raster, bit_depth=8, color_type=6):
|
||||
"""PNG with correct chunk lengths and CRCs around arbitrary IDAT bytes."""
|
||||
return crafted_png_extra(
|
||||
width, height, raster, bit_depth=bit_depth, color_type=color_type,
|
||||
interlace=interlace,
|
||||
)
|
||||
|
||||
|
||||
def crafted_png_extra(width, height, raster, pre_idat=(), bit_depth=8, color_type=6, interlace=0):
|
||||
"""PNG whose IDAT is preceded by caller-supplied chunks (PLTE/tRNS/...)."""
|
||||
ihdr = struct.pack('>IIBBBBB', width, height, bit_depth, color_type, 0, 0, interlace)
|
||||
return (
|
||||
b'\x89PNG\r\n\x1a\n'
|
||||
+ png_chunk(b'IHDR', ihdr)
|
||||
+ b''.join(pre_idat)
|
||||
+ png_chunk(b'IDAT', zlib.compress(raster))
|
||||
+ png_chunk(b'IEND', b'')
|
||||
)
|
||||
@@ -112,6 +121,30 @@ def main():
|
||||
upload(client, alice, chat, trailing, expected=415)
|
||||
print('trailing bytes after PNG zlib stream: 415')
|
||||
|
||||
# tRNS is forbidden for alpha color types and has fixed lengths otherwise.
|
||||
rgba_trns = crafted_png_extra(
|
||||
1, 1, b'\x00' + b'\x00' * 4,
|
||||
pre_idat=(png_chunk(b'tRNS', b'\x00'),), color_type=6,
|
||||
)
|
||||
upload(client, alice, chat, rgba_trns, expected=415)
|
||||
print('tRNS on RGBA PNG: 415')
|
||||
|
||||
rgb_trns = crafted_png_extra(
|
||||
1, 1, b'\x00' + b'\x00' * 3,
|
||||
pre_idat=(png_chunk(b'tRNS', b'\x00'),), color_type=2,
|
||||
)
|
||||
upload(client, alice, chat, rgb_trns, expected=415)
|
||||
print('short tRNS on RGB PNG: 415')
|
||||
|
||||
# A 1-bit palette cannot address three entries.
|
||||
palette_overflow = crafted_png_extra(
|
||||
1, 1, b'\x00\x00',
|
||||
pre_idat=(png_chunk(b'PLTE', bytes((255, 0, 0, 0, 255, 0, 0, 0, 255))),),
|
||||
bit_depth=1, color_type=3,
|
||||
)
|
||||
upload(client, alice, chat, palette_overflow, expected=415)
|
||||
print('PLTE entries exceed palette bit depth: 415')
|
||||
|
||||
# Dangerous display names.
|
||||
for name in ('../x.png', 'a/b.png', 'a\\b.png', 'a\x00.png', 'a\n.png'):
|
||||
upload(client, alice, chat, fixture, filename=name, expected=400)
|
||||
|
||||
Reference in New Issue
Block a user