Bug #23769 [Com]: Archive_Tar in Tar::extractList fails to get file

From: Date: Thu, 20 Sep 2018 14:50:25 +0000
Subject: Bug #23769 [Com]: Archive_Tar in Tar::extractList fails to get file
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to [email protected] to get a copy of this message
Edit report at https://pear.php.net/bugs/bug.php?id=23769&edit=1

 ID:               23769
 Comment by:       aparcos at gmail dot com
 Reported By:      aparcos at gmail dot com
 Summary:          Archive_Tar in Tar::extractList fails to get file
 Status:           Open
 Type:             Bug
 Package:          Archive_Tar
 Operating System: Windows
 Package Version:  1.4.3
 PHP Version:      Irrelevant
 Roadmap Versions: 
 New Comment:

I have changed build.php

==== build.php to create the structure and files is going to generate 
<?php

function createFile($filename, $size, $blocks) {
	$fp = fopen($filename, 'w+b');
	$str = $blocks[rand(0, 3)] . $blocks[rand(0, 3)] . $blocks[rand(0, 3)]
. $blocks[rand(0, 3)];
	$data = str_repeat($str, $size / strlen($str));
    fwrite($fp, $data, $size);	
	fclose($fp);
}

$blocks = [
  'abcd',
  'efgh',
  'ijkl',
  'mnop'
];

if (!file_exists('build')) {
	mkdir('build');
}
chdir('./build/');

$subFolderCounter = 20;
while ($subFolderCounter-- > 0) {
	mkdir($subfolder=uniqid());
	chdir($subfolder);

	$numFiles = 20000;
	while($numFiles-- > 0) {
		createFile('file-' . uniqid(), 1024, $blocks);
	}
	chdir('../');
}

$subFolderCounter = 36;
while ($subFolderCounter-- > 0) {	
	mkdir($subfolder=uniqid());
	chdir($subfolder);
	
	$numSizeTotal = 40 * 1024 * 1024;
	while($numSizeTotal > 0) {
		createFile('file-big-' . uniqid(), $size = rand(15, 20) * 1024 *1024,
$blocks);
		$numSizeTotal -= $size;
	}
	chdir('../');
}

// Create a json file
file_put_contents('file.json', json_encode(['thisAObject' => 0]));

chdir('../');

echo 'Done!', PHP_EOL;


Previous Comments:
------------------------------------------------------------------------

[2018-09-20 10:36:20] aparcos

-Status: Feedback
+Status: Open
Hi Michiel,

I have done some scripts to reproduce it.



==== build.php to create the structure and files is going to generate 
<?php

function createFile($filename, $size, $blocks) {
	$fp = fopen($filename, 'w+b');
	$str = $blocks[rand(0, 3)] . $blocks[rand(0, 3)] . $blocks[rand(0, 3)]
. $blocks[rand(0, 3)];
	$data = str_repeat($str, $size / strlen($str));
    fwrite($fp, $data, $size);	
	fclose($fp);
}

$blocks = [
  'abcd',
  'efgh',
  'ijkl',
  'mnop'
];

if (!file_exists('build')) {
	mkdir('build');
}
chdir('./build/');

$subFolderCounter = 20;
while ($subFolderCounter-- > 0) {
	mkdir($subfolder=uniqid());
	chdir($subfolder);

	$numFiles = 20000;
	while($numFiles-- > 0) {
		createFile('file-' . uniqid(), 1024, $blocks);
	}
	chdir('../');
}

$subFolderCounter = 36;
while ($subFolderCounter-- > 0) {	
	mkdir($subfolder=uniqid());
	chdir($subfolder);
	
	$numSizeTotal = 40 * 1024 * 1024;
	while($numSizeTotal-- > 0) {
		createFile('file-big-' . uniqid(), $size = rand(15, 20) * 1024 *1024,
$blocks);
		$numSizeTotal -= $size;
	}
	chdir('../');
}

// Create a json file
file_put_contents('file.json', json_encode(['thisAObject' => 0]));

chdir('../');

echo 'Done!', PHP_EOL;


==== tar_build.php to generate the whole tar files 

<?php

chdir('./build/');
$output = tar czf ../whole.tar.gz *;

echo "Output: $output\n"; 


==== get.php This will retrieve only one file 

<?php

require_once 'pear/Archive/Tar.php';

$filename = 'file.json';
$tar = new Archive_Tar('whole.tar.gz');
$tar->extractList([$filename]);

if ($tar->error_object !== null) {
        // We found the issue :(
        echo 'Message from error_object: ' . 
$tar->error_object->message, PHP_EOL;
        exit(0);
}

if (file_exists($filename)) {
        // We noy found the issue :)
        echo 'Oops, the file was extracted', PHP_EOL;
        echo file_get_contents($filename);
        unlink($filename);
} 


==== You shouldn't see some message like:

$ php get.php
Message from error_object: Invalid checksum for file
"nopabcdefghmnopmnopabcdefg
hmnopmnopabcdefghmnopmnopabcdefghmnopmnopabcdefghmnopmnopabcdefghmnopmnopabcdefg
hmnopmnopabcdefghmnopmnop/efghmnopmnopabcdefghmnopmnopabcdefghmnopmnopabcdefghmn
opmnopabcdefghmnopmnopabcdefghmnopmnopabcdefgh" : 53388 calculated, 0
expected


Some more comments. I realized could be caused for the number of files
but i am not sure, i have seen for the whole size of the build folder is
created (for me is 2171207697 bytes)

I hope these scripts help to see the real issue.

Thanks!! \o

------------------------------------------------------------------------

[2018-09-19 13:54:10] mrook

-Status: Open
+Status: Feedback
We are unable to reproduce the bug as reported.
Please provide a simple script (10 lines or less)
or a link to an external script that can be used
to reproduce the bug.

If you can provide the script, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PEAR.


Do you have a .tar file I can use to reproduce this?

------------------------------------------------------------------------

[2018-09-19 11:31:09] aparcos

Description:
------------
I have an issue with this library:

Method Tar:extractList cannot get a file when the size of uncompressed
whole files are 2117952732 bytes

this->error_object contains the error message

Invalid checksum for file "global!=="undefined"){g=global}else if(typeof
self!=="undefined"){g=self}else{g=this}g.Plotly = f()}})(function(){var
define,module//**
* plotly.js (gl3d) v1.24.2
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
* Licensed" : 44975 calculated, 0 expected


Where file should be a correct filename but it is the content (or
rubissh from a bad offset, i think, not sure)

Could you check it also for me?

I have used Archive_Tar Pear library version 1.4.3 with PHP 7.2.5
(64bits)

------------------------------------------------------------------------


-- 
Edit this bug report at https://pear.php.net/bugs/bug.php?id=23769&edit=1


Thread (1 message)

« previous php.pear.bugs (#11430) next »