Skip to content

Commit

Permalink
Int value overflow problem
Browse files Browse the repository at this point in the history
  • Loading branch information
yangzong18 authored and huiguangjun committed Aug 25, 2021
1 parent 0c9d902 commit 9d16ee5
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 46 deletions.
2 changes: 1 addition & 1 deletion samples/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ function printImage($func, $imageFile)
Common::println("$func, image width: " . $array[0]);
Common::println("$func, image height: " . $array[1]);
Common::println("$func, image type: " . ($array[2] === 2 ? 'jpg' : 'png'));
Common::println("$func, image size: " . ceil(filesize($imageFile)));
Common::println("$func, image size: " . ceil(sprintf('%u',filesize($imageFile))));
}
2 changes: 1 addition & 1 deletion samples/MultipartUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function putObjectByRawApis($ossClient, $bucket)
*/
$partSize = 10 * 1024 * 1024;
$uploadFile = __FILE__;
$uploadFileSize = filesize($uploadFile);
$uploadFileSize = sprintf('%u',filesize($uploadFile));
$pieces = $ossClient->generateMultiuploadParts($uploadFileSize, $partSize);
$responseUploadPart = array();
$uploadPosition = 0;
Expand Down
2 changes: 1 addition & 1 deletion samples/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function getSignedUrlForPuttingObjectFromFile($ossClient, $bucket)
$request->set_method('PUT');
$request->add_header('Content-Type', 'txt');
$request->set_read_file($file);
$request->set_read_stream_size(filesize($file));
$request->set_read_stream_size(sprintf('%u',filesize($file)));
$request->send_request();
$res = new ResponseCore($request->get_response_header(),
$request->get_response_body(), $request->get_response_code());
Expand Down
4 changes: 2 additions & 2 deletions src/OSS/Core/OssUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static function throwOssExceptionWithMessageIfEmpty($name, $errMsg)
*/
public static function generateFile($filename, $size)
{
if (file_exists($filename) && $size == filesize($filename)) {
if (file_exists($filename) && $size == sprintf('%u',filesize($filename))) {
echo $filename . " already exists, no need to create again. ";
return;
}
Expand Down Expand Up @@ -284,7 +284,7 @@ public static function getMd5SumForFile($filename, $from_pos, $to_pos)
if (($to_pos - $from_pos) > self::OSS_MAX_PART_SIZE) {
return $content_md5;
}
$filesize = filesize($filename);
$filesize = sprintf('%u',filesize($filename));
if ($from_pos >= $filesize || $to_pos >= $filesize || $from_pos < 0 || $to_pos < 0) {
return $content_md5;
}
Expand Down
33 changes: 22 additions & 11 deletions src/OSS/Model/ObjectInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ObjectInfo
* @param string $lastModified
* @param string $eTag
* @param string $type
* @param int $size
* @param string $size
* @param string $storageClass
*/
public function __construct($key, $lastModified, $eTag, $type, $size, $storageClass)
Expand Down Expand Up @@ -67,15 +67,26 @@ public function getType()
{
return $this->type;
}

/**
* @return int
*/
public function getSize()
{
return $this->size;
}


/**
* php7 && 64bit can use it
* @return int
*/
public function getSize()
{
return (int)$this->size;
}


/**
* php5.x or 32bit must use it
* @return string
*/
public function getSizeStr()
{
return $this->size;
}

/**
* @return string
*/
Expand All @@ -88,6 +99,6 @@ public function getStorageClass()
private $lastModified = "";
private $eTag = "";
private $type = "";
private $size = 0;
private $size = "0";
private $storageClass = "";
}
31 changes: 21 additions & 10 deletions src/OSS/Model/ObjectVersionInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ObjectVersionInfo
* @param string $lastModified
* @param string $eTag
* @param string $type
* @param int $size
* @param string $size
* @param string $storageClass
* @param string $isLatest
*/
Expand Down Expand Up @@ -78,14 +78,25 @@ public function getType()
{
return $this->type;
}

/**
* @return int
*/
public function getSize()
{
return $this->size;
}

/**
* php7 && 64bit can use it
* @return int
*/
public function getSize()
{
return (int)$this->size;
}


/**
* php5.x or 32bit must use it
* @return string
*/
public function getSizeStr()
{
return $this->size;
}

/**
* @return string
Expand All @@ -108,7 +119,7 @@ public function getIsLatest()
private $lastModified = "";
private $eTag = "";
private $type = "";
private $size = 0;
private $size = "0";
private $storageClass = "";
private $isLatest = "";
}
17 changes: 14 additions & 3 deletions src/OSS/Model/PartInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PartInfo
* @param int $partNumber
* @param string $lastModified
* @param string $eTag
* @param int $size
* @param string $size
*/
public function __construct($partNumber, $lastModified, $eTag, $size)
{
Expand Down Expand Up @@ -49,15 +49,26 @@ public function getETag()
}

/**
* php7 && 64bit can use it
* @return int
*/
public function getSize()
{
return $this->size;
return (int)$this->size;
}


/**
* php5.x or 32bit must use it
* @return string
*/
public function getSizeStr()
{
return $this->size;
}

private $partNumber = 0;
private $lastModified = "";
private $eTag = "";
private $size = 0;
private $size = "0";
}
7 changes: 4 additions & 3 deletions src/OSS/OssClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ public function uploadFile($bucket, $object, $file, $options = NULL)
throw new OssException($file . " file does not exist");
}
$options[self::OSS_FILE_UPLOAD] = $file;
$file_size = filesize($options[self::OSS_FILE_UPLOAD]);
$file_size = sprintf('%u',filesize($options[self::OSS_FILE_UPLOAD]));
$is_check_md5 = $this->isCheckMD5($options);
if ($is_check_md5) {
$content_md5 = base64_encode(md5_file($options[self::OSS_FILE_UPLOAD], true));
Expand Down Expand Up @@ -1816,7 +1816,7 @@ public function appendFile($bucket, $object, $file, $position, $options = NULL)
throw new OssException($file . " file does not exist");
}
$options[self::OSS_FILE_UPLOAD] = $file;
$file_size = filesize($options[self::OSS_FILE_UPLOAD]);
$file_size = sprintf('%u',filesize($options[self::OSS_FILE_UPLOAD]));
$is_check_md5 = $this->isCheckMD5($options);
if ($is_check_md5) {
$content_md5 = base64_encode(md5_file($options[self::OSS_FILE_UPLOAD], true));
Expand Down Expand Up @@ -2460,7 +2460,8 @@ public function multiuploadFile($bucket, $object, $file, $options = null)
if (isset($options[self::OSS_CONTENT_LENGTH])) {
$upload_file_size = (integer)$options[self::OSS_CONTENT_LENGTH];
} else {
$upload_file_size = filesize($uploadFile);
$upload_file_size = sprintf('%u',filesize($uploadFile));

if ($upload_file_size !== false) {
$upload_file_size -= $upload_position;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OSS/Result/ListObjectVersionsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private function parseObjecVersionList($xml, $encodingType)
$lastModified = isset($content->LastModified) ? strval($content->LastModified) : "";
$eTag = isset($content->ETag) ? strval($content->ETag) : "";
$type = isset($content->Type) ? strval($content->Type) : "";
$size = isset($content->Size) ? intval($content->Size) : 0;
$size = isset($content->Size) ? strval($content->Size) : "0";
$storageClass = isset($content->StorageClass) ? strval($content->StorageClass) : "";
$isLatest = isset($content->IsLatest) ? strval($content->IsLatest) : "";
$retList[] = new ObjectVersionInfo($key, $versionId, $lastModified, $eTag, $type, $size, $storageClass, $isLatest);
Expand Down
2 changes: 1 addition & 1 deletion src/OSS/Result/ListObjectsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private function parseObjectList($xml, $encodingType)
$lastModified = isset($content->LastModified) ? strval($content->LastModified) : "";
$eTag = isset($content->ETag) ? strval($content->ETag) : "";
$type = isset($content->Type) ? strval($content->Type) : "";
$size = isset($content->Size) ? intval($content->Size) : 0;
$size = isset($content->Size) ? strval($content->Size) : "0";
$storageClass = isset($content->StorageClass) ? strval($content->StorageClass) : "";
$retList[] = new ObjectInfo($key, $lastModified, $eTag, $type, $size, $storageClass);
}
Expand Down
2 changes: 1 addition & 1 deletion src/OSS/Result/ListPartsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function parseDataFromResponse()
$partNumber = isset($part->PartNumber) ? intval($part->PartNumber) : "";
$lastModified = isset($part->LastModified) ? strval($part->LastModified) : "";
$eTag = isset($part->ETag) ? strval($part->ETag) : "";
$size = isset($part->Size) ? intval($part->Size) : "";
$size = isset($part->Size) ? strval($part->Size) : "";
$partList[] = new PartInfo($partNumber, $lastModified, $eTag, $size);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/OSS/Tests/OssClientMultipartUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function testAbortMultipartUpload()
*/
$part_size = 10 * 1024 * 1024;
$upload_file = __FILE__;
$upload_filesize = filesize($upload_file);
$upload_filesize = sprintf('%u',filesize($upload_file));
$pieces = $this->ossClient->generateMultiuploadParts($upload_filesize, $part_size);
$response_upload_part = array();
$upload_position = 0;
Expand Down Expand Up @@ -257,7 +257,7 @@ public function testPutObjectByRawApis()
*/
$part_size = 10 * 1024 * 1024;
$upload_file = __FILE__;
$upload_filesize = filesize($upload_file);
$upload_filesize = sprintf('%u',filesize($upload_file));
$pieces = $this->ossClient->generateMultiuploadParts($upload_filesize, $part_size);
$response_upload_part = array();
$upload_position = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/OSS/Tests/OssClientObjectRequestPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function testMultipartOperationsWithRequester()
*/
$part_size = 1 * 1024 * 1024;
$upload_file = __FILE__;
$upload_filesize = filesize($upload_file);
$upload_filesize = sprintf('%u',filesize($upload_file));
$pieces = $this->payerClient->generateMultiuploadParts($upload_filesize, $part_size);
$response_upload_part = array();
$upload_position = 0;
Expand Down
8 changes: 4 additions & 4 deletions tests/OSS/Tests/OssClientObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ public function testAppendObject()
*/
try {
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, 0);
$this->assertEquals($position, filesize(__FILE__));
$this->assertEquals($position, sprintf('%u',filesize(__FILE__)));
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, $position);
$this->assertEquals($position, filesize(__FILE__) * 2);
$this->assertEquals($position, sprintf('%u',filesize(__FILE__)) * 2);
} catch (OssException $e) {
$this->assertFalse(true);
}
Expand Down Expand Up @@ -568,9 +568,9 @@ public function testCheckMD5()
*/
try {
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, 0, $options);
$this->assertEquals($position, filesize(__FILE__));
$this->assertEquals($position, sprintf('%u',filesize(__FILE__)));
$position = $this->ossClient->appendFile($this->bucket, $object, __FILE__, $position, $options);
$this->assertEquals($position, filesize(__FILE__) * 2);
$this->assertEquals($position, sprintf('%u',filesize(__FILE__)) * 2);
} catch (OssException $e) {
$this->assertFalse(true);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/OSS/Tests/OssClientSignatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testGetSignedUrlForPuttingObjectFromFile()
$request->set_method('PUT');
$request->add_header('Content-Type', 'txt');
$request->set_read_file($file);
$request->set_read_stream_size(filesize($file));
$request->set_read_stream_size(sprintf('%u',filesize($file)));
$request->send_request();
$res = new ResponseCore($request->get_response_header(),
$request->get_response_body(), $request->get_response_code());
Expand Down
6 changes: 3 additions & 3 deletions tests/OSS/Tests/OssUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,18 @@ public function testReadDir()

public function testGetMd5SumForFile()
{
$this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, filesize(__FILE__) - 1), base64_encode(md5(file_get_contents(__FILE__), true)));
$this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, sprintf('%u',filesize(__FILE__)) - 1), base64_encode(md5(file_get_contents(__FILE__), true)));
// false case
$this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, OssClient::OSS_MAX_PART_SIZE + 1), "");
$this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, filesize(__FILE__) + 1), "");
$this->assertEquals(OssUtil::getMd5SumForFile(__FILE__, 0, sprintf('%u',filesize(__FILE__)) + 1), "");

}

public function testGenerateFile()
{
$path = __DIR__ . DIRECTORY_SEPARATOR . "generatedFile.txt";
OssUtil::generateFile($path, 1024 * 1024);
$this->assertEquals(filesize($path), 1024 * 1024);
$this->assertEquals(sprintf('%u',filesize($path)), 1024 * 1024);
unlink($path);
}

Expand Down

0 comments on commit 9d16ee5

Please sign in to comment.