From dda7c9142f61e0d54e2575eafef9c923e450e338 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Sat, 22 Jul 2023 12:31:39 +0200 Subject: [PATCH] Cancel and return failure when user aborted connection --- src/ZipStreamer.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ZipStreamer.php b/src/ZipStreamer.php index 03ac56b..aaf6c0f 100644 --- a/src/ZipStreamer.php +++ b/src/ZipStreamer.php @@ -211,6 +211,10 @@ public function addFileFromStream($stream, $filePath, $options = NULL) { list($gpFlags, $lfhLength) = $this->beginFile($filePath, False, $options['comment'], $options['timestamp'], $gpFlags, $options['compress']); list($dataLength, $gzLength, $dataCRC32) = $this->streamFileData($stream, $options['compress'], $options['level']); + if($dataLength === 0) { + // Handle invalid result + return false; + } $ddLength = $this->addDataDescriptor($dataLength, $gzLength, $dataCRC32); @@ -366,6 +370,12 @@ private function streamFileData($stream, $compress, $level) { $this->write($data); $this->flush(); + + // Before potentially reading the next chunk, check if user aborted the connection. + // Ignored (not aborted), when ignore_user_abort is set. + if (connection_aborted() === 1 && ignore_user_abort() === 0) { + return array(0, 0, 0); + } } if (COMPR::DEFLATE === $compress) { $data = $compStream->finish();