Azure / Azurite

A lightweight server clone of Azure Storage that simulates most of the commands supported by it with minimal dependencies
MIT License
1.74k stars 309 forks source link

Azurite doesn't match Azure when downloading byte range from empty blob #2410

Open mikamins opened 3 weeks ago

mikamins commented 3 weeks ago

Which service(blob, file, queue, table) does this issue concern?

blob

Which version of the Azurite was used?

v3.30.0

Where do you get Azurite? (npm, DockerHub, NuGet, Visual Studio Code Extension)

npm

What's the Node.js version?

v20.10.0

What problem was encountered?

When downloading a byte range from a 0-sized blob, Azurite is successful (206), while a real storage account returns an error (416)

Steps to reproduce the issue?

azurite.log shows:

  1. Create container
  2. Upload an empty blob
  3. Download a byte range from that blob

Azurite response

HTTP/1.1 206 Partial Content
Server: Azurite-Blob/3.30.0
last-modified: Fri, 07 Jun 2024 15:59:24 GMT
x-ms-creation-time: Fri, 07 Jun 2024 15:59:24 GMT
content-length: 0
content-type: application/octet-stream
content-range: bytes 0--1/0
etag: "0x1F20D878DBCF020"
content-md5: 1B2M2Y8AsgTpgAmY7PhCfg==
x-ms-blob-type: BlockBlob
x-ms-lease-state: available
x-ms-lease-status: unlocked
x-ms-client-request-id: 2f17c3a5-75b0-4d26-8bdb-fd485bf9cb96
x-ms-request-id: 24e1b533-7213-4936-842d-9108c42b811d
x-ms-version: 2024-05-04
accept-ranges: bytes
date: Fri, 07 Jun 2024 15:59:24 GMT
x-ms-server-encrypted: true
x-ms-blob-content-md5: 1B2M2Y8AsgTpgAmY7PhCfg==
Connection: keep-alive
Keep-Alive: timeout=5

Azure response in same scenario

HTTP/1.1 416 The range specified is invalid for the current size of the resource.
Content-Length: 249
Content-Type: application/xml
Content-Range: bytes */0
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 091c4acf-b01e-0045-64f3-b846c2000000
x-ms-client-request-id: b5093669-485f-496f-9eda-b375dd8b65d3
x-ms-version: 2019-12-12
x-ms-error-code: InvalidRange
Date: Fri, 07 Jun 2024 15:57:39 GMT

<?xml version="1.0" encoding="utf-8"?><Error><Code>InvalidRange</Code><Message>The range specified is invalid for the current size of the resource.
RequestId:091c4acf-b01e-0045-64f3-b846c2000000
Time:2024-06-07T15:57:39.2526413Z</Message></Error>

Have you found a mitigation/solution?

No

blueww commented 2 weeks ago

@mikamins

Thanks for reporting this issue! We will look into how to fix it.

Azurite welcome contribution! It would be great if you could raise a PR to fix it!

The fix might can be: adding code to the following place, to report error when "x-ms-rage" end is bigger than blob length and blob length is 0 : Block & Append: https://github.com/Azure/Azurite/blob/e53428818dc418372a6885ad9c5fe8789c1061e3/src/blob/handlers/BlobHandler.ts#L1020 Page: https://github.com/Azure/Azurite/blob/e53428818dc418372a6885ad9c5fe8789c1061e3/src/blob/handlers/BlobHandler.ts#L1145