Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit 4da6cea

Browse files
committed
EncryptedInputStream fix
1 parent 9beae8b commit 4da6cea

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

ChangeLog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
XXXX.XX.XX Version X.X.X
2+
* Fixed a bug in BlobInputStream that would return extra zeros at the end of the stream if the data was encrypted using client-side encryption.
3+
* MD5 checks on BlobInputStream are skipped if data being downloaded is also being decrypted via client-side encryption, even if disableMd5Calculation is set to false. Previously this check would always fail as MD5 is calculated on cipher text on upload but was calculated on plaintext on download.
4+
15
2019.12.06 Version 8.6.0
26
* Added the skipDecode flag to the generate sas method on CloudBlob. This flag allows the customer to skip the url decode that happens by default on the string to sign right before signing. This resolves some problems with custom values for some of the query parameters when used with third party clients.
37

microsoft-azure-storage-test/src/com/microsoft/azure/storage/TestHelper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,7 @@ public static void assertStreamsAreEqual(InputStream src, InputStream dst) throw
283283
}
284284

285285
next = dst.read();
286-
while (next != -1) {
287-
assertEquals(0, next);
288-
next = dst.read();
289-
}
286+
assertEquals(next, -1);
290287
}
291288

292289
public static void assertStreamsAreEqualAtIndex(ByteArrayInputStream src, ByteArrayInputStream dst, int srcIndex,

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobInputStream.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,19 @@ private synchronized void dispatchRead(final int readLength) throws IOException
302302
try {
303303
final byte[] byteBuffer = new byte[readLength];
304304

305-
this.parentBlobRef.downloadRangeInternal(this.currentAbsoluteReadPosition, (long) readLength, byteBuffer,
306-
0, this.accessCondition, this.options, this.opContext);
307-
308-
this.currentBuffer = new ByteArrayInputStream(byteBuffer);
305+
int numBytes = this.parentBlobRef.downloadRangeInternal(this.currentAbsoluteReadPosition, (long) readLength,
306+
byteBuffer, 0, this.accessCondition, this.options, this.opContext);
307+
308+
/*
309+
In the case of client-side decryption, we may get fewer bytes than we request at the end of the blob when
310+
we remove padding. We want to ensure our data is the correct size, even in this case. Also, in this case,
311+
we can no longer validate the MD5 because it was calculated on the ciphertext on upload, but this
312+
inputstream calculates it on the plaintext.
313+
*/
314+
if (numBytes < readLength && this.options.getEncryptionPolicy() != null) {
315+
this.validateBlobMd5 = false;
316+
}
317+
this.currentBuffer = new ByteArrayInputStream(byteBuffer, 0, numBytes);
309318
this.bufferSize = readLength;
310319
this.bufferStartOffset = this.currentAbsoluteReadPosition;
311320
}

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/CloudBlob.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,8 @@ public final BlobInputStream openInputStream(final AccessCondition accessConditi
26442644
}
26452645

26462646
/**
2647-
* Opens a blob input stream to download the blob using the specified request options and operation context.
2647+
* Opens a blob input stream to download the blob using the specified request options and operation context. If
2648+
* the blob is decrypted as it is downloaded, the final MD5 validation will be skipped.
26482649
* <p>
26492650
* Use {@link #setStreamMinimumReadSizeInBytes(int)} to configure the read size.
26502651
*

0 commit comments

Comments
 (0)