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

Commit 9bd52d4

Browse files
committed
Fixed a bug that Utilities::allZero() will return true for non-zero data chunks.
1 parent 01d9644 commit 9bd52d4

6 files changed

Lines changed: 22 additions & 4 deletions

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All
1111
* Moved method `SharedAccessSignatureHelper::generateFileServiceSharedAccessSignatureToken()` into `FileSharedAccessSignatureHelper`.
1212
* `CommonMiddleWare` constructor requires storage service version as parameter now.
1313
* `AccessPolicy` class is now an abstract class, added children classes `BlobAccessPolicy`, `ContainerAccessPolicy`, `TableAccessPolicy`, `QueueAccessPolicy`, `FileAccessPolicy` and `ShareAccessPolicy`.
14+
* Fixed a bug that `Utilities::allZero()` will return true for non-zero data chunks.
1415
* Deprecated PHP 5.5 support.
1516

1617
Blob

azure-storage-common/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
* Moved method `SharedAccessSignatureHelper::generateFileServiceSharedAccessSignatureToken()` into `FileSharedAccessSignatureHelper`.
88
* `CommonMiddleWare` constructor requires storage service version as parameter now.
99
* `AccessPolicy` class is now an abstract class, added children classes `BlobAccessPolicy`, `ContainerAccessPolicy`, `TableAccessPolicy`, `QueueAccessPolicy`, `FileAccessPolicy` and `ShareAccessPolicy`.
10+
* Fixed a bug that `Utilities::allZero()` will return true for non-zero data chunks.
1011
* Deprecated PHP 5.5 support.

azure-storage-common/src/Common/Internal/Utilities.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,15 +783,17 @@ public static function appendToFile($path, $content)
783783

784784
/**
785785
* Check if all the bytes are zero.
786+
*
786787
* @param string $content The content.
788+
* @return bool
787789
*/
788790
public static function allZero($content)
789791
{
790792
$size = strlen($content);
791793

792794
// If all Zero, skip this range
793795
for ($i = 0; $i < $size; $i++) {
794-
if (ord($content[$i] != 0)) {
796+
if (ord($content[$i]) != 0) {
795797
return false;
796798
}
797799
}

samples/BlobSamples.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
2828
use MicrosoftAzure\Storage\Blob\BlobSharedAccessSignatureHelper;
29+
use MicrosoftAzure\Storage\Blob\Models\CreateBlockBlobOptions;
2930
use MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions;
3031
use MicrosoftAzure\Storage\Blob\Models\PublicAccessType;
3132
use MicrosoftAzure\Storage\Blob\Models\DeleteBlobOptions;
@@ -370,7 +371,7 @@ function generateBlobDownloadLinkWithSAS()
370371
Resources::RESOURCE_TYPE_BLOB,
371372
'mycontainer/myblob',
372373
'r', // Read
373-
'2018-01-01T08:30:00Z'//, // A valid ISO 8601 format expiry time
374+
'2019-01-01T08:30:00Z'//, // A valid ISO 8601 format expiry time
374375
//'2016-01-01T08:30:00Z', // A valid ISO 8601 format expiry time
375376
//'0.0.0.0-255.255.255.255'
376377
//'https,http'
@@ -610,7 +611,7 @@ function leaseOperations($blobClient)
610611
$blob = 'Blob' . generateRandomString();
611612
echo "Create blob " . $blob . PHP_EOL;
612613
$contentType = 'text/plain; charset=UTF-8';
613-
$options = new CreateBlobOptions();
614+
$options = new CreateBlockBlobOptions();
614615
$options->setContentType($contentType);
615616
$blobClient->createBlockBlob($container, $blob, 'Hello world', $options);
616617

tests/Unit/Blob/BlobRestProxyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,7 @@ public function testCopyBlobIncremental()
17281728
// Setup
17291729
$sourceContainerName = 'copyblobincrementalsource' . $this->createSuffix();
17301730
$sourceBlobName = 'sourceblob';
1731-
$sourceContentLength = 1024 * 1024 * 8;
1731+
$sourceContentLength = 512 * 8;
17321732
$sourceBlobContent = openssl_random_pseudo_bytes($sourceContentLength);
17331733

17341734
$destinationContainerName = 'copyblobincrementaldest' . $this->createSuffix();

tests/Unit/Common/Internal/UtilitiesTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ public function testSerializeAttribute()
244244
$this->assertEquals($expected, $actual);
245245
}
246246

247+
public function testAllZero()
248+
{
249+
$this->assertFalse(Utilities::allZero('hello'));
250+
251+
for ($i = 1; $i < 256; $i++) {
252+
$this->assertFalse(Utilities::allZero(pack('c', $i)));
253+
}
254+
255+
$this->assertTrue(Utilities::allZero(pack('c', 0)));
256+
257+
$this->assertTrue(Utilities::allZero(''));
258+
}
259+
247260
public function testToBoolean()
248261
{
249262
$this->assertTrue(is_bool(Utilities::toBoolean('true')));

0 commit comments

Comments
 (0)