Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit 6aece7b

Browse files
committed
Merge pull request #348 from unclejack/fix_ranges_off_by_one
fix Content-Length off by one for bytes ranges
2 parents 0c03458 + 8fe60f6 commit 6aece7b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

docker_registry/images.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _get_image_layer(image_id, headers=None, bytes_range=None):
9292
bytes_range = (bytes_range[0], layer_size)
9393

9494
if bytes_range:
95-
content_length = bytes_range[1] - bytes_range[0]
95+
content_length = bytes_range[1] - bytes_range[0] + 1
9696
if not _valid_bytes_range(bytes_range):
9797
return flask.Response(status=416, headers=headers)
9898
status = 206
@@ -151,11 +151,10 @@ def _parse_bytes_range():
151151

152152

153153
def _valid_bytes_range(bytes_range):
154-
if bytes_range[1] < bytes_range[0]:
155-
return False
154+
length = bytes_range[1] - bytes_range[0] + 1
156155
if bytes_range[0] < 0 or bytes_range[1] < 1:
157156
return False
158-
if bytes_range[1] - bytes_range[0] < 1:
157+
if length < 2:
159158
return False
160159
return True
161160

0 commit comments

Comments
 (0)