Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F7455
SVGreader.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 11:25 PM
2014-11-21 23:25:15 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
SVGreader.patch
View Options
Index: includes/media/SVGMetadataExtractor.php
===================================================================
--- includes/media/SVGMetadataExtractor.php (revision 82956)
+++ includes/media/SVGMetadataExtractor.php (working copy)
@@ -39,6 +39,7 @@
private $reader = null;
private $mDebug = false;
private $metadata = Array();
+ private $filesize = 0;
/**
* Constructor
@@ -49,6 +50,7 @@
function __construct( $source ) {
$this->reader = new XMLReader();
$this->reader->open( $source, null, LIBXML_NOERROR | LIBXML_NOWARNING );
+ $this->filesize = filesize( $source );
$this->metadata['width'] = self::DEFAULT_WIDTH;
$this->metadata['height'] = self::DEFAULT_HEIGHT;
@@ -67,6 +69,7 @@
* Read the SVG
*/
public function read() {
+ global $wgSVGMaxFilesize;
$keepReading = $this->reader->read();
/* Skip until first element */
@@ -98,10 +101,20 @@
$this->readField( $tag, 'description' );
} elseif ( $this->qualifiedNameEquals( $tag, 'svg', 'metadata' ) && $type == XmlReader::ELEMENT ) {
$this->readXml( $tag, 'metadata' );
- } elseif ( $tag !== '#text' ) {
+ } else {
$this->debug( "Unhandled top-level XML tag $tag" );
- $this->animateFilter( $tag );
- //$skip = true;
+
+ /* By default we will want to skip everything that we don't recognize.
+ * If we don't skip, and walk entire files, than limit this to cases
+ * where the filesize is < wgSVGMaxFilesize */
+ $skip = true;
+ $this->debug( "Filesize: " . $this->filesize . " SVGMaxFilesize: " . $wgSVGMaxFilesize );
+ if ( $tag !== '#text' && $this->filesize < $wgSVGMaxFilesize ) {
+ if( !isset( $this->metadata['animated']) ) {
+ $skip = false;
+ $this->animateFilter( $tag );
+ }
+ }
}
if ($skip) {
Index: includes/DefaultSettings.php
===================================================================
--- includes/DefaultSettings.php (revision 82956)
+++ includes/DefaultSettings.php (working copy)
@@ -675,6 +675,9 @@
$wgSVGConverterPath = '';
/** Don't scale a SVG larger than this */
$wgSVGMaxSize = 2048;
+/** Don't parse an SVG larger than this
+ * Default is 1024*1024*10 bytes */
+$wgSVGMaxFilesize = 10485760;
/**
* MediaWiki will reject HTMLesque tags in uploaded files due to idiotic browsers which can't
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6986
Default Alt Text
SVGreader.patch (2 KB)
Attached To
Mode
T29508: SVGMetadataExtractor is taking too much memory/time on large svgs, rendering certain pages inaccessible
Attached
Detach File
Event Timeline
Log In to Comment