Browse Source

Add marker loop detection

master
JustAnotherArchivist 4 years ago
parent
commit
bfe5f59e25
1 changed files with 5 additions and 0 deletions
  1. +5
    -0
      s3-bucket-list

+ 5
- 0
s3-bucket-list View File

@@ -62,6 +62,9 @@ while True:
if not body.startswith(b'<?xml version="1.0" encoding="UTF-8"?>\n<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">'):
raise RuntimeError(f'Invalid body: {body[:200]}...')

if b'<Marker></Marker>' in body[:200] and 'marker' in params:
raise RuntimeError('Marker loop (empty marker in response despite providing one)')

# No risk, no fun!
contents = body.split(b'<Contents>')
assert all(content.startswith(b'<Key>') for content in contents[1:])
@@ -91,4 +94,6 @@ while True:

if not truncated:
break
if 'marker' in params and params['marker'] == lastKey:
raise RuntimeError('Marker loop (same last key as previous marker)')
params['marker'] = lastKey

Loading…
Cancel
Save