Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Fixed a bug that Utilities::allZero() will return true for non-zero d…
Browse files Browse the repository at this point in the history
…ata chunks.
  • Loading branch information
XiaoningLiu committed Jan 10, 2018
1 parent 01d9644 commit 9bd52d4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All
* Moved method `SharedAccessSignatureHelper::generateFileServiceSharedAccessSignatureToken()` into `FileSharedAccessSignatureHelper`.
* `CommonMiddleWare` constructor requires storage service version as parameter now.
* `AccessPolicy` class is now an abstract class, added children classes `BlobAccessPolicy`, `ContainerAccessPolicy`, `TableAccessPolicy`, `QueueAccessPolicy`, `FileAccessPolicy` and `ShareAccessPolicy`.
* Fixed a bug that `Utilities::allZero()` will return true for non-zero data chunks.
* Deprecated PHP 5.5 support.

Blob
Expand Down
1 change: 1 addition & 0 deletions azure-storage-common/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
* Moved method `SharedAccessSignatureHelper::generateFileServiceSharedAccessSignatureToken()` into `FileSharedAccessSignatureHelper`.
* `CommonMiddleWare` constructor requires storage service version as parameter now.
* `AccessPolicy` class is now an abstract class, added children classes `BlobAccessPolicy`, `ContainerAccessPolicy`, `TableAccessPolicy`, `QueueAccessPolicy`, `FileAccessPolicy` and `ShareAccessPolicy`.
* Fixed a bug that `Utilities::allZero()` will return true for non-zero data chunks.
* Deprecated PHP 5.5 support.
4 changes: 3 additions & 1 deletion azure-storage-common/src/Common/Internal/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,15 +783,17 @@ public static function appendToFile($path, $content)

/**
* Check if all the bytes are zero.
*
* @param string $content The content.
* @return bool
*/
public static function allZero($content)
{
$size = strlen($content);

// If all Zero, skip this range
for ($i = 0; $i < $size; $i++) {
if (ord($content[$i] != 0)) {
if (ord($content[$i]) != 0) {
return false;
}
}
Expand Down
5 changes: 3 additions & 2 deletions samples/BlobSamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use MicrosoftAzure\Storage\Blob\BlobSharedAccessSignatureHelper;
use MicrosoftAzure\Storage\Blob\Models\CreateBlockBlobOptions;
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions;
use MicrosoftAzure\Storage\Blob\Models\PublicAccessType;
use MicrosoftAzure\Storage\Blob\Models\DeleteBlobOptions;
Expand Down Expand Up @@ -370,7 +371,7 @@ function generateBlobDownloadLinkWithSAS()
Resources::RESOURCE_TYPE_BLOB,
'mycontainer/myblob',
'r', // Read
'2018-01-01T08:30:00Z'//, // A valid ISO 8601 format expiry time
'2019-01-01T08:30:00Z'//, // A valid ISO 8601 format expiry time
//'2016-01-01T08:30:00Z', // A valid ISO 8601 format expiry time
//'0.0.0.0-255.255.255.255'
//'https,http'
Expand Down Expand Up @@ -610,7 +611,7 @@ function leaseOperations($blobClient)
$blob = 'Blob' . generateRandomString();
echo "Create blob " . $blob . PHP_EOL;
$contentType = 'text/plain; charset=UTF-8';
$options = new CreateBlobOptions();
$options = new CreateBlockBlobOptions();
$options->setContentType($contentType);
$blobClient->createBlockBlob($container, $blob, 'Hello world', $options);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Blob/BlobRestProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,7 @@ public function testCopyBlobIncremental()
// Setup
$sourceContainerName = 'copyblobincrementalsource' . $this->createSuffix();
$sourceBlobName = 'sourceblob';
$sourceContentLength = 1024 * 1024 * 8;
$sourceContentLength = 512 * 8;
$sourceBlobContent = openssl_random_pseudo_bytes($sourceContentLength);

$destinationContainerName = 'copyblobincrementaldest' . $this->createSuffix();
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Common/Internal/UtilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,19 @@ public function testSerializeAttribute()
$this->assertEquals($expected, $actual);
}

public function testAllZero()
{
$this->assertFalse(Utilities::allZero('hello'));

for ($i = 1; $i < 256; $i++) {
$this->assertFalse(Utilities::allZero(pack('c', $i)));
}

$this->assertTrue(Utilities::allZero(pack('c', 0)));

$this->assertTrue(Utilities::allZero(''));
}

public function testToBoolean()
{
$this->assertTrue(is_bool(Utilities::toBoolean('true')));
Expand Down

0 comments on commit 9bd52d4

Please sign in to comment.