From 900a927dd4e08e580fb5cfc83026e78684fc6310 Mon Sep 17 00:00:00 2001 From: Ash-Shiddiqul Akbar Hidayat Date: Wed, 19 Jun 2024 11:31:54 +0700 Subject: [PATCH 1/3] make sure stream_truncate returns boolean. Otherwise you would get this error message: Error: ftruncate(): wapmorgan\UnifiedArchive\LzwStreamWrapper::stream_truncate did not return a boolean --- src/LzwStreamWrapper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/LzwStreamWrapper.php b/src/LzwStreamWrapper.php index 297ec15..8c8f17e 100644 --- a/src/LzwStreamWrapper.php +++ b/src/LzwStreamWrapper.php @@ -403,6 +403,8 @@ public function stream_truncate($new_size) fclose($fp); } } + + return true; } /** From adbef91dff33b785630381b169060c6a72196502 Mon Sep 17 00:00:00 2001 From: Ash-Shiddiqul Akbar Hidayat Date: Wed, 19 Jun 2024 11:33:54 +0700 Subject: [PATCH 2/3] Make sure to update the writtenbytes value when the truncate size is smaller than the original --- src/LzwStreamWrapper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/LzwStreamWrapper.php b/src/LzwStreamWrapper.php index 8c8f17e..5b59940 100644 --- a/src/LzwStreamWrapper.php +++ b/src/LzwStreamWrapper.php @@ -396,6 +396,7 @@ public function stream_truncate($new_size) } elseif ($new_size < $actual_data_size) { if ($this->tmp === null) { $this->data = substr($this->data, 0, $new_size); + $this->writtenBytes = $new_size; } else { $fp = fopen($this->tmp, 'w'.(strpos($this->mode, 'b') !== 0 ? 'b' : null)); @@ -403,7 +404,7 @@ public function stream_truncate($new_size) fclose($fp); } } - + return true; } From e0538fcf194b15ca5e9e56e32f53b1c8080d7ca0 Mon Sep 17 00:00:00 2001 From: Ash-Shiddiqul Akbar Hidayat Date: Wed, 19 Jun 2024 13:39:36 +0700 Subject: [PATCH 3/3] we need to update the datasize everythime ->data is updated --- src/LzwStreamWrapper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/LzwStreamWrapper.php b/src/LzwStreamWrapper.php index 5b59940..5598f14 100644 --- a/src/LzwStreamWrapper.php +++ b/src/LzwStreamWrapper.php @@ -274,6 +274,7 @@ public function stream_close() if (file_exists($this->tmp2)) unlink($this->tmp2); } else { $this->data = null; + $this->dataSize = 0; } } @@ -339,6 +340,7 @@ public function stream_write($data) $postfix = substr($this->data, ($this->pointer + $count)); $this->data = $prefix.$data.$postfix; $this->pointer += $count; + $this->dataSize = strlen($this->data); return $count; } @@ -396,6 +398,7 @@ public function stream_truncate($new_size) } elseif ($new_size < $actual_data_size) { if ($this->tmp === null) { $this->data = substr($this->data, 0, $new_size); + $this->dataSize = strlen($this->data); $this->writtenBytes = $new_size; } else { $fp = fopen($this->tmp, 'w'.(strpos($this->mode, 'b') !== 0