Skip to content

Commit

Permalink
Fix issue 2454
Browse files Browse the repository at this point in the history
  • Loading branch information
blueww committed Sep 3, 2024
1 parent 76f6262 commit 0b56ea5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
Blob:

- Fixed an issue where all blob APIs allowed metadata names which were not valid C# identifiers.
- Fixed issue of download 0 size blob with range > 0 should has header "Content-Range: bytes \*/0" in returned error. (issue #2458)

## 2024.08 Version 3.32.0

General:

- Bump mysql2 to resolve to 3.10.1 for security patches
- Fixed an issue where premature client disconnections led to all following requests failing with a 500 error. (issue #1346)
- Fixed an issue where premature client disconnections led to all following requests failing with a 500 error. (issue #1346)
- Bump up service API version to 2024-11-04

Blob:
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 {
var returnValue = new StorageError(

Check failure on line 203 in src/blob/errors/StorageErrorFactory.ts

View workflow job for this annotation

GitHub Actions / BlobTest_Win_Node18

Unexpected var, use let or const instead

Check failure on line 203 in src/blob/errors/StorageErrorFactory.ts

View workflow job for this annotation

GitHub Actions / BlobTest_Win_Node20

Unexpected var, use let or const instead

Check failure on line 203 in src/blob/errors/StorageErrorFactory.ts

View workflow job for this annotation

GitHub Actions / QueueTest_Win_Node18

Unexpected var, use let or const instead

Check failure on line 203 in src/blob/errors/StorageErrorFactory.ts

View workflow job for this annotation

GitHub Actions / QueueTest_Win_Node16

Unexpected var, use let or const instead

Check failure on line 203 in src/blob/errors/StorageErrorFactory.ts

View workflow job for this annotation

GitHub Actions / TableTest_Win_Node16

Unexpected var, use let or const instead

Check failure on line 203 in src/blob/errors/StorageErrorFactory.ts

View workflow job for this annotation

GitHub Actions / TableTest_Win_Node20

Unexpected var, use let or const instead

Check failure on line 203 in src/blob/errors/StorageErrorFactory.ts

View workflow job for this annotation

GitHub Actions / Azurite_ExeTest

Unexpected var, use let or const instead

Check failure on line 203 in src/blob/errors/StorageErrorFactory.ts

View workflow job for this annotation

GitHub Actions / Azurite_Win_Node20

Unexpected var, use let or const instead

Check failure on line 203 in src/blob/errors/StorageErrorFactory.ts

View workflow job for this annotation

GitHub Actions / Azurite_Win_Node22

Unexpected var, use let or const instead
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 @@ -372,6 +372,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 @@ -303,6 +303,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

0 comments on commit 0b56ea5

Please sign in to comment.