Accept multipart ETag signatures for chunked uploads on S3 devices (#12585)

* (test): accept multipart ETag signatures for chunked uploads on S3 devices

* (test): guard against fopen failure in chunked signature helper
This commit is contained in:
Chirag Aggarwal authored and GitHub committed 2026-06-12 09:37:06 +05:30
1 parent 8e4429b6dc
commit 0987b03e70
1 file changed
+33 -1
+33 -1
View File
@@ -24,6 +24,38 @@ trait StorageBase
*/
private static array $cachedZstdBucket = [];
/**
* Valid signatures for a chunk-uploaded file: the content MD5 on local
* devices, or the composite multipart ETag (md5 of part MD5s suffixed
* with the part count) on S3 devices.
*/
protected function getChunkedFileSignatures(string $path, int $chunkSize = 5 * 1024 * 1024): array
{
$signatures = [\md5_file($path)];
$handle = \fopen($path, 'rb');
if ($handle === false) {
return $signatures;
}
$binary = '';
$parts = 0;
while (!\feof($handle)) {
$chunk = \fread($handle, $chunkSize);
if ($chunk === '' || $chunk === false) {
break;
}
$binary .= \md5($chunk, true);
$parts++;
}
\fclose($handle);
if ($parts > 1) {
$signatures[] = \md5($binary) . '-' . $parts;
}
return $signatures;
}
/**
* Helper method to set up bucket and file data for tests.
* Uses static caching to avoid recreating resources.
@@ -287,7 +319,7 @@ trait StorageBase
$this->assertEquals('large-file.mp4', $largeFile['body']['name']);
$this->assertEquals('video/mp4', $largeFile['body']['mimeType']);
$this->assertEquals($totalSize, $largeFile['body']['sizeOriginal']);
$this->assertEquals(md5_file(realpath(__DIR__ . '/../../../resources/disk-a/large-file.mp4')), $largeFile['body']['signature']); // should validate that the file is not encrypted
$this->assertContains($largeFile['body']['signature'], $this->getChunkedFileSignatures(realpath(__DIR__ . '/../../../resources/disk-a/large-file.mp4'))); // should validate that the file is not encrypted
/**
* Failure