Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #13361 and #19330 - prevent invalid blocks (orig. patch by Marc…

…o Pracucci)

git-svn-id: https://svn.php.net/repository/pear/packages/Archive_Tar/trunk@324840 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 7b4e4efa3a64fb432147fb990b68a4b2510285be 1 parent 19c5515
@mrook mrook authored
Showing with 19 additions and 1 deletion.
  1. +19 −1 Archive/Tar.php
View
20 Archive/Tar.php
@@ -1773,12 +1773,20 @@ function _openAppend()
}
if ($this->_compress_type == 'gz') {
+ $end_blocks = 0;
+
while (!@gzeof($v_temp_tar)) {
$v_buffer = @gzread($v_temp_tar, 512);
if ($v_buffer == ARCHIVE_TAR_END_BLOCK || strlen($v_buffer) == 0) {
+ $end_blocks++;
// do not copy end blocks, we will re-make them
// after appending
continue;
+ } elseif ($end_blocks > 0) {
+ for ($i = 0; $i < $end_blocks; $i++) {
+ $this->_writeBlock(ARCHIVE_TAR_END_BLOCK);
+ }
+ $end_blocks = 0;
}
$v_binary_data = pack("a512", $v_buffer);
$this->_writeBlock($v_binary_data);
@@ -1787,9 +1795,19 @@ function _openAppend()
@gzclose($v_temp_tar);
}
elseif ($this->_compress_type == 'bz2') {
+ $end_blocks = 0;
+
while (strlen($v_buffer = @bzread($v_temp_tar, 512)) > 0) {
- if ($v_buffer == ARCHIVE_TAR_END_BLOCK) {
+ if ($v_buffer == ARCHIVE_TAR_END_BLOCK || strlen($v_buffer) == 0) {
+ $end_blocks++;
+ // do not copy end blocks, we will re-make them
+ // after appending
continue;
+ } elseif ($end_blocks > 0) {
+ for ($i = 0; $i < $end_blocks; $i++) {
+ $this->_writeBlock(ARCHIVE_TAR_END_BLOCK);
+ }
+ $end_blocks = 0;
}
$v_binary_data = pack("a512", $v_buffer);
$this->_writeBlock($v_binary_data);
Please sign in to comment.
Something went wrong with that request. Please try again.