lab5: завершение второго ревью
PNG: validate color-type/bit-depth pairs, reject duplicate IHDR/PLTE, non-consecutive IDAT, PLTE after IDAT, and trailing bytes after the zlib stream; keep accepting valid palette, split-IDAT, 16-bit, and Adam7 uploads. Replay: a newer failed unpublished version returns the attachment to queued, while a published ready version stays serving.
This commit is contained in:
@@ -31,9 +31,9 @@ def png_chunk(ctype, payload):
|
||||
return struct.pack('>I', len(payload)) + ctype + payload + struct.pack('>I', crc)
|
||||
|
||||
|
||||
def crafted_png(width, height, interlace, raster):
|
||||
def crafted_png(width, height, interlace, raster, bit_depth=8, color_type=6):
|
||||
"""PNG with correct chunk lengths and CRCs around arbitrary IDAT bytes."""
|
||||
ihdr = struct.pack('>IIBBBBB', width, height, 8, 6, 0, 0, interlace)
|
||||
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)
|
||||
@@ -87,6 +87,31 @@ def main():
|
||||
upload(client, alice, chat, crafted_png(2, 2, 0, invalid_filter), expected=415)
|
||||
print('valid zlib, invalid PNG scanline filter: 415')
|
||||
|
||||
# RGBA forbids bit depth 1; every chunk CRC is correct.
|
||||
upload(client, alice, chat, crafted_png(1, 1, 0, b'\x00', bit_depth=1), expected=415)
|
||||
print('invalid PNG color type/bit depth pair: 415')
|
||||
|
||||
# Duplicate IHDR is forbidden even with correct CRCs.
|
||||
ihdr = png_chunk(b'IHDR', struct.pack('>IIBBBBB', 1, 1, 8, 6, 0, 0, 0))
|
||||
duplicate_header = (
|
||||
b'\x89PNG\r\n\x1a\n'
|
||||
+ ihdr + ihdr
|
||||
+ png_chunk(b'IDAT', zlib.compress(b'\x00' + b'\x00' * 4))
|
||||
+ png_chunk(b'IEND', b'')
|
||||
)
|
||||
upload(client, alice, chat, duplicate_header, expected=415)
|
||||
print('duplicate PNG IHDR: 415')
|
||||
|
||||
# Bytes after the zlib stream inside IDAT are not part of a valid raster.
|
||||
trailing = (
|
||||
b'\x89PNG\r\n\x1a\n'
|
||||
+ png_chunk(b'IHDR', struct.pack('>IIBBBBB', 1, 1, 8, 6, 0, 0, 0))
|
||||
+ png_chunk(b'IDAT', zlib.compress(b'\x00' + b'\x00' * 4) + b'junk')
|
||||
+ png_chunk(b'IEND', b'')
|
||||
)
|
||||
upload(client, alice, chat, trailing, expected=415)
|
||||
print('trailing bytes after PNG zlib stream: 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)
|
||||
|
||||
@@ -6,6 +6,7 @@ FAULTS_ENABLED=1 and targeted failpoints, then restores the normal services.
|
||||
|
||||
python3 student-tests/lab5_faults.py --base-url http://localhost:8080
|
||||
"""
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
@@ -232,6 +233,41 @@ def scenario_lease_takeover(client, alice, chat):
|
||||
reset_relay()
|
||||
|
||||
|
||||
def scenario_replay_reprocessed_version(client, alice, chat):
|
||||
compose('stop', 'worker')
|
||||
attached, _ = client.attachment(alice, chat)
|
||||
reprocessed = json.loads(jobctl('reprocess', '-attachment', attached['id'], '-pipeline', '2').stdout)
|
||||
jid = reprocessed['ID']
|
||||
|
||||
worker_with(FAULTS_ENABLED='1', FAULT_TARGET_JOB=jid, FAULT_WORKER_FAIL='permanent')
|
||||
|
||||
deadline = time.monotonic() + 40
|
||||
last = ''
|
||||
while time.monotonic() < deadline:
|
||||
job_status = psql("select status from attachment_jobs where job_id='%s'" % jid)
|
||||
last = psql("select status || '|' || coalesce(error_code,'') from attachments where id='%s'" % attached['id'])
|
||||
if job_status == 'failed' and last.startswith('failed|'):
|
||||
break
|
||||
time.sleep(0.2)
|
||||
|
||||
check(job_status == 'failed' and last == 'failed|injected_failure',
|
||||
'reprocessed failure did not settle: ' + last)
|
||||
|
||||
compose('stop', 'worker')
|
||||
jobctl('replay', '-job', jid)
|
||||
projection = client.call(
|
||||
'GET', '/api/v1/attachments/' + attached['id'], actor=alice, schema='Attachment',
|
||||
)['json']
|
||||
check(projection['status'] == 'queued' and projection['error_code'] is None,
|
||||
'replay left stale terminal projection: ' + str(projection['status']))
|
||||
|
||||
reset_worker()
|
||||
client.wait_ready(alice, attached, wait_seconds=90)
|
||||
check(psql("select pipeline_version from attachments where id='%s'" % attached['id']) == '2',
|
||||
'replayed reprocess did not publish pipeline 2')
|
||||
print('replay of failed reprocess: queued projection restored, then ready at pipeline 2')
|
||||
|
||||
|
||||
def main():
|
||||
args = arguments('Lab5 level 4 fault injection')
|
||||
client = Client(args.base_url, args.ca_file)
|
||||
@@ -239,6 +275,7 @@ def main():
|
||||
|
||||
scenarios = [
|
||||
scenario_permanent_failure_and_replay,
|
||||
scenario_replay_reprocessed_version,
|
||||
scenario_transient_exhaustion,
|
||||
scenario_crash_after_first_variant,
|
||||
scenario_crash_after_commit,
|
||||
|
||||
Reference in New Issue
Block a user