Skip to content

Commit

Permalink
Fixed InputStream issue where request conditions are not honored when…
Browse files Browse the repository at this point in the history
… doing the initial getProperties call (#20125)
  • Loading branch information
gapra-msft authored Mar 25, 2021
1 parent 7f152bb commit cc88c0f
Show file tree
Hide file tree
Showing 16 changed files with 1,813 additions and 1 deletion.
3 changes: 3 additions & 0 deletions sdk/storage/azure-storage-blob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release History

## 12.10.2 (Unreleased)
- Fixed a bug where BlobInputStream would not use request conditions when doing the initial getProperties call in openInputStream.

## 12.10.1 (2021-03-19)
- Removed a deep copy in the general upload path to reduce memory consumption and increase perf
- Added a deep copy immediately after calling BlobOutputStream.write to prevent overwriting data in the case of reusing a single buffer to write to an output stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public final BlobInputStream openInputStream(BlobRange range, BlobRequestConditi
public BlobInputStream openInputStream(BlobInputStreamOptions options) {
options = options == null ? new BlobInputStreamOptions() : options;

BlobProperties properties = getProperties();
BlobProperties properties = getPropertiesWithResponse(options.getRequestConditions(), null, null).getValue();

BlobRange range = options.getRange() == null ? new BlobRange(0) : options.getRange();
int chunkSize = options.getBlockSize() == null ? 4 * Constants.MB : options.getBlockSize();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.azure.storage.blob

import com.azure.storage.blob.models.BlobRequestConditions
import com.azure.storage.blob.models.BlobStorageException
import com.azure.storage.blob.models.BlobType
import com.azure.storage.blob.options.BlobInputStreamOptions
import com.azure.storage.blob.specialized.BlobOutputStream
Expand Down Expand Up @@ -173,4 +174,61 @@ class BlockBlobInputOutputStreamTest extends APISpec {
then:
thrown(IOException)
}

@Unroll
def "InputStream AC"() {
setup:
bc.upload(new ByteArrayInputStream(new byte[0]), 0)
def t = new HashMap<String, String>()
t.put("foo", "bar")
bc.setTags(t)
def bac = new BlobRequestConditions()
.setLeaseId(setupBlobLeaseCondition(bc, leaseID))
.setIfMatch(setupBlobMatchCondition(bc, match))
.setIfNoneMatch(noneMatch)
.setIfModifiedSince(modified)
.setIfUnmodifiedSince(unmodified)
.setTagsConditions(tags)

expect:
bc.openInputStream(new BlobInputStreamOptions().setRequestConditions(bac))

where:
modified | unmodified | match | noneMatch | leaseID | tags
null | null | null | null | null | null
oldDate | null | null | null | null | null
null | newDate | null | null | null | null
null | null | receivedEtag | null | null | null
null | null | null | garbageEtag | null | null
null | null | null | null | receivedLeaseID | null
null | null | null | null | null | "\"foo\" = 'bar'"
}

@Unroll
def "InputStream AC fail"() {
setup:
bc.upload(new ByteArrayInputStream(new byte[0]), 0)
def bac = new BlobRequestConditions()
.setLeaseId(setupBlobLeaseCondition(bc, leaseID))
.setIfMatch(match)
.setIfNoneMatch(setupBlobMatchCondition(bc, noneMatch))
.setIfModifiedSince(modified)
.setIfUnmodifiedSince(unmodified)
.setTagsConditions(tags)

when:
bc.openInputStream(new BlobInputStreamOptions().setRequestConditions(bac))

then:
thrown(BlobStorageException)

where:
modified | unmodified | match | noneMatch | leaseID | tags
newDate | null | null | null | null | null
null | oldDate | null | null | null | null
null | null | garbageEtag | null | null | null
null | null | null | receivedEtag | null | null
null | null | null | null | garbageLeaseID | null
null | null | null | null | null | "\"notfoo\" = 'notbar'"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac031238822a8ebf4bfe49a580a8?restype=container",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "666633ab-4a19-420c-a21d-61d32f1695eb"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "0x8D8EFC3F52D9781",
"Last-Modified" : "Thu, 25 Mar 2021 19:26:58 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "1ec7217c-e01e-00b7-1eac-21db8b000000",
"Date" : "Thu, 25 Mar 2021 19:26:58 GMT",
"x-ms-client-request-id" : "666633ab-4a19-420c-a21d-61d32f1695eb"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac031238822a8ebf4bfe49a580a8/javablobinputstreamac1868478523f13f3792468392",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "5d714dea-6a7a-4ea6-834b-690ee7cffae3",
"Content-Type" : "application/octet-stream"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-content-crc64" : "AAAAAAAAAAA=",
"Last-Modified" : "Thu, 25 Mar 2021 19:26:58 GMT",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-server-encrypted" : "true",
"Date" : "Thu, 25 Mar 2021 19:26:58 GMT",
"Content-MD5" : "1B2M2Y8AsgTpgAmY7PhCfg==",
"ETag" : "0x8D8EFC3F56D02DC",
"Content-Length" : "0",
"x-ms-request-id" : "1ec721b2-e01e-00b7-3dac-21db8b000000",
"x-ms-client-request-id" : "5d714dea-6a7a-4ea6-834b-690ee7cffae3"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac031238822a8ebf4bfe49a580a8/javablobinputstreamac1868478523f13f3792468392?comp=tags",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "9093a83b-9c85-4fc4-bcbb-723afd597171",
"Content-Type" : "application/xml; charset=utf-8"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"StatusCode" : "204",
"x-ms-request-id" : "1ec721c9-e01e-00b7-50ac-21db8b000000",
"Date" : "Thu, 25 Mar 2021 19:26:58 GMT",
"x-ms-client-request-id" : "9093a83b-9c85-4fc4-bcbb-723afd597171"
},
"Exception" : null
}, {
"Method" : "HEAD",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac031238822a8ebf4bfe49a580a8/javablobinputstreamac1868478523f13f3792468392",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "a0ab8d8f-7d8d-452b-b667-92abb7fb9cff"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"x-ms-lease-status" : "unlocked",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-tag-count" : "1",
"x-ms-lease-state" : "available",
"Last-Modified" : "Thu, 25 Mar 2021 19:26:58 GMT",
"retry-after" : "0",
"StatusCode" : "200",
"Date" : "Thu, 25 Mar 2021 19:26:58 GMT",
"x-ms-blob-type" : "BlockBlob",
"Content-MD5" : "1B2M2Y8AsgTpgAmY7PhCfg==",
"Accept-Ranges" : "bytes",
"x-ms-server-encrypted" : "true",
"x-ms-access-tier-inferred" : "true",
"x-ms-access-tier" : "Hot",
"ETag" : "0x8D8EFC3F56D02DC",
"x-ms-creation-time" : "Thu, 25 Mar 2021 19:26:58 GMT",
"Content-Length" : "0",
"x-ms-request-id" : "1ec721e5-e01e-00b7-65ac-21db8b000000",
"x-ms-client-request-id" : "a0ab8d8f-7d8d-452b-b667-92abb7fb9cff",
"Content-Type" : "application/octet-stream"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://REDACTED.blob.core.windows.net?prefix=jtcinputstreamac&comp=list",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "942d2abd-0d2d-4993-8239-ff1615670ad9"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"StatusCode" : "200",
"x-ms-request-id" : "1ec721f5-e01e-00b7-72ac-21db8b000000",
"Body" : "<?xml version=\"1.0\" encoding=\"utf-8\"?><EnumerationResults ServiceEndpoint=\"https://seancanary.blob.core.windows.net/\"><Prefix>jtcinputstreamac</Prefix><Containers><Container><Name>jtcinputstreamac031238822a8ebf4bfe49a580a8</Name><Properties><Last-Modified>Thu, 25 Mar 2021 19:26:58 GMT</Last-Modified><Etag>\"0x8D8EFC3F52D9781\"</Etag><LeaseStatus>unlocked</LeaseStatus><LeaseState>available</LeaseState><DefaultEncryptionScope>$account-encryption-key</DefaultEncryptionScope><DenyEncryptionScopeOverride>false</DenyEncryptionScopeOverride><HasImmutabilityPolicy>false</HasImmutabilityPolicy><HasLegalHold>false</HasLegalHold></Properties></Container></Containers><NextMarker /></EnumerationResults>",
"Date" : "Thu, 25 Mar 2021 19:26:59 GMT",
"x-ms-client-request-id" : "942d2abd-0d2d-4993-8239-ff1615670ad9",
"Content-Type" : "application/xml"
},
"Exception" : null
}, {
"Method" : "DELETE",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac031238822a8ebf4bfe49a580a8?restype=container",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "df49e3c4-e44e-46e2-9ba4-b6f7a9f8886a"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "202",
"x-ms-request-id" : "1ec72201-e01e-00b7-7cac-21db8b000000",
"Date" : "Thu, 25 Mar 2021 19:26:59 GMT",
"x-ms-client-request-id" : "df49e3c4-e44e-46e2-9ba4-b6f7a9f8886a"
},
"Exception" : null
} ],
"variables" : [ "jtcinputstreamac031238822a8ebf4bfe49a580a8", "javablobinputstreamac1868478523f13f3792468392" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac0106040e864fcf60114888b133?restype=container",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "22a97318-c7aa-4ecd-84b6-8b5c722da1a0"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "0x8D8EFC3F606037F",
"Last-Modified" : "Thu, 25 Mar 2021 19:26:59 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "1ec7222d-e01e-00b7-26ac-21db8b000000",
"Date" : "Thu, 25 Mar 2021 19:26:59 GMT",
"x-ms-client-request-id" : "22a97318-c7aa-4ecd-84b6-8b5c722da1a0"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac0106040e864fcf60114888b133/javablobinputstreamac174174285de589c80041e687",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "1036302a-4f86-4f00-9ed2-b9e69368cd7f",
"Content-Type" : "application/octet-stream"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-content-crc64" : "AAAAAAAAAAA=",
"Last-Modified" : "Thu, 25 Mar 2021 19:26:59 GMT",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-server-encrypted" : "true",
"Date" : "Thu, 25 Mar 2021 19:26:59 GMT",
"Content-MD5" : "1B2M2Y8AsgTpgAmY7PhCfg==",
"ETag" : "0x8D8EFC3F61440DF",
"Content-Length" : "0",
"x-ms-request-id" : "1ec72250-e01e-00b7-48ac-21db8b000000",
"x-ms-client-request-id" : "1036302a-4f86-4f00-9ed2-b9e69368cd7f"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac0106040e864fcf60114888b133/javablobinputstreamac174174285de589c80041e687?comp=tags",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "bb5766ac-495d-4ecb-9915-f64997899618",
"Content-Type" : "application/xml; charset=utf-8"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"StatusCode" : "204",
"x-ms-request-id" : "1ec72257-e01e-00b7-4eac-21db8b000000",
"Date" : "Thu, 25 Mar 2021 19:26:59 GMT",
"x-ms-client-request-id" : "bb5766ac-495d-4ecb-9915-f64997899618"
},
"Exception" : null
}, {
"Method" : "HEAD",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac0106040e864fcf60114888b133/javablobinputstreamac174174285de589c80041e687",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "7cf0270a-2920-4516-af45-bdbf7b192438"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"x-ms-lease-status" : "unlocked",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-tag-count" : "1",
"x-ms-lease-state" : "available",
"Last-Modified" : "Thu, 25 Mar 2021 19:26:59 GMT",
"retry-after" : "0",
"StatusCode" : "200",
"Date" : "Thu, 25 Mar 2021 19:26:59 GMT",
"x-ms-blob-type" : "BlockBlob",
"Content-MD5" : "1B2M2Y8AsgTpgAmY7PhCfg==",
"Accept-Ranges" : "bytes",
"x-ms-server-encrypted" : "true",
"x-ms-access-tier-inferred" : "true",
"x-ms-access-tier" : "Hot",
"ETag" : "0x8D8EFC3F61440DF",
"x-ms-creation-time" : "Thu, 25 Mar 2021 19:26:59 GMT",
"Content-Length" : "0",
"x-ms-request-id" : "1ec7226d-e01e-00b7-60ac-21db8b000000",
"x-ms-client-request-id" : "7cf0270a-2920-4516-af45-bdbf7b192438",
"Content-Type" : "application/octet-stream"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "https://REDACTED.blob.core.windows.net?prefix=jtcinputstreamac&comp=list",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "6d51aea1-e7db-483b-928b-53bdf42ceab1"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"StatusCode" : "200",
"x-ms-request-id" : "1ec72280-e01e-00b7-6fac-21db8b000000",
"Body" : "<?xml version=\"1.0\" encoding=\"utf-8\"?><EnumerationResults ServiceEndpoint=\"https://seancanary.blob.core.windows.net/\"><Prefix>jtcinputstreamac</Prefix><Containers><Container><Name>jtcinputstreamac0106040e864fcf60114888b133</Name><Properties><Last-Modified>Thu, 25 Mar 2021 19:26:59 GMT</Last-Modified><Etag>\"0x8D8EFC3F606037F\"</Etag><LeaseStatus>unlocked</LeaseStatus><LeaseState>available</LeaseState><DefaultEncryptionScope>$account-encryption-key</DefaultEncryptionScope><DenyEncryptionScopeOverride>false</DenyEncryptionScopeOverride><HasImmutabilityPolicy>false</HasImmutabilityPolicy><HasLegalHold>false</HasLegalHold></Properties></Container></Containers><NextMarker /></EnumerationResults>",
"Date" : "Thu, 25 Mar 2021 19:26:59 GMT",
"x-ms-client-request-id" : "6d51aea1-e7db-483b-928b-53bdf42ceab1",
"Content-Type" : "application/xml"
},
"Exception" : null
}, {
"Method" : "DELETE",
"Uri" : "https://REDACTED.blob.core.windows.net/jtcinputstreamac0106040e864fcf60114888b133?restype=container",
"Headers" : {
"x-ms-version" : "2020-04-08",
"User-Agent" : "azsdk-java-azure-storage-blob/12.10.1 (11.0.7; Windows 10; 10.0)",
"x-ms-client-request-id" : "3733cda5-5e34-4b4e-a2fe-61f0e94389e6"
},
"Response" : {
"x-ms-version" : "2020-04-08",
"Server" : "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "202",
"x-ms-request-id" : "1ec72294-e01e-00b7-01ac-21db8b000000",
"Date" : "Thu, 25 Mar 2021 19:26:59 GMT",
"x-ms-client-request-id" : "3733cda5-5e34-4b4e-a2fe-61f0e94389e6"
},
"Exception" : null
} ],
"variables" : [ "jtcinputstreamac0106040e864fcf60114888b133", "javablobinputstreamac174174285de589c80041e687" ]
}
Loading

0 comments on commit cc88c0f

Please sign in to comment.