From: umorigu Date: Tue, 14 Dec 2021 14:37:09 +0000 (+0900) Subject: BugTrack/2514 PHP8 - dump plugin: Support empty (0 byte) file X-Git-Tag: r1_5_4~24 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ebd04029ab4adc3d37b87373d1e8e79a51bfd76a;hp=779d7eaec0610523f7df97e9503cc3f8d63a1fae;p=pukiwiki%2Fpukiwiki.git BugTrack/2514 PHP8 - dump plugin: Support empty (0 byte) file * Avoid error on fread($fp, 0) * Improve filename pattern --- diff --git a/plugin/dump.inc.php b/plugin/dump.inc.php index 46c4f37..20fb95c 100644 --- a/plugin/dump.inc.php +++ b/plugin/dump.inc.php @@ -32,15 +32,18 @@ global $_STORAGE; // DATA_DIR (wiki/*.txt) $_STORAGE['DATA_DIR']['add_filter'] = '^[0-9A-F]+\.txt'; -$_STORAGE['DATA_DIR']['extract_filter'] = '^' . preg_quote(DATA_DIR, '/') . '((?:[0-9A-F])+)(\.txt){0,1}'; +$_STORAGE['DATA_DIR']['extract_filter'] = '^' . preg_quote(DATA_DIR, '/') + . '((?:[0-9A-F])+)(\.txt){0,1}$'; // UPLOAD_DIR (attach/*) $_STORAGE['UPLOAD_DIR']['add_filter'] = '^[0-9A-F_]+'; -$_STORAGE['UPLOAD_DIR']['extract_filter'] = '^' . preg_quote(UPLOAD_DIR, '/') . '((?:[0-9A-F]{2})+)_((?:[0-9A-F])+)'; +$_STORAGE['UPLOAD_DIR']['extract_filter'] = '^' . preg_quote(UPLOAD_DIR, '/') + . '((?:[0-9A-F]{2})+)_((?:[0-9A-F])+)(\.(log|[0-9]{1,3})){0,1}$'; // BACKUP_DIR (backup/*.gz) $_STORAGE['BACKUP_DIR']['add_filter'] = '^[0-9A-F]+\.gz'; -$_STORAGE['BACKUP_DIR']['extract_filter'] = '^' . preg_quote(BACKUP_DIR, '/') . '((?:[0-9A-F])+)(\.gz){0,1}'; +$_STORAGE['BACKUP_DIR']['extract_filter'] = '^' . preg_quote(BACKUP_DIR, '/') + . '((?:[0-9A-F])+)(\.gz){0,1}$'; ///////////////////////////////////////////////// @@ -391,7 +394,7 @@ class tarlib if ($this->status != TARLIB_STATUS_CREATE) return ''; // File is not created - unset($files); + $files = array(); // 指定されたパスのファイルのリストを取得する $dp = @opendir($dir); @@ -462,7 +465,12 @@ class tarlib // ファイルデータの取得 $fpr = @fopen($name , 'rb'); flock($fpr, LOCK_SH); - $data = fread($fpr, $size); + if ($size === 0) { + // Avoid error on fread($fp, 0); + $data = ''; + } else { + $data = fread($fpr, $size); + } flock($fpr, LOCK_UN); fclose( $fpr ); @@ -600,7 +608,6 @@ class tarlib function extract($pattern) { if ($this->status != TARLIB_STATUS_OPEN) return ''; // Not opened - $files = array(); $longname = ''; @@ -665,12 +672,21 @@ class tarlib if ($name == TARLIB_DATA_LONGLINK) { // LongLink - $buff = fread($this->fp, $pdsz); + if ($pdsz) { + $buff = fread($this->fp, $pdsz); + } else { + // 0 or invalid + $buff = ''; + } $longname = substr($buff, 0, $size); } else if (preg_match("/$pattern/", $name) ) { // } else if ($type == 0 && preg_match("/$pattern/", $name) ) { - $buff = fread($this->fp, $pdsz); - + if ($pdsz) { + $buff = fread($this->fp, $pdsz); + } else { + // 0 or invalid + $buff = ''; + } // 既に同じファイルがある場合は上書きされる $fpw = @fopen($name, 'wb'); if ($fpw !== FALSE) {