Skip to content

Commit b34b7ac

Browse files
committed
Apply suggestions from code review
1 parent a290116 commit b34b7ac

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/FileCache.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,14 @@ protected function cacheFromResource(File $file, $source, $target)
567567
$maxBytes = intval($this->config['max_file_size']);
568568
// Copy one byte more than allowed to detect files that exceed the limit.
569569
// Using $maxBytes directly would reject files of exactly $maxBytes bytes.
570-
$copyLimit = $maxBytes >= 0 ? $maxBytes + 1 : -1;
570+
// Clamp at PHP_INT_MAX to avoid overflowing to float for very large limits.
571+
if ($maxBytes < 0) {
572+
$copyLimit = -1;
573+
} elseif ($maxBytes < PHP_INT_MAX) {
574+
$copyLimit = $maxBytes + 1;
575+
} else {
576+
$copyLimit = PHP_INT_MAX;
577+
}
571578
$bytes = stream_copy_to_stream($source, $target, $copyLimit);
572579

573580
if ($bytes === false) {

tests/FileCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public function testGetRemoteExactlyMaxSize()
109109
$cache->stream = $stream;
110110
$path = $cache->get($file, $this->noop);
111111
$this->assertEquals(3, filesize($path));
112+
$this->assertFalse(is_resource($cache->stream));
112113
}
113114

114115
public function testGetDiskDoesNotExist()
@@ -200,7 +201,6 @@ public function testGetDiskCloudExactlyMaxSize()
200201
{
201202
config(['filesystems.disks.s3' => ['driver' => 's3']]);
202203
$file = new GenericFile('s3://files/image.txt');
203-
$hash = hash('sha256', 's3://files/image.txt');
204204

205205
$stream = fopen('php://temp', 'r+');
206206
fwrite($stream, 'abc');

0 commit comments

Comments
 (0)