Skip to content

Commit 81b6595

Browse files
fix(validation): guard invalid signed file streams in CertificateChainService
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 2717ca0 commit 81b6595

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

lib/Service/File/CertificateChainService.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function getCertificateChain($fileNode, File $libreSignFile, $options): a
2727

2828
try {
2929
$resource = $fileNode->fopen('rb');
30+
if (!is_resource($resource)) {
31+
$this->logger->warning('Failed to load certificate chain: unable to open signed file stream');
32+
return [];
33+
}
3034
$sha256 = $this->getSha256FromResource($resource);
3135
rewind($resource);
3236
if ($sha256 === $libreSignFile->getSignedHash()) {
@@ -42,9 +46,16 @@ public function getCertificateChain($fileNode, File $libreSignFile, $options): a
4246
}
4347

4448
private function getSha256FromResource($resource): string {
49+
if (!is_resource($resource)) {
50+
return '';
51+
}
52+
4553
$hashContext = hash_init('sha256');
4654
while (!feof($resource)) {
4755
$buffer = fread($resource, 8192);
56+
if ($buffer === false) {
57+
break;
58+
}
4859
hash_update($hashContext, $buffer);
4960
}
5061
return hash_final($hashContext);

0 commit comments

Comments
 (0)