From 6c0f062bad47182d5289d1ef7155b4f473c8a418 Mon Sep 17 00:00:00 2001 From: JinmingHu Date: Tue, 5 Apr 2022 13:15:04 +0800 Subject: [PATCH] fix a bug where the xml body cannot be too big (#3502) * fix a bug where the xml body cannot be too big * ut * CL * record --- .../test/ut/block_blob_client_test.cpp | 18 +++ .../BlockBlobClientTest.MaximumBlocks.json | 128 ++++++++++++++++++ sdk/storage/azure-storage-common/CHANGELOG.md | 2 + .../azure-storage-common/src/xml_wrapper.cpp | 16 ++- 4 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 sdk/storage/azure-storage-blobs/test/ut/recordings/BlockBlobClientTest.MaximumBlocks.json diff --git a/sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp b/sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp index 63269e34d..290a947f2 100644 --- a/sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp +++ b/sdk/storage/azure-storage-blobs/test/ut/block_blob_client_test.cpp @@ -1933,4 +1933,22 @@ namespace Azure { namespace Storage { namespace Test { leaseClient.Release(); } + TEST_F(BlockBlobClientTest, MaximumBlocks) + { + auto const testName(GetTestName()); + auto blobClient = GetBlockBlobClient(testName); + + const std::vector content(static_cast(1), 'a'); + const std::string blockId = Base64EncodeText(std::string(64, '0')); + auto blockContent = Azure::Core::IO::MemoryBodyStream(content.data(), content.size()); + blobClient.StageBlock(blockId, blockContent); + + std::vector blockIds(50000, blockId); + EXPECT_NO_THROW(blobClient.CommitBlockList(blockIds)); + + EXPECT_EQ( + blobClient.GetProperties().Value.BlobSize, + static_cast(blockIds.size() * content.size())); + } + }}} // namespace Azure::Storage::Test diff --git a/sdk/storage/azure-storage-blobs/test/ut/recordings/BlockBlobClientTest.MaximumBlocks.json b/sdk/storage/azure-storage-blobs/test/ut/recordings/BlockBlobClientTest.MaximumBlocks.json new file mode 100644 index 000000000..5a53de691 --- /dev/null +++ b/sdk/storage/azure-storage-blobs/test/ut/recordings/BlockBlobClientTest.MaximumBlocks.json @@ -0,0 +1,128 @@ +{ + "networkCallRecords": [ + { + "Headers": { + "user-agent": "azsdk-cpp-storage-blobs/12.4.0-beta.2 (Windows 10 Pro 6.3 22000 22000.1.amd64fre.co_release.210604-1628)", + "x-ms-client-request-id": "488e96d5-a300-4658-7f2e-a03799a513b6", + "x-ms-version": "2020-08-04" + }, + "Method": "PUT", + "Response": { + "BODY": "", + "REASON_PHRASE": "Created", + "STATUS_CODE": "201", + "content-length": "0", + "date": "Tue, 05 Apr 2022 04:35:57 GMT", + "etag": "\"0x8DA16BDC7108781\"", + "last-modified": "Tue, 05 Apr 2022 04:35:57 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "488e96d5-a300-4658-7f2e-a03799a513b6", + "x-ms-request-id": "f6fa231b-901e-0004-69a6-484152000000", + "x-ms-version": "2020-08-04" + }, + "Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestmaximumblocks?restype=container" + }, + { + "Headers": { + "user-agent": "azsdk-cpp-storage-blobs/12.4.0-beta.2 (Windows 10 Pro 6.3 22000 22000.1.amd64fre.co_release.210604-1628)", + "x-ms-client-request-id": "7bd19eba-c92b-4550-47dc-8a913dbeff57", + "x-ms-version": "2020-08-04" + }, + "Method": "PUT", + "Response": { + "BODY": "", + "REASON_PHRASE": "Created", + "STATUS_CODE": "201", + "content-length": "0", + "date": "Tue, 05 Apr 2022 04:35:57 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "7bd19eba-c92b-4550-47dc-8a913dbeff57", + "x-ms-content-crc64": "PPzLtEWEL4w=", + "x-ms-request-id": "f6fa2455-901e-0004-12a6-484152000000", + "x-ms-request-server-encrypted": "true", + "x-ms-version": "2020-08-04" + }, + "Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestmaximumblocks/MaximumBlocks?blockid=MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMA%3D%3D&comp=block" + }, + { + "Headers": { + "content-type": "application/xml; charset=UTF-8", + "user-agent": "azsdk-cpp-storage-blobs/12.4.0-beta.2 (Windows 10 Pro 6.3 22000 22000.1.amd64fre.co_release.210604-1628)", + "x-ms-client-request-id": "a590e2ab-2de9-4eeb-625c-db8ad5e98d49", + "x-ms-version": "2020-08-04" + }, + "Method": "PUT", + "Response": { + "BODY": "", + "REASON_PHRASE": "Created", + "STATUS_CODE": "201", + "content-length": "0", + "date": "Tue, 05 Apr 2022 04:36:01 GMT", + "etag": "\"0x8DA16BDC954B5D3\"", + "last-modified": "Tue, 05 Apr 2022 04:36:00 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "a590e2ab-2de9-4eeb-625c-db8ad5e98d49", + "x-ms-content-crc64": "JSucJt7HJKg=", + "x-ms-request-id": "f6fa274d-901e-0004-44a6-484152000000", + "x-ms-request-server-encrypted": "true", + "x-ms-version": "2020-08-04", + "x-ms-version-id": "2022-04-05T04:36:00.8818459Z" + }, + "Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestmaximumblocks/MaximumBlocks?comp=blocklist" + }, + { + "Headers": { + "user-agent": "azsdk-cpp-storage-blobs/12.4.0-beta.2 (Windows 10 Pro 6.3 22000 22000.1.amd64fre.co_release.210604-1628)", + "x-ms-client-request-id": "3aef73c3-4588-4d98-7e1e-2a6d6beca62e", + "x-ms-version": "2020-08-04" + }, + "Method": "HEAD", + "Response": { + "BODY": "", + "REASON_PHRASE": "OK", + "STATUS_CODE": "200", + "accept-ranges": "bytes", + "content-length": "50000", + "content-type": "application/octet-stream", + "date": "Tue, 05 Apr 2022 04:36:01 GMT", + "etag": "\"0x8DA16BDC954B5D3\"", + "last-modified": "Tue, 05 Apr 2022 04:36:00 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "vary": "Origin", + "x-ms-access-tier": "Hot", + "x-ms-access-tier-inferred": "true", + "x-ms-blob-type": "BlockBlob", + "x-ms-client-request-id": "3aef73c3-4588-4d98-7e1e-2a6d6beca62e", + "x-ms-creation-time": "Tue, 05 Apr 2022 04:36:00 GMT", + "x-ms-is-current-version": "true", + "x-ms-lease-state": "available", + "x-ms-lease-status": "unlocked", + "x-ms-request-id": "f6fa302e-901e-0004-64a6-484152000000", + "x-ms-server-encrypted": "true", + "x-ms-version": "2020-08-04", + "x-ms-version-id": "2022-04-05T04:36:00.8818459Z" + }, + "Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestmaximumblocks/MaximumBlocks" + }, + { + "Headers": { + "user-agent": "azsdk-cpp-storage-blobs/12.4.0-beta.2 (Windows 10 Pro 6.3 22000 22000.1.amd64fre.co_release.210604-1628)", + "x-ms-client-request-id": "37e31d24-000b-4a13-71c1-3dc8fceb4126", + "x-ms-version": "2020-08-04" + }, + "Method": "DELETE", + "Response": { + "BODY": "", + "REASON_PHRASE": "Accepted", + "STATUS_CODE": "202", + "content-length": "0", + "date": "Tue, 05 Apr 2022 04:36:01 GMT", + "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0", + "x-ms-client-request-id": "37e31d24-000b-4a13-71c1-3dc8fceb4126", + "x-ms-request-id": "f6fa3179-901e-0004-1ca6-484152000000", + "x-ms-version": "2020-08-04" + }, + "Url": "https://REDACTED.blob.core.windows.net/blockblobclienttestmaximumblocks?restype=container" + } + ] +} diff --git a/sdk/storage/azure-storage-common/CHANGELOG.md b/sdk/storage/azure-storage-common/CHANGELOG.md index 01a6716c5..80956642f 100644 --- a/sdk/storage/azure-storage-common/CHANGELOG.md +++ b/sdk/storage/azure-storage-common/CHANGELOG.md @@ -8,6 +8,8 @@ ### Bugs Fixed +- Fixed a bug where we got error when XML request body is too big. + ### Other Changes ## 12.2.2 (2022-03-09) diff --git a/sdk/storage/azure-storage-common/src/xml_wrapper.cpp b/sdk/storage/azure-storage-common/src/xml_wrapper.cpp index e09a45262..f914421b6 100644 --- a/sdk/storage/azure-storage-common/src/xml_wrapper.cpp +++ b/sdk/storage/azure-storage-common/src/xml_wrapper.cpp @@ -362,18 +362,22 @@ namespace Azure { namespace Storage { namespace _internal { auto context = static_cast(m_context); BOOL boolValueTrue = TRUE; - WS_XML_WRITER_PROPERTY writerProperty; - writerProperty.id = WS_XML_WRITER_PROPERTY_WRITE_DECLARATION; - writerProperty.value = &boolValueTrue; - writerProperty.valueSize = sizeof(boolValueTrue); + WS_XML_WRITER_PROPERTY writerProperty[2]; + writerProperty[0].id = WS_XML_WRITER_PROPERTY_WRITE_DECLARATION; + writerProperty[0].value = &boolValueTrue; + writerProperty[0].valueSize = sizeof(boolValueTrue); + writerProperty[1].id = WS_XML_WRITER_PROPERTY_BUFFER_MAX_SIZE; + ULONG maxBufferSize = 256 * 1024 * 1024UL; + writerProperty[1].value = &maxBufferSize; + writerProperty[1].valueSize = sizeof(maxBufferSize); void* xml = nullptr; ULONG xmlLength = 0; HRESULT ret = WsWriteXmlBufferToBytes( context->writer, context->buffer, nullptr, - &writerProperty, - 1, + writerProperty, + sizeof(writerProperty) / sizeof(writerProperty[0]), context->heap, &xml, &xmlLength,