Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download 0 size blob with range > 0 should has header "Content-Range: bytes \*/0" in returned error #2461

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## Upcoming Release

Blob:

- Fixed issue of download 0 size blob with range > 0 should has header "Content-Range: bytes \*/0" in returned error. (issue #2458)

## 2024.10 Version 3.33.0

General:
Expand Down
11 changes: 8 additions & 3 deletions src/blob/errors/StorageErrorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,18 @@ export default class StorageErrorFactory {
);
}

public static getInvalidPageRange2(contextID: string): StorageError {
return new StorageError(
public static getInvalidPageRange2(contextID: string, contentRange?: string): StorageError {
let returnValue = new StorageError(
416,
"InvalidRange",
"The range specified is invalid for the current size of the resource.",
contextID
);
);
if(contentRange)
{
returnValue.headers!["Content-Range"] = contentRange;
}
return returnValue;
}

public static getInvalidLeaseDuration(
Expand Down
8 changes: 4 additions & 4 deletions src/blob/handlers/BlobHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,14 +1010,14 @@ export default class BlobHandler extends BaseHandler implements IBlobHandler {

// Start Range is bigger than blob length
if (rangeStart > blob.properties.contentLength!) {
throw StorageErrorFactory.getInvalidPageRange(context.contextId!);
throw StorageErrorFactory.getInvalidPageRange2(context.contextId!,`bytes */${blob.properties.contentLength}`);
}

// Will automatically shift request with longer data end than blob size to blob size
if (rangeEnd + 1 >= blob.properties.contentLength!) {
// report error is blob size is 0, and rangeEnd is specified but not 0
if (blob.properties.contentLength == 0 && rangeEnd !== 0 && rangeEnd !== Infinity) {
throw StorageErrorFactory.getInvalidPageRange2(context.contextId!);
throw StorageErrorFactory.getInvalidPageRange2(context.contextId!,`bytes */${blob.properties.contentLength}`);
}
else {
rangeEnd = blob.properties.contentLength! - 1;
Expand Down Expand Up @@ -1141,14 +1141,14 @@ export default class BlobHandler extends BaseHandler implements IBlobHandler {

// Start Range is bigger than blob length
if (rangeStart > blob.properties.contentLength!) {
throw StorageErrorFactory.getInvalidPageRange(context.contextId!);
throw StorageErrorFactory.getInvalidPageRange2(context.contextId!,`bytes */${blob.properties.contentLength}`);
}

// Will automatically shift request with longer data end than blob size to blob size
if (rangeEnd + 1 >= blob.properties.contentLength!) {
// report error is blob size is 0, and rangeEnd is specified but not 0
if (blob.properties.contentLength == 0 && rangeEnd !== 0 && rangeEnd !== Infinity) {
throw StorageErrorFactory.getInvalidPageRange2(context.contextId!);
throw StorageErrorFactory.getInvalidPageRange2(context.contextId!,`bytes */${blob.properties.contentLength}`);
}
else {
rangeEnd = blob.properties.contentLength! - 1;
Expand Down
1 change: 1 addition & 0 deletions tests/blob/apis/blockblob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ describe("BlockBlobAPIs", () => {
await blockBlobClient.download(0, 3);
} catch (error) {
assert.deepStrictEqual(error.statusCode, 416);
assert.deepStrictEqual(error.response.headers.get("content-range"), 'bytes */0')
return;
}
assert.fail();
Expand Down
1 change: 1 addition & 0 deletions tests/blob/apis/pageblob.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ describe("PageBlobAPIs", () => {
await pageBlobClient.download(0, 3);
} catch (error) {
assert.deepStrictEqual(error.statusCode, 416);
assert.deepStrictEqual(error.response.headers.get("content-range"), 'bytes */0')
return;
}
assert.fail();
Expand Down
Loading