Skip to content

Commit

Permalink
Merge pull request #25 from matomo-org/dev-18670
Browse files Browse the repository at this point in the history
Ensure that failing fread won't cause a hanging process
  • Loading branch information
sgiehl authored Nov 21, 2024
2 parents 28bc54b + e29d20c commit 3e96938
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/Bzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,20 @@ public function extract($pathExtracted)
}

$output = fopen($pathExtracted, 'w');

while (!feof($file)) {
fwrite($output, fread($file, 1024 * 1024));
$content = fread($file, 1024 * 1024);

if (false === $content) {
$this->error = "fread failed";
fclose($output);
@unlink($pathExtracted);
return false;
}

fwrite($output, $content);
}

fclose($output);

$success = bzclose($file);
Expand Down
13 changes: 12 additions & 1 deletion src/Gzip.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,20 @@ public function extract($pathExtracted)
}

$output = fopen($pathExtracted, 'w');

while (!feof($file)) {
fwrite($output, fread($file, 1024 * 1024));
$content = fread($file, 1024 * 1024);

if (false === $content) {
$this->error = "fread failed";
fclose($output);
@unlink($pathExtracted);
return false;
}

fwrite($output, $content);
}

fclose($output);

$success = gzclose($file);
Expand Down

0 comments on commit 3e96938

Please sign in to comment.