Skip to content

Add CRC-64/NVME transactional checksum support for StageBlock#2644

Open
mcroomp wants to merge 11 commits into
Azure:mainfrom
mcroomp:feature/stage-block-crc64-transactional-checksum
Open

Add CRC-64/NVME transactional checksum support for StageBlock#2644
mcroomp wants to merge 11 commits into
Azure:mainfrom
mcroomp:feature/stage-block-crc64-transactional-checksum

Conversation

@mcroomp
Copy link
Copy Markdown

@mcroomp mcroomp commented May 6, 2026

  • Add CRC-64/NVME transactional checksum support for StageBlock, PutBlock and PutBlob. Implements CRC-64 validation in the StageBlock handler, computes MD5 and CRC-64 in a single stream pass via computeTransactionalChecksums, and removes x-ms-content-crc64 from the unsupported headers blocklist.
  • Make CopyBlobFromURL return the contentMD5 if it was passed in as per the Azure contract.

Test improvements

  • Use a global counter instead of random to generate unique keys, as on a fast runner this was causing random test failure.
  • Add environment variable AZURITE_LIVE_TEST_CONNECTION_STRING to allow running the unit tests against a real azure account in order to verify that we are testing correct behavior. The required some changes in the baseUrl setup for tests.

Copilot AI review requested due to automatic review settings May 6, 2026 19:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds CRC-64/ECMA-182 transactional checksum support for the Blob StageBlock operation, enabling request validation via x-ms-content-crc64 and echoing the validated checksum back in the response.

Changes:

  • Added CRC64 utilities (getCRC64FromString, getCRC64FromStream) plus a combined computeTransactionalChecksums helper.
  • Updated BlockBlobHandler.stageBlock to validate transactionalContentCrc64 and return x-ms-content-crc64 when provided.
  • Added unit/integration tests covering CRC64 correctness and StageBlock success/failure behaviors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/blob/utils.test.ts Adds CRC64 unit tests (known-check value, stream parity, chunk-boundary invariance).
tests/blob/apis/blockblob.test.ts Adds StageBlock tests for CRC64 success, mismatch failure, and absence of CRC64 response header.
src/common/utils/utils.ts Introduces CRC-64/ECMA-182 implementation and a combined MD5+CRC64 streaming helper.
src/blob/middlewares/StrictModelMiddlewareFactory.ts Allows x-ms-content-crc64 header by removing it from the strict-model unsupported list.
src/blob/handlers/BlockBlobHandler.ts Validates transactional CRC64 for StageBlock and conditionally returns x-ms-content-crc64 in the response.
Comments suppressed due to low confidence (1)

src/blob/handlers/BlockBlobHandler.ts:7

  • There are now two separate imports from the same module (../../common/utils/utils): one for convertRawHeadersToMetadata and another for the rest. Consider consolidating into a single import to avoid duplication and keep imports easier to maintain.
import { convertRawHeadersToMetadata } from "../../common/utils/utils";
import {
  computeTransactionalChecksums,
  getMD5FromStream,
  getMD5FromString,
  newEtag
} from "../../common/utils/utils";

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/common/utils/utils.ts Outdated
Comment thread src/blob/handlers/BlockBlobHandler.ts Outdated
Copilot AI review requested due to automatic review settings May 7, 2026 15:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/blob/handlers/BlockBlobHandler.ts Outdated
Comment thread src/blob/handlers/BlockBlobHandler.ts Outdated
@jainakanksha-msft
Copy link
Copy Markdown
Collaborator

@mcroomp Is StageBlock the first step of CRC64 support rollout, or is there a service-compatibility reason this checksum should only be supported on Put Block and not on other upload APIs yet?

…r. Also added logic to crc PutBlock and AppendBlock
@mcroomp mcroomp changed the title Add CRC-64/ECMA-182 transactional checksum support for StageBlock Add CRC-64/NVME transactional checksum support for StageBlock May 11, 2026
@mcroomp mcroomp requested a review from Copilot May 11, 2026 13:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/blob/middlewares/StrictModelMiddlewareFactory.ts:27

  • Removing x-ms-content-crc64 from the global unsupported-header blocklist means requests can now include this header on operations that still ignore it (e.g., PageBlob UploadPages includes transactionalContentCrc64 in the generated spec, but PageBlobHandler has no CRC64/MD5 transactional validation). This will cause Azurite to accept x-ms-content-crc64 without validating it, which violates the Azure REST contract and can give callers a false sense of integrity checking. Consider either (1) implementing CRC64 validation for the other operations that accept this header (at least PageBlobUploadPages), or (2) making unsupported-header validation operation-aware so x-ms-content-crc64 is only allowed where it is actually implemented.
  const UnsupportedHeaderKeys = [
    HeaderConstants.X_MS_RANGE_GET_CONTENT_CRC64,
    HeaderConstants.X_MS_ENCRYPTION_KEY,
    HeaderConstants.X_MS_ENCRYPTION_KEY_SHA256,
    HeaderConstants.X_MS_ENCRYPTION_ALGORITHM
  ];

Comment thread tests/BlobTestServerFactory.ts
Comment thread src/blob/utils/utils.ts Outdated
Copilot AI review requested due to automatic review settings May 11, 2026 14:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Comment thread tests/testutils.ts
Comment thread tests/testutils.ts Outdated
@mcroomp
Copy link
Copy Markdown
Author

mcroomp commented May 11, 2026

@jainakanksha-msft Is StageBlock the first step of CRC64 support rollout, or is there a service-compatibility reason this checksum should only be supported on Put Block and not on other upload APIs yet?

Ok I implemented PutBlock and AppendBlock as well. I also added an env variable so we can run the test cases against real Azure to make sure the behavior is the same. I identified a couple gaps from this in the md5/crc behavior.

Comment thread src/blob/errors/StorageErrorFactory.ts
Verified against real Azure: a 4-byte Content-MD5 header is rejected with
InvalidMd5 (not Md5Mismatch). The new test guards stageBlock against
silently regressing this code, complementing the existing wrong-value
test that asserts Md5Mismatch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 20, 2026 07:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 4 comments.

Comment thread src/blob/handlers/PageBlobHandler.ts
Comment thread src/blob/handlers/BlockBlobHandler.ts
Comment thread src/blob/utils/utils.ts
Comment thread src/blob/utils/utils.ts Outdated
@jainakanksha-msft
Copy link
Copy Markdown
Collaborator

@mcroomp, this PR looks good to me. Please go through all the copilot comments.
@blueww please take a quick look.

Live probe showed real Azure returns InvalidMd5 (not InvalidHeaderValue)
for wrong-length x-ms-blob-content-md5 on Put Blob. Drop Azurite's
explicit InvalidHeaderValue path and let the unified transactional
validator handle all three MD5 sources (Content-MD5,
transactionalContentMD5, x-ms-blob-content-md5) the same way.

Also adds a CRC64 wrong-length test (pins the existing
InvalidHeaderValue path) and a Put Blob wrong-length-blob-content-md5
test (pins the new InvalidMd5 path). Both verified live.

Clarifies tests/testutils.ts JSDoc to acknowledge http:// connection
strings instead of claiming HTTPS is always used in live mode.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mcroomp
Copy link
Copy Markdown
Author

mcroomp commented May 21, 2026

@mcroomp, this PR looks good to me. Please go through all the copilot comments. @blueww please take a quick look.

One small change since the review due to copilot comment, added the InvalidMd5 behavior checks to all cases and ensured we are consistent with live azure. Closed the rest of the copilot low confidence comments that werent helpful.

…vely against live azure to ensure identical behavior
Copilot AI review requested due to automatic review settings May 25, 2026 08:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.

Comment thread src/blob/utils/utils.ts
Comment thread src/blob/utils/utils.ts
Comment thread tests/blob/utils.test.ts Outdated
Comment thread tests/blob/utils.test.ts Outdated
Comment thread tests/blob/utils.test.ts Outdated
Comment thread tests/blob/apis/blockblob.test.ts Outdated
Comment thread tests/testutils.ts Fixed
@mcroomp mcroomp requested a review from jainakanksha-msft May 25, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants