Skip to content

Commit 0b56ea5

Browse files
committed
Fix issue 2454
1 parent 76f6262 commit 0b56ea5

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

ChangeLog.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
Blob:
88

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

1112
## 2024.08 Version 3.32.0
1213

1314
General:
1415

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

1920
Blob:

src/blob/errors/StorageErrorFactory.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,18 @@ export default class StorageErrorFactory {
199199
);
200200
}
201201

202-
public static getInvalidPageRange2(contextID: string): StorageError {
203-
return new StorageError(
202+
public static getInvalidPageRange2(contextID: string, contentRange?: string): StorageError {
203+
var returnValue = new StorageError(
204204
416,
205205
"InvalidRange",
206206
"The range specified is invalid for the current size of the resource.",
207207
contextID
208-
);
208+
);
209+
if(contentRange)
210+
{
211+
returnValue.headers!["Content-Range"] = contentRange;
212+
}
213+
return returnValue;
209214
}
210215

211216
public static getInvalidLeaseDuration(

src/blob/handlers/BlobHandler.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1010,14 +1010,14 @@ export default class BlobHandler extends BaseHandler implements IBlobHandler {
10101010

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

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

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

11471147
// Will automatically shift request with longer data end than blob size to blob size
11481148
if (rangeEnd + 1 >= blob.properties.contentLength!) {
11491149
// report error is blob size is 0, and rangeEnd is specified but not 0
11501150
if (blob.properties.contentLength == 0 && rangeEnd !== 0 && rangeEnd !== Infinity) {
1151-
throw StorageErrorFactory.getInvalidPageRange2(context.contextId!);
1151+
throw StorageErrorFactory.getInvalidPageRange2(context.contextId!,`bytes */${blob.properties.contentLength}`);
11521152
}
11531153
else {
11541154
rangeEnd = blob.properties.contentLength! - 1;

tests/blob/apis/blockblob.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ describe("BlockBlobAPIs", () => {
372372
await blockBlobClient.download(0, 3);
373373
} catch (error) {
374374
assert.deepStrictEqual(error.statusCode, 416);
375+
assert.deepStrictEqual(error.response.headers.get("content-range"), 'bytes */0')
375376
return;
376377
}
377378
assert.fail();

tests/blob/apis/pageblob.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ describe("PageBlobAPIs", () => {
303303
await pageBlobClient.download(0, 3);
304304
} catch (error) {
305305
assert.deepStrictEqual(error.statusCode, 416);
306+
assert.deepStrictEqual(error.response.headers.get("content-range"), 'bytes */0')
306307
return;
307308
}
308309
assert.fail();

0 commit comments

Comments
 (0)