33 if (!self::$shutdownRegistered) {
34 self::$shutdownRegistered =
true;
35 register_shutdown_function([__CLASS__,
'shutdown']);
43 return new self(
'<!ENTITY');
48 return new self(
'<!DOCTYPE');
50 return new self(
'<!DOCTYPE');
56 if (PHP_MAJOR_VERSION == 7) {
57 switch (PHP_MINOR_VERSION) {
59 return PHP_RELEASE_VERSION >= 1;
61 return PHP_RELEASE_VERSION >= 13;
63 return PHP_RELEASE_VERSION >= 27;
77 if (self::$libxmlDisableEntityLoaderValue === null) {
85 if (self::$libxmlDisableEntityLoaderValue !== null && \PHP_VERSION_ID < 80000) {
86 libxml_disable_entity_loader(self::$libxmlDisableEntityLoaderValue);
87 self::$libxmlDisableEntityLoaderValue = null;
105 $charset = strtoupper(
$result ? $matches[1] :
'UTF-8');
107 if ($charset !==
'UTF-8') {
108 $xml = mb_convert_encoding(
$xml,
'UTF-8', $charset);
111 $charset = strtoupper(
$result ? $matches[1] :
'UTF-8');
112 if ($charset !==
'UTF-8') {
113 throw new Reader\Exception(
'Suspicious Double-encoded XML, spreadsheet file load() aborted to prevent XXE/XEE attacks');
134 $pattern =
'/\\0?' . implode(
'\\0?', str_split($this->pattern)) .
'\\0?/';
137 throw new Reader\Exception(
'Detected use of ENTITY in XML, spreadsheet file load() aborted to prevent XXE/XEE attacks');
140 if ($this->callback !== null && is_callable($this->callback)) {
141 $xml = call_user_func($this->callback,
$xml);
156 return $this->
scan(file_get_contents($filestream));
static $shutdownRegistered
static $libxmlDisableEntityLoaderValue
static threadSafeLibxmlDisableEntityLoaderAvailability()
disableEntityLoaderCheck()
setAdditionalCallback(callable $callback)
Reader for SpreadsheetML, the XML schema for Microsoft Office Excel 2003.
static getLibXmlDisableEntityLoader()
Return the state of the entity loader (disabled/enabled) for libxml loader.
static getInstance(Reader\IReader $reader)
scan($xml)
Scan the XML for use of <!ENTITY to prevent XXE/XEE attacks.
__construct($pattern='<!DOCTYPE')
scanFile($filestream)
Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks.
PhpSpreadsheet root directory.