Linux anchor 4.4.0-210-generic #242-Ubuntu SMP Fri Apr 16 09:57:56 UTC 2021 x86_64
Apache/2.4.18 (Ubuntu)
Server IP : 10.10.100.4 & Your IP : 216.73.217.150
Domains :
Cant Read [ /etc/named.conf ]
User : www-data
Terminal
Auto Root
Create File
Create Folder
Localroot Suggester
Backdoor Destroyer
Readme
/
var /
www /
wiki.bernardino.org /
includes /
Delete
Unzip
Name
Size
Permission
Date
Action
actions
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
api
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
auth
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
cache
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
changes
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
changetags
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
clientpool
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
collation
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
compat
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
composer
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
config
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
content
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
context
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
dao
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
db
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
debug
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
deferred
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
diff
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
exception
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
export
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
extauth
[ DIR ]
drwxr-xr-x
2012-03-22 16:23
externalstore
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
filebackend
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
filerepo
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
gallery
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
htmlform
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
http
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
import
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
installer
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
interwiki
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
job
[ DIR ]
drwxr-xr-x
2012-03-22 16:23
jobqueue
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
json
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
libs
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
linker
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
logging
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
mail
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
media
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
normal
[ DIR ]
drwxr-xr-x
2012-03-22 16:23
objectcache
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
page
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
pager
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
parser
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
password
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
poolcounter
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
profiler
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
rcfeed
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
registration
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
resourceloader
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
revisiondelete
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
search
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
services
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
session
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
site
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
skins
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
specialpage
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
specials
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
templates
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
tidy
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
title
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
upload
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
user
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
utils
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
widget
[ DIR ]
drwxr-xr-x
2016-11-28 20:20
zhtable
[ DIR ]
drwxr-xr-x
2012-03-22 16:23
.htaccess
197
B
-r--r--r--
2026-08-22 08:29
Action.php
12.43
KB
-rw-r--r--
2011-09-16 17:01
AjaxDispatcher.php
4.03
KB
-rw-r--r--
2016-11-28 20:20
AjaxResponse.php
8.15
KB
-rw-r--r--
2016-11-28 20:20
Article.php
58.64
KB
-rw-r--r--
2011-11-15 20:46
AuthPlugin.php
9.2
KB
-rw-r--r--
2016-11-28 20:20
AutoLoader.php
3
KB
-rw-r--r--
2016-11-28 20:20
Autopromote.php
6.77
KB
-rw-r--r--
2016-11-28 20:20
BacklinkCache.php
9.03
KB
-rw-r--r--
2011-06-30 01:09
Block.php
41.97
KB
-rw-r--r--
2016-11-28 20:20
Category.php
10.34
KB
-rw-r--r--
2016-11-28 20:20
CategoryFinder.php
6.2
KB
-rw-r--r--
2016-11-28 20:20
CategoryPage.php
21.84
KB
-rw-r--r--
2011-10-28 23:20
CategoryViewer.php
22.5
KB
-rw-r--r--
2016-11-28 20:20
Categoryfinder.php
5.13
KB
-rw-r--r--
2011-05-19 02:03
Cdb.php
3.57
KB
-rw-r--r--
2011-05-28 20:58
Cdb_PHP.php
10.11
KB
-rw-r--r--
2011-05-28 19:51
ChangeTags.php
6.66
KB
-rw-r--r--
2011-07-09 11:01
ChangesFeed.php
5.82
KB
-rw-r--r--
2011-06-19 07:45
ChangesList.php
35.52
KB
-rw-r--r--
2011-10-25 23:51
Collation.php
9.86
KB
-rw-r--r--
2011-09-21 00:36
ConfEditor.php
29.16
KB
-rw-r--r--
2011-08-27 21:28
Cookie.php
6.17
KB
-rw-r--r--
2011-06-02 00:35
CryptRand.php
16.96
KB
-rw-r--r--
2012-03-21 11:43
DefaultSettings.php
265.47
KB
-rw-r--r--
2016-11-28 20:20
Defines.php
7.85
KB
-rw-r--r--
2016-11-28 20:20
DeprecatedGlobal.php
1.9
KB
-rw-r--r--
2016-11-28 20:20
DerivativeRequest.php
2.46
KB
-rw-r--r--
2016-11-28 20:20
DjVuImage.php
10.58
KB
-rw-r--r--
2011-05-18 00:03
DummyLinker.php
9.01
KB
-rw-r--r--
2016-11-28 20:20
EditPage.php
136.53
KB
-rw-r--r--
2016-11-28 20:20
EventRelayerGroup.php
1.27
KB
-rw-r--r--
2016-11-28 20:20
Exception.php
11.5
KB
-rw-r--r--
2011-10-22 04:34
Export.php
32.27
KB
-rw-r--r--
2011-11-24 02:29
ExternalEdit.php
2.45
KB
-rw-r--r--
2011-09-07 22:14
ExternalStore.php
4.29
KB
-rw-r--r--
2011-05-29 16:24
ExternalStoreDB.php
4.44
KB
-rw-r--r--
2011-10-17 00:24
ExternalStoreHttp.php
463
B
-rw-r--r--
2010-01-08 22:35
ExternalUser.php
8.96
KB
-rw-r--r--
2011-05-26 21:52
FakeTitle.php
6.6
KB
-rw-r--r--
2011-05-26 22:38
Fallback.php
5.49
KB
-rw-r--r--
2011-05-28 20:58
FauxRequest.php
5.66
KB
-rw-r--r--
2016-11-28 20:20
Feed.php
10.58
KB
-rw-r--r--
2016-11-28 20:20
FeedUtils.php
8.64
KB
-rw-r--r--
2016-11-28 20:20
FileDeleteForm.php
11.7
KB
-rw-r--r--
2016-11-28 20:20
ForkController.php
5.4
KB
-rw-r--r--
2016-11-28 20:20
FormOptions.php
11.08
KB
-rw-r--r--
2016-11-28 20:20
GenderCache.php
3.35
KB
-rw-r--r--
2011-09-19 14:58
GitInfo.php
10.74
KB
-rw-r--r--
2016-11-28 20:20
GlobalFunctions.php
106.76
KB
-rw-r--r--
2016-11-28 20:20
HTMLForm.php
49.55
KB
-rw-r--r--
2011-11-09 18:04
HistoryBlob.php
16.15
KB
-rw-r--r--
2016-11-28 20:20
HistoryPage.php
21.66
KB
-rw-r--r--
2011-09-16 16:12
Hooks.php
6.47
KB
-rw-r--r--
2016-11-28 20:20
Html.php
31.91
KB
-rw-r--r--
2016-11-28 20:20
HtmlFormatter.php
1015
B
-rw-r--r--
2016-11-28 20:20
HttpFunctions.old.php
319
B
-rw-r--r--
2011-05-28 17:59
HttpFunctions.php
21.28
KB
-rw-r--r--
2011-09-16 15:19
IP.php
21.58
KB
-rw-r--r--
2011-11-09 16:00
ImageFunctions.php
2.58
KB
-rw-r--r--
2011-05-29 16:24
ImageGallery.php
10.46
KB
-rw-r--r--
2011-07-16 01:18
ImagePage.php
36
KB
-rw-r--r--
2011-07-11 02:39
ImageQueryPage.php
1.5
KB
-rw-r--r--
2011-05-26 21:21
Import.php
33.63
KB
-rw-r--r--
2011-10-28 23:20
Init.php
4.67
KB
-rw-r--r--
2011-06-17 01:40
Licenses.php
4.89
KB
-rw-r--r--
2016-11-28 20:20
LinkFilter.php
6.08
KB
-rw-r--r--
2016-11-28 20:20
Linker.php
72.71
KB
-rw-r--r--
2016-11-28 20:20
LinksUpdate.php
23.7
KB
-rw-r--r--
2011-11-14 21:58
ListToggle.php
2.02
KB
-rw-r--r--
2016-11-28 20:20
LocalisationCache.php
29.31
KB
-rw-r--r--
2011-09-12 17:03
LogEventsList.php
32.56
KB
-rw-r--r--
2011-07-10 20:12
LogPage.php
16.09
KB
-rw-r--r--
2011-07-10 20:12
MWFunction.php
1.96
KB
-rw-r--r--
2011-03-22 21:23
MWGrants.php
5.85
KB
-rw-r--r--
2016-11-28 20:20
MWNamespace.php
13.76
KB
-rw-r--r--
2016-11-28 20:20
MWTimestamp.php
6.1
KB
-rw-r--r--
2016-11-28 20:20
MagicWord.php
15.1
KB
-rw-r--r--
2016-11-28 20:20
MagicWordArray.php
7.86
KB
-rw-r--r--
2016-11-28 20:20
MediaWiki.php
35.29
KB
-rw-r--r--
2016-11-28 20:20
MediaWikiServices.php
18.8
KB
-rw-r--r--
2016-11-28 20:20
MediaWikiVersionFetcher.php
746
B
-rw-r--r--
2016-11-28 20:20
MergeHistory.php
10.41
KB
-rw-r--r--
2016-11-28 20:20
Message.php
32.49
KB
-rw-r--r--
2016-11-28 20:20
MessageBlobStore.php
10.5
KB
-rw-r--r--
2011-05-28 00:42
Metadata.php
5.53
KB
-rw-r--r--
2011-06-30 00:09
MimeMagic.php
2.87
KB
-rw-r--r--
2016-11-28 20:20
MovePage.php
18.08
KB
-rw-r--r--
2016-11-28 20:20
Namespace.php
7.78
KB
-rw-r--r--
2011-05-21 21:07
NoLocalSettings.php
2.03
KB
-rw-r--r--
2016-11-28 20:20
OutputHandler.php
6.19
KB
-rw-r--r--
2016-11-28 20:20
OutputPage.php
113
KB
-rw-r--r--
2016-11-28 20:20
PHPVersionCheck.php
8.52
KB
-rw-r--r--
2016-11-28 20:20
PHPVersionError.php
2.96
KB
-rw-r--r--
2011-07-19 01:06
PageProps.php
8.52
KB
-rw-r--r--
2016-11-28 20:20
PageQueryPage.php
680
B
-rw-r--r--
2010-12-22 15:16
Pager.php
30.89
KB
-rw-r--r--
2011-07-06 04:26
PathRouter.php
12.43
KB
-rw-r--r--
2016-11-28 20:20
PatrolLog.php
2.53
KB
-rw-r--r--
2011-07-10 20:12
Pingback.php
7.31
KB
-rw-r--r--
2016-11-28 20:20
PoolCounter.php
5.65
KB
-rw-r--r--
2011-05-28 21:00
Preferences.php
51.21
KB
-rw-r--r--
2016-11-28 20:20
PrefixSearch.php
12.36
KB
-rw-r--r--
2016-11-28 20:20
ProtectionForm.php
19.56
KB
-rw-r--r--
2016-11-28 20:20
ProxyLookup.php
2.12
KB
-rw-r--r--
2016-11-28 20:20
ProxyTools.php
4.6
KB
-rw-r--r--
2011-09-07 22:14
QueryPage.php
22.76
KB
-rw-r--r--
2011-10-17 00:24
RawPage.php
6.2
KB
-rw-r--r--
2011-07-05 23:28
RecentChange.php
23.52
KB
-rw-r--r--
2011-08-27 21:28
RequestContext.php
7.85
KB
-rw-r--r--
2012-01-04 02:07
Revision.php
54.61
KB
-rw-r--r--
2016-11-28 20:20
RevisionList.php
9.25
KB
-rw-r--r--
2016-11-28 20:20
Sanitizer.php
58.04
KB
-rw-r--r--
2016-11-28 20:20
SeleniumWebSettings.php
6.3
KB
-rw-r--r--
2011-06-26 01:27
ServiceWiring.php
11.72
KB
-rw-r--r--
2016-11-28 20:20
Setup.php
27.89
KB
-rw-r--r--
2016-11-28 20:20
SiteConfiguration.php
18.34
KB
-rw-r--r--
2016-11-28 20:20
SiteStats.php
9.85
KB
-rw-r--r--
2016-11-28 20:20
Skin.php
42.13
KB
-rw-r--r--
2012-02-25 16:23
SkinLegacy.php
22.82
KB
-rw-r--r--
2011-10-20 22:50
SkinTemplate.php
64.93
KB
-rw-r--r--
2011-12-09 21:31
SpecialPage.php
31.23
KB
-rw-r--r--
2012-01-04 02:07
SpecialPageFactory.php
17.68
KB
-rw-r--r--
2011-10-28 23:20
SquidPurgeClient.php
10.02
KB
-rw-r--r--
2011-05-21 21:54
Status.php
12.63
KB
-rw-r--r--
2016-11-28 20:20
StreamFile.php
4.66
KB
-rw-r--r--
2016-11-28 20:20
StringUtils.php
11.32
KB
-rw-r--r--
2011-05-21 21:54
StubObject.php
6.4
KB
-rw-r--r--
2016-11-28 20:20
TemplateParser.php
6.46
KB
-rw-r--r--
2016-11-28 20:20
TemplatesOnThisPageFormatter.php
5.36
KB
-rw-r--r--
2016-11-28 20:20
Title.php
140.81
KB
-rw-r--r--
2016-11-28 20:20
TitleArray.php
1.83
KB
-rw-r--r--
2016-11-28 20:20
TitleArrayFromResult.php
1.95
KB
-rw-r--r--
2016-11-28 20:20
User.php
114.26
KB
-rw-r--r--
2012-03-21 11:43
UserArray.php
1.9
KB
-rw-r--r--
2011-05-28 17:59
UserMailer.php
20.52
KB
-rw-r--r--
2012-02-02 15:15
UserRightsProxy.php
5.38
KB
-rw-r--r--
2010-10-14 01:11
ViewCountUpdate.php
3.4
KB
-rw-r--r--
2011-06-25 21:13
WatchedItem.php
5.04
KB
-rw-r--r--
2016-11-28 20:20
WatchedItemQueryService.php
20.4
KB
-rw-r--r--
2016-11-28 20:20
WatchedItemStore.php
25.57
KB
-rw-r--r--
2016-11-28 20:20
WebRequest.php
37.68
KB
-rw-r--r--
2016-11-28 20:20
WebRequestUpload.php
3.4
KB
-rw-r--r--
2016-11-28 20:20
WebResponse.php
9.2
KB
-rw-r--r--
2016-11-28 20:20
WebStart.php
5.54
KB
-rw-r--r--
2016-11-28 20:20
Wiki.php
20.05
KB
-rw-r--r--
2012-01-03 18:34
WikiCategoryPage.php
898
B
-rw-r--r--
2011-08-27 21:28
WikiError.php
3.84
KB
-rw-r--r--
2011-05-06 23:09
WikiFilePage.php
3.34
KB
-rw-r--r--
2011-07-01 22:07
WikiMap.php
8.19
KB
-rw-r--r--
2016-11-28 20:20
WikiPage.php
78.59
KB
-rw-r--r--
2012-01-12 23:09
Xml.php
26.47
KB
-rw-r--r--
2016-11-28 20:20
XmlSelect.php
3.46
KB
-rw-r--r--
2016-11-28 20:20
XmlTypeCheck.php
2.45
KB
-rw-r--r--
2011-05-21 21:36
ZhClient.php
2.92
KB
-rw-r--r--
2011-05-29 16:25
ZhConversion.php
415
KB
-rw-r--r--
2011-10-27 23:40
ZipDirectoryReader.php
20.35
KB
-rw-r--r--
2011-05-13 18:16
limit.sh
2.86
KB
-rwxr-xr-x
2016-11-28 20:20
mime.info
3.82
KB
-rw-r--r--
2011-06-29 22:31
mime.types
5.18
KB
-rw-r--r--
2011-06-29 22:31
tidy.conf
413
B
-rw-r--r--
2009-10-25 14:43
wp-blog-header.php
2.74
KB
-r--r--r--
2026-08-22 08:29
wp-cron.php
2.74
KB
-rw-r--r--
2026-08-22 08:29
Save
Rename
<?php /** * A class for reading ZIP file directories, for the purposes of upload * verification. * * Only a functional interface is provided: ZipFileReader::read(). No access is * given to object instances. * */ class ZipDirectoryReader { /** * Read a ZIP file and call a function for each file discovered in it. * * Because this class is aimed at verification, an error is raised on * suspicious or ambiguous input, instead of emulating some standard * behaviour. * * @param $fileName string The archive file name * @param $callback Array The callback function. It will be called for each file * with a single associative array each time, with members: * * - name: The file name. Directories conventionally have a trailing * slash. * * - mtime: The file modification time, in MediaWiki 14-char format * * - size: The uncompressed file size * * @param $options Array An associative array of read options, with the option * name in the key. This may currently contain: * * - zip64: If this is set to true, then we will emulate a * library with ZIP64 support, like OpenJDK 7. If it is set to * false, then we will emulate a library with no knowledge of * ZIP64. * * NOTE: The ZIP64 code is untested and probably doesn't work. It * turned out to be easier to just reject ZIP64 archive uploads, * since they are likely to be very rare. Confirming safety of a * ZIP64 file is fairly complex. What do you do with a file that is * ambiguous and broken when read with a non-ZIP64 reader, but valid * when read with a ZIP64 reader? This situation is normal for a * valid ZIP64 file, and working out what non-ZIP64 readers will make * of such a file is not trivial. * * @return Status object. The following fatal errors are defined: * * - zip-file-open-error: The file could not be opened. * * - zip-wrong-format: The file does not appear to be a ZIP file. * * - zip-bad: There was something wrong or ambiguous about the file * data. * * - zip-unsupported: The ZIP file uses features which * ZipDirectoryReader does not support. * * The default messages for those fatal errors are written in a way that * makes sense for upload verification. * * If a fatal error is returned, more information about the error will be * available in the debug log. * * Note that the callback function may be called any number of times before * a fatal error is returned. If this occurs, the data sent to the callback * function should be discarded. */ public static function read( $fileName, $callback, $options = array() ) { $zdr = new self( $fileName, $callback, $options ); return $zdr->execute(); } /** The file name */ var $fileName; /** The opened file resource */ var $file; /** The cached length of the file, or null if it has not been loaded yet. */ var $fileLength; /** A segmented cache of the file contents */ var $buffer; /** The file data callback */ var $callback; /** The ZIP64 mode */ var $zip64 = false; /** Stored headers */ var $eocdr, $eocdr64, $eocdr64Locator; /** The "extra field" ID for ZIP64 central directory entries */ const ZIP64_EXTRA_HEADER = 0x0001; /** The segment size for the file contents cache */ const SEGSIZE = 16384; /** The index of the "general field" bit for UTF-8 file names */ const GENERAL_UTF8 = 11; /** The index of the "general field" bit for central directory encryption */ const GENERAL_CD_ENCRYPTED = 13; /** * Private constructor */ protected function __construct( $fileName, $callback, $options ) { $this->fileName = $fileName; $this->callback = $callback; if ( isset( $options['zip64'] ) ) { $this->zip64 = $options['zip64']; } } /** * Read the directory according to settings in $this. * * @return Status */ function execute() { $this->file = fopen( $this->fileName, 'r' ); $this->data = array(); if ( !$this->file ) { return Status::newFatal( 'zip-file-open-error' ); } $status = Status::newGood(); try { $this->readEndOfCentralDirectoryRecord(); if ( $this->zip64 ) { list( $offset, $size ) = $this->findZip64CentralDirectory(); $this->readCentralDirectory( $offset, $size ); } else { if ( $this->eocdr['CD size'] == 0xffffffff || $this->eocdr['CD offset'] == 0xffffffff || $this->eocdr['CD entries total'] == 0xffff ) { $this->error( 'zip-unsupported', 'Central directory header indicates ZIP64, ' . 'but we are in legacy mode. Rejecting this upload is necessary to avoid '. 'opening vulnerabilities on clients using OpenJDK 7 or later.' ); } list( $offset, $size ) = $this->findOldCentralDirectory(); $this->readCentralDirectory( $offset, $size ); } } catch ( ZipDirectoryReaderError $e ) { $status->fatal( $e->getErrorCode() ); } fclose( $this->file ); return $status; } /** * Throw an error, and log a debug message */ function error( $code, $debugMessage ) { wfDebug( __CLASS__.": Fatal error: $debugMessage\n" ); throw new ZipDirectoryReaderError( $code ); } /** * Read the header which is at the end of the central directory, * unimaginatively called the "end of central directory record" by the ZIP * spec. */ function readEndOfCentralDirectoryRecord() { $info = array( 'signature' => 4, 'disk' => 2, 'CD start disk' => 2, 'CD entries this disk' => 2, 'CD entries total' => 2, 'CD size' => 4, 'CD offset' => 4, 'file comment length' => 2, ); $structSize = $this->getStructSize( $info ); $startPos = $this->getFileLength() - 65536 - $structSize; if ( $startPos < 0 ) { $startPos = 0; } $block = $this->getBlock( $startPos ); $sigPos = strrpos( $block, "PK\x05\x06" ); if ( $sigPos === false ) { $this->error( 'zip-wrong-format', "zip file lacks EOCDR signature. It probably isn't a zip file." ); } $this->eocdr = $this->unpack( substr( $block, $sigPos ), $info ); $this->eocdr['EOCDR size'] = $structSize + $this->eocdr['file comment length']; if ( $structSize + $this->eocdr['file comment length'] != strlen( $block ) - $sigPos ) { $this->error( 'zip-bad', 'trailing bytes after the end of the file comment' ); } if ( $this->eocdr['disk'] !== 0 || $this->eocdr['CD start disk'] !== 0 ) { $this->error( 'zip-unsupported', 'more than one disk (in EOCDR)' ); } $this->eocdr += $this->unpack( $block, array( 'file comment' => array( 'string', $this->eocdr['file comment length'] ) ), $sigPos + $structSize ); $this->eocdr['position'] = $startPos + $sigPos; } /** * Read the header called the "ZIP64 end of central directory locator". An * error will be raised if it does not exist. */ function readZip64EndOfCentralDirectoryLocator() { $info = array( 'signature' => array( 'string', 4 ), 'eocdr64 start disk' => 4, 'eocdr64 offset' => 8, 'number of disks' => 4, ); $structSize = $this->getStructSize( $info ); $block = $this->getBlock( $this->getFileLength() - $this->eocdr['EOCDR size'] - $structSize, $structSize ); $this->eocdr64Locator = $data = $this->unpack( $block, $info ); if ( $data['signature'] !== "PK\x06\x07" ) { // Note: Java will allow this and continue to read the // EOCDR64, so we have to reject the upload, we can't // just use the EOCDR header instead. $this->error( 'zip-bad', 'wrong signature on Zip64 end of central directory locator' ); } } /** * Read the header called the "ZIP64 end of central directory record". It * may replace the regular "end of central directory record" in ZIP64 files. */ function readZip64EndOfCentralDirectoryRecord() { if ( $this->eocdr64Locator['eocdr64 start disk'] != 0 || $this->eocdr64Locator['number of disks'] != 0 ) { $this->error( 'zip-unsupported', 'more than one disk (in EOCDR64 locator)' ); } $info = array( 'signature' => array( 'string', 4 ), 'EOCDR64 size' => 8, 'version made by' => 2, 'version needed' => 2, 'disk' => 4, 'CD start disk' => 4, 'CD entries this disk' => 8, 'CD entries total' => 8, 'CD size' => 8, 'CD offset' => 8 ); $structSize = $this->getStructSize( $info ); $block = $this->getBlock( $this->eocdr64Locator['eocdr64 offset'], $structSize ); $this->eocdr64 = $data = $this->unpack( $block, $info ); if ( $data['signature'] !== "PK\x06\x06" ) { $this->error( 'zip-bad', 'wrong signature on Zip64 end of central directory record' ); } if ( $data['disk'] !== 0 || $data['CD start disk'] !== 0 ) { $this->error( 'zip-unsupported', 'more than one disk (in EOCDR64)' ); } } /** * Find the location of the central directory, as would be seen by a * non-ZIP64 reader. * * @return List containing offset, size and end position. */ function findOldCentralDirectory() { $size = $this->eocdr['CD size']; $offset = $this->eocdr['CD offset']; $endPos = $this->eocdr['position']; // Some readers use the EOCDR position instead of the offset field // to find the directory, so to be safe, we check if they both agree. if ( $offset + $size != $endPos ) { $this->error( 'zip-bad', 'the central directory does not immediately precede the end ' . 'of central directory record' ); } return array( $offset, $size ); } /** * Find the location of the central directory, as would be seen by a * ZIP64-compliant reader. * * @return List containing offset, size and end position. */ function findZip64CentralDirectory() { // The spec is ambiguous about the exact rules of precedence between the // ZIP64 headers and the original headers. Here we follow zip_util.c // from OpenJDK 7. $size = $this->eocdr['CD size']; $offset = $this->eocdr['CD offset']; $numEntries = $this->eocdr['CD entries total']; $endPos = $this->eocdr['position']; if ( $size == 0xffffffff || $offset == 0xffffffff || $numEntries == 0xffff ) { $this->readZip64EndOfCentralDirectoryLocator(); if ( isset( $this->eocdr64Locator['eocdr64 offset'] ) ) { $this->readZip64EndOfCentralDirectoryRecord(); if ( isset( $this->eocdr64['CD offset'] ) ) { $size = $this->eocdr64['CD size']; $offset = $this->eocdr64['CD offset']; $endPos = $this->eocdr64Locator['eocdr64 offset']; } } } // Some readers use the EOCDR position instead of the offset field // to find the directory, so to be safe, we check if they both agree. if ( $offset + $size != $endPos ) { $this->error( 'zip-bad', 'the central directory does not immediately precede the end ' . 'of central directory record' ); } return array( $offset, $size ); } /** * Read the central directory at the given location */ function readCentralDirectory( $offset, $size ) { $block = $this->getBlock( $offset, $size ); $fixedInfo = array( 'signature' => array( 'string', 4 ), 'version made by' => 2, 'version needed' => 2, 'general bits' => 2, 'compression method' => 2, 'mod time' => 2, 'mod date' => 2, 'crc-32' => 4, 'compressed size' => 4, 'uncompressed size' => 4, 'name length' => 2, 'extra field length' => 2, 'comment length' => 2, 'disk number start' => 2, 'internal attrs' => 2, 'external attrs' => 4, 'local header offset' => 4, ); $fixedSize = $this->getStructSize( $fixedInfo ); $pos = 0; while ( $pos < $size ) { $data = $this->unpack( $block, $fixedInfo, $pos ); $pos += $fixedSize; if ( $data['signature'] !== "PK\x01\x02" ) { $this->error( 'zip-bad', 'Invalid signature found in directory entry' ); } $variableInfo = array( 'name' => array( 'string', $data['name length'] ), 'extra field' => array( 'string', $data['extra field length'] ), 'comment' => array( 'string', $data['comment length'] ), ); $data += $this->unpack( $block, $variableInfo, $pos ); $pos += $this->getStructSize( $variableInfo ); if ( $this->zip64 && ( $data['compressed size'] == 0xffffffff || $data['uncompressed size'] == 0xffffffff || $data['local header offset'] == 0xffffffff ) ) { $zip64Data = $this->unpackZip64Extra( $data['extra field'] ); if ( $zip64Data ) { $data = $zip64Data + $data; } } if ( $this->testBit( $data['general bits'], self::GENERAL_CD_ENCRYPTED ) ) { $this->error( 'zip-unsupported', 'central directory encryption is not supported' ); } // Convert the timestamp into MediaWiki format // For the format, please see the MS-DOS 2.0 Programmer's Reference, // pages 3-5 and 3-6. $time = $data['mod time']; $date = $data['mod date']; $year = 1980 + ( $date >> 9 ); $month = ( $date >> 5 ) & 15; $day = $date & 31; $hour = ( $time >> 11 ) & 31; $minute = ( $time >> 5 ) & 63; $second = ( $time & 31 ) * 2; $timestamp = sprintf( "%04d%02d%02d%02d%02d%02d", $year, $month, $day, $hour, $minute, $second ); // Convert the character set in the file name if ( !function_exists( 'iconv' ) || $this->testBit( $data['general bits'], self::GENERAL_UTF8 ) ) { $name = $data['name']; } else { $name = iconv( 'CP437', 'UTF-8', $data['name'] ); } // Compile a data array for the user, with a sensible format $userData = array( 'name' => $name, 'mtime' => $timestamp, 'size' => $data['uncompressed size'], ); call_user_func( $this->callback, $userData ); } } /** * Interpret ZIP64 "extra field" data and return an associative array. */ function unpackZip64Extra( $extraField ) { $extraHeaderInfo = array( 'id' => 2, 'size' => 2, ); $extraHeaderSize = $this->getStructSize( $extraHeaderInfo ); $zip64ExtraInfo = array( 'uncompressed size' => 8, 'compressed size' => 8, 'local header offset' => 8, 'disk number start' => 4, ); $extraPos = 0; while ( $extraPos < strlen( $extraField ) ) { $extra = $this->unpack( $extraField, $extraHeaderInfo, $extraPos ); $extraPos += $extraHeaderSize; $extra += $this->unpack( $extraField, array( 'data' => array( 'string', $extra['size'] ) ), $extraPos ); $extraPos += $extra['size']; if ( $extra['id'] == self::ZIP64_EXTRA_HEADER ) { return $this->unpack( $extra['data'], $zip64ExtraInfo ); } } return false; } /** * Get the length of the file. */ function getFileLength() { if ( $this->fileLength === null ) { $stat = fstat( $this->file ); $this->fileLength = $stat['size']; } return $this->fileLength; } /** * Get the file contents from a given offset. If there are not enough bytes * in the file to satisfy the request, an exception will be thrown. * * @param $start The byte offset of the start of the block. * @param $length The number of bytes to return. If omitted, the remainder * of the file will be returned. * * @return string */ function getBlock( $start, $length = null ) { $fileLength = $this->getFileLength(); if ( $start >= $fileLength ) { $this->error( 'zip-bad', "getBlock() requested position $start, " . "file length is $fileLength" ); } if ( $length === null ) { $length = $fileLength - $start; } $end = $start + $length; if ( $end > $fileLength ) { $this->error( 'zip-bad', "getBlock() requested end position $end, " . "file length is $fileLength" ); } $startSeg = floor( $start / self::SEGSIZE ); $endSeg = ceil( $end / self::SEGSIZE ); $block = ''; for ( $segIndex = $startSeg; $segIndex <= $endSeg; $segIndex++ ) { $block .= $this->getSegment( $segIndex ); } $block = substr( $block, $start - $startSeg * self::SEGSIZE, $length ); if ( strlen( $block ) < $length ) { $this->error( 'zip-bad', 'getBlock() returned an unexpectedly small amount of data' ); } return $block; } /** * Get a section of the file starting at position $segIndex * self::SEGSIZE, * of length self::SEGSIZE. The result is cached. This is a helper function * for getBlock(). * * If there are not enough bytes in the file to satsify the request, the * return value will be truncated. If a request is made for a segment beyond * the end of the file, an empty string will be returned. */ function getSegment( $segIndex ) { if ( !isset( $this->buffer[$segIndex] ) ) { $bytePos = $segIndex * self::SEGSIZE; if ( $bytePos >= $this->getFileLength() ) { $this->buffer[$segIndex] = ''; return ''; } if ( fseek( $this->file, $bytePos ) ) { $this->error( 'zip-bad', "seek to $bytePos failed" ); } $seg = fread( $this->file, self::SEGSIZE ); if ( $seg === false ) { $this->error( 'zip-bad', "read from $bytePos failed" ); } $this->buffer[$segIndex] = $seg; } return $this->buffer[$segIndex]; } /** * Get the size of a structure in bytes. See unpack() for the format of $struct. */ function getStructSize( $struct ) { $size = 0; foreach ( $struct as $type ) { if ( is_array( $type ) ) { list( $typeName, $fieldSize ) = $type; $size += $fieldSize; } else { $size += $type; } } return $size; } /** * Unpack a binary structure. This is like the built-in unpack() function * except nicer. * * @param $string The binary data input * * @param $struct An associative array giving structure members and their * types. In the key is the field name. The value may be either an * integer, in which case the field is a little-endian unsigned integer * encoded in the given number of bytes, or an array, in which case the * first element of the array is the type name, and the subsequent * elements are type-dependent parameters. Only one such type is defined: * - "string": The second array element gives the length of string. * Not null terminated. * * @param $offset The offset into the string at which to start unpacking. * * @return Unpacked associative array. Note that large integers in the input * may be represented as floating point numbers in the return value, so * the use of weak comparison is advised. */ function unpack( $string, $struct, $offset = 0 ) { $size = $this->getStructSize( $struct ); if ( $offset + $size > strlen( $string ) ) { $this->error( 'zip-bad', 'unpack() would run past the end of the supplied string' ); } $data = array(); $pos = $offset; foreach ( $struct as $key => $type ) { if ( is_array( $type ) ) { list( $typeName, $fieldSize ) = $type; switch ( $typeName ) { case 'string': $data[$key] = substr( $string, $pos, $fieldSize ); $pos += $fieldSize; break; default: throw new MWException( __METHOD__.": invalid type \"$typeName\"" ); } } else { // Unsigned little-endian integer $length = intval( $type ); $bytes = substr( $string, $pos, $length ); // Calculate the value. Use an algorithm which automatically // upgrades the value to floating point if necessary. $value = 0; for ( $i = $length - 1; $i >= 0; $i-- ) { $value *= 256; $value += ord( $string[$pos + $i] ); } // Throw an exception if there was loss of precision if ( $value > pow( 2, 52 ) ) { $this->error( 'zip-unsupported', 'number too large to be stored in a double. ' . 'This could happen if we tried to unpack a 64-bit structure ' . 'at an invalid location.' ); } $data[$key] = $value; $pos += $length; } } return $data; } /** * Returns a bit from a given position in an integer value, converted to * boolean. * * @param $value integer * @param $bitIndex The index of the bit, where 0 is the LSB. */ function testBit( $value, $bitIndex ) { return (bool)( ( $value >> $bitIndex ) & 1 ); } /** * Debugging helper function which dumps a string in hexdump -C format. */ function hexDump( $s ) { $n = strlen( $s ); for ( $i = 0; $i < $n; $i += 16 ) { printf( "%08X ", $i ); for ( $j = 0; $j < 16; $j++ ) { print " "; if ( $j == 8 ) { print " "; } if ( $i + $j >= $n ) { print " "; } else { printf( "%02X", ord( $s[$i + $j] ) ); } } print " |"; for ( $j = 0; $j < 16; $j++ ) { if ( $i + $j >= $n ) { print " "; } elseif ( ctype_print( $s[$i + $j] ) ) { print $s[$i + $j]; } else { print '.'; } } print "|\n"; } } } /** * Internal exception class. Will be caught by private code. */ class ZipDirectoryReaderError extends Exception { var $code; function __construct( $code ) { $this->code = $code; parent::__construct( "ZipDirectoryReader error: $code" ); } function getErrorCode() { return $this->code; } }