Skip to content

Commit ed2c527

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

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/Service/File/EnvelopeAssembler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public function buildEnvelopeChildData(File $childFile, \OCA\Libresign\Service\F
143143
$certData = $this->certificateChainService->getCertificateChain($fileNode, $childFile, $options);
144144
} else {
145145
$resource = $fileNode->fopen('rb');
146+
if (!is_resource($resource)) {
147+
throw new \RuntimeException('unable to open signed file stream');
148+
}
146149
$sha256 = $this->getSha256FromResource($resource);
147150
rewind($resource);
148151
if ($sha256 === $childFile->getSignedHash()) {
@@ -164,9 +167,16 @@ public function buildEnvelopeChildData(File $childFile, \OCA\Libresign\Service\F
164167
}
165168

166169
private function getSha256FromResource($resource): string {
170+
if (!is_resource($resource)) {
171+
return '';
172+
}
173+
167174
$hashContext = hash_init('sha256');
168175
while (!feof($resource)) {
169176
$buffer = fread($resource, 8192);
177+
if ($buffer === false) {
178+
break;
179+
}
170180
hash_update($hashContext, $buffer);
171181
}
172182
return hash_final($hashContext);

0 commit comments

Comments
 (0)