This quick patch fixes a bug (#13361) that happens with files that contain the end block as file data (ex. some mp3 files). Marco Pracucci (Waymedia) http://www.pracucci.com http://www.waymedia.it --- /usr/share/php/Archive/Tar.php 2008-02-04 21:17:21.000000000 +0100 +++ library/Waymedia/Archive/Tar.php 2008-03-25 15:20:51.000000000 +0100 @@ -1639,13 +1639,26 @@ return false; } - if ($this->_compress_type == 'gz') { + 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) { + $v_buffer = @gzread($v_temp_tar, 512); + if ($v_buffer == ARCHIVE_TAR_END_BLOCK) { + $end_blocks++; + // do not copy end blocks, we will re-make them // after appending - continue; + continue; + } + // FIX: this quick patch fixes a bug that happens with files that + // contain the end block as file data. This code just adds the + // end block if we have not reached the end of .tar.gz file. + else if ($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); @@ -1654,10 +1667,22 @@ @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) { + $end_blocks++; continue; } + // FIX: this quick patch fixes a bug that happens with files that + // contain the end block as file data. This code just adds the + // end block if we have not reached the end of .tar.bz2 file. + else if ($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); }