Skip to content

Commit 570cabe

Browse files
authored
[Storage] Fix content range check for empty files (#26872)
1 parent fc76739 commit 570cabe

File tree

5 files changed

+5
-4
lines changed

5 files changed

+5
-4
lines changed

sdk/storage/azure-storage-blob/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- Fixed possible invalid content range exception that gets raised when downloading empty blobs through Azurite.
1011

1112
### Other Changes
1213
- Removed `msrest` dependency.

sdk/storage/azure-storage-blob/azure/storage/blob/_download.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ def _initial_request(self):
431431
# Parse the total file size and adjust the download size if ranges
432432
# were specified
433433
self._file_size = parse_length_from_content_range(response.properties.content_range)
434-
if not self._file_size:
434+
if self._file_size is None:
435435
raise ValueError("Required Content-Range response header is missing or malformed.")
436436
# Remove any extra encryption data size from blob size
437437
self._file_size = adjust_blob_size_for_encryption(self._file_size, self._encryption_data)

sdk/storage/azure-storage-blob/azure/storage/blob/aio/_download_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ async def _initial_request(self):
353353
# Parse the total file size and adjust the download size if ranges
354354
# were specified
355355
self._file_size = parse_length_from_content_range(response.properties.content_range)
356-
if not self._file_size:
356+
if self._file_size is None:
357357
raise ValueError("Required Content-Range response header is missing or malformed.")
358358
# Remove any extra encryption data size from blob size
359359
self._file_size = adjust_blob_size_for_encryption(self._file_size, self._encryption_data)

sdk/storage/azure-storage-file-share/azure/storage/fileshare/_download.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def _initial_request(self):
311311
# Parse the total file size and adjust the download size if ranges
312312
# were specified
313313
self._file_size = parse_length_from_content_range(response.properties.content_range)
314-
if not self._file_size:
314+
if self._file_size is None:
315315
raise ValueError("Required Content-Range response header is missing or malformed.")
316316

317317
if self._end_range is not None:

sdk/storage/azure-storage-file-share/azure/storage/fileshare/aio/_download_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ async def _initial_request(self):
264264
# Parse the total file size and adjust the download size if ranges
265265
# were specified
266266
self._file_size = parse_length_from_content_range(response.properties.content_range)
267-
if not self._file_size:
267+
if self._file_size is None:
268268
raise ValueError("Required Content-Range response header is missing or malformed.")
269269

270270
if self._end_range is not None:

0 commit comments

Comments
 (0)