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)
|
||||
|
||||
@@ -268,6 +268,32 @@ def scenario_replay_reprocessed_version(client, alice, chat):
|
||||
print('replay of failed reprocess: queued projection restored, then ready at pipeline 2')
|
||||
|
||||
|
||||
def scenario_replay_older_version_refused(client, alice, chat):
|
||||
compose('stop', 'worker')
|
||||
attached, _ = client.attachment(alice, chat)
|
||||
jid_v1 = job_id(attached['id'])
|
||||
|
||||
worker_with(FAULTS_ENABLED='1', FAULT_TARGET_JOB=jid_v1, FAULT_WORKER_FAIL='permanent')
|
||||
status, code, _ = wait_db(attached['id'], lambda s, e, a: s == 'failed', 40, 'failed v1')
|
||||
check(code == 'injected_failure', 'unexpected v1 failure: ' + code)
|
||||
|
||||
compose('stop', 'worker')
|
||||
reprocessed = json.loads(jobctl('reprocess', '-attachment', attached['id'], '-pipeline', '2').stdout)
|
||||
refused = jobctl('replay', '-job', jid_v1, check=False)
|
||||
check(refused.returncode != 0, 'older failed version was replayed while v2 exists')
|
||||
jobs = psql("select pipeline_version || ':' || status from attachment_jobs where attachment_id='%s' order by pipeline_version" % attached['id'])
|
||||
check(jobs == '1:failed\n2:queued', 'older replay changed job state: ' + jobs.replace('\n', ', '))
|
||||
print('replay older failed version while v2 queued: refused, state intact')
|
||||
|
||||
reset_worker()
|
||||
client.wait_ready(alice, attached, wait_seconds=90)
|
||||
check(psql("select pipeline_version from attachments where id='%s'" % attached['id']) == '2',
|
||||
'v2 did not publish after older replay was refused')
|
||||
check(psql("select job_id from attachment_jobs where attachment_id='%s' and pipeline_version=2" % attached['id']) == reprocessed['ID'],
|
||||
'v2 job identity changed')
|
||||
print('v2 published after older replay refusal')
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments('Lab5 level 4 fault injection')
|
||||
client = Client(args.base_url, args.ca_file)
|
||||
@@ -275,6 +301,7 @@ def main():
|
||||
|
||||
scenarios = [
|
||||
scenario_permanent_failure_and_replay,
|
||||
scenario_replay_older_version_refused,
|
||||
scenario_replay_reprocessed_version,
|
||||
scenario_transient_exhaustion,
|
||||
scenario_crash_after_first_variant,
|
||||
|
||||
Reference in New Issue
Block a user