Description
Describe the bug
With the new beta version of the blob storage SDK 12.8.0-beta.1
, zero length blobs are uploaded if the specified blob size does not match with the input stream. This can mislead applications into believing that blobs have been uploaded correctly. The previous version of the SDK threw an error instead of uploading the blob.
Exception or Stack Trace
NA
To Reproduce
Sample code to repro this:
final String containerName = "<container_name>";
final String blobName = "<blob_name>";
final String content = "Hello World!";
final byte[] contentBytes = content.getBytes();
try(InputStream inStream = new ByteArrayInputStream(contentBytes))
{
BlobClient blobClient = serviceClient.getBlobContainerClient(containerName)
.getBlobClient(blobName);
blobClient.upload(inStream, contentBytes.length + 10); // Incorrect length
BlobProperties properties = blobClient.getProperties();
System.out.println("Blob size: " + properties.getBlobSize());
}
Output with 12.8.0-beta.1
:
Blob size: 0
Output with 12.7.0
:
Exception in thread "main" com.azure.core.exception.UnexpectedLengthException: Request body emitted 12 bytes, less than the expected 22 bytes.
Code Snippet
Added above
Expected behavior
Either the SDK should throw an error if the lengths did not match or treat the input stream as source of truth and upload the content available from the stream.
Screenshots
NA
Setup (please complete the following information):
- OS: Linux
- IDE : IntelliJ
- Version of the Library used: 12.8.0-beta.1
Additional context
NA
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added
Activity