1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-15 11:04:02 +02:00

Constraint memory used in TAR export

This commit is contained in:
Jakub Vrana
2013-05-01 09:33:23 -07:00
parent 17a8495c2e
commit 601cdd43c1
6 changed files with 33 additions and 9 deletions

View File

@@ -409,13 +409,13 @@ function remove_definer($query) {
return preg_replace('~^([A-Z =]+) DEFINER=`' . preg_replace('~@(.*)~', '`@`(%|\\1)', logged_user()) . '`~', '\\1', $query); //! proper escaping of user
}
/** Get string to add a file in TAR
* @param string
/** Add a file to TAR
* @param string
* @param TmpFile
* @return null prints the output
*/
function tar_file($filename, $contents) {
$return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct(strlen($contents)), decoct(time()));
function tar_file($filename, $tmp_file) {
$return = pack("a100a8a8a8a12a12", $filename, 644, 0, 0, decoct($tmp_file->size), decoct(time()));
$checksum = 8*32; // space for checksum itself
for ($i=0; $i < strlen($return); $i++) {
$checksum += ord($return[$i]);
@@ -423,8 +423,8 @@ function tar_file($filename, $contents) {
$return .= sprintf("%06o", $checksum) . "\0 ";
echo $return;
echo str_repeat("\0", 512 - strlen($return));
echo $contents;
echo str_repeat("\0", 511 - (strlen($contents) + 511) % 512);
$tmp_file->send();
echo str_repeat("\0", 511 - ($tmp_file->size + 511) % 512);
}
/** Get INI bytes value

View File

@@ -0,0 +1,21 @@
<?php
class TmpFile {
var $handler;
var $size;
function TmpFile() {
$this->handler = tmpfile();
}
function write($contents) {
$this->size += strlen($contents);
fwrite($this->handler, $contents);
}
function send() {
fseek($this->handler, 0);
fpassthru($this->handler);
fclose($this->handler);
}
}