Commit graph

48 commits

Author SHA1 Message Date
Chad Horohoe
cadc248105 (bug 22935) image/x-ms-bmp mime type added for BMP files 2010-04-01 23:27:49 +00:00
Chad Horohoe
a4e5e935b6 Mass convert NULL -> null. Left strings and comments alone, obviously. 2009-12-11 21:07:27 +00:00
Aryeh Gregor
777386da76 Reduce false positives for PHP in MimeMagic
(bug 16583) This was detecting PHP if any of a few three-byte strings
occurred anywhere in the first 1024 bytes of the file.  This is too
paranoid -- it creates a significant number of false positives for
binary files, reportedly on the order of about one every 4096 uploads.

It's hard to see what security advantage this check every conveyed,
because it only looks in the first 1024 bytes anyway.  For the purposes
of upload it could surely be removed entirely, but I didn't check all
callers, so maybe some caller wants to guess whether the file is PHP for
some purpose other than banning it.  So for now I only removed the
checks for the shortest strings, which were most likely to get hit.
2009-11-06 21:03:19 +00:00
Brion Vibber
5bb6e71e38 Fix ordering of OpenDocument type detection so template files can actually be uploaded.
Previously, the shorter types like 'text' matched before the longer ones like 'text-template', causing an .ott file to be misdetected as an .odt... and thus rejected for being the wrong type.
2009-01-22 00:15:16 +00:00
Tim Starling
ea471f0d79 Moved the IE content type checks to their own class. Disassembled IE 5 and 6 and added the results to the class. The entry points now return an array giving MIME types for all versions. The most important version difference is the introduction of an early check for PNG headers in IE 7. Added application/x-msdownload to disallowed types, haven't been able to reproduce any vulnerability, but it's better to be on the safe side. 2008-12-12 15:06:35 +00:00
Tim Starling
c6362060b0 New file upload content type checks using a simulation of IE's content type detection algorithm. 2008-12-05 05:35:22 +00:00
Brion Vibber
a14508de09 * Improved upload file type detection for OpenDocument formats
Added a check for the magic value header in OpenDocument zip archives which specifies which subtype it is. Such files will get detected with the appropriate mime type and matching extension, so ODT etc uploads will work again where enabled.

(Previously the general ZIP check and blacklist would disable them.)
2008-09-25 18:43:33 +00:00
Chad Horohoe
b042f2c835 Add accessor to $rootElement, rather than accessing it directly. 2008-09-19 13:39:30 +00:00
Tim Starling
1347fc05a6 By default, reject file uploads that look like ZIP files, to avoid the so-called GIFAR vulnerability. 2008-08-12 03:10:07 +00:00
Chad Horohoe
53914531b8 Trying this again. Define XML mimetypes in new global called $wgXMLMimeTypes. Used for MimeMagic detection of svg, etc. Now with less code and more documentation. :) 2008-07-02 23:25:20 +00:00
Brion Vibber
f041d796db Revert r36816 for the moment (Add $wgAdditionalXMLTypes, an array of XML mimetypes we can check for with MimeMagic.)
I very much like the idea of making this extensible, but the current implementation has a couple problems. I'd recommend addresses the following:
* The format of the array isn't documented; it has neither examples nor a description of the content format in its comment. If I wanted to add something to it, I wouldn't know what the result should look like without looking up the code.
* Rather than "additional" types, it might be best to simply list *all* the types we recognize in the default array -- then it can be modified and extended in local configuration. This would have the following benefits:
** Allows modifying existing types
** Defaults are an example of format, making the structure self-documenting
** Avoids code duplication -- we only have to check one array, not two, and don't have to worry about their formats getting out of sync.
2008-07-02 23:07:39 +00:00
Chad Horohoe
a946cdda2d Add $wgAdditionalXMLTypes, an array of XML mimetypes we can check for with MimeMagic. 2008-06-30 14:46:19 +00:00
Brion Vibber
2d38ed8aa4 Add 'ogv' as recognized alias to 'ogg', allowing uploads of .ogv files to proceed if allowed 2008-06-06 19:58:06 +00:00
Leon Weber
5677670d27 * * Added 'application/x-dia-diagram' to XML MIME types. Patch by dpy 2008-04-27 13:28:55 +00:00
Siebrand Mazeland
79d5225c0e * remove end of line whitespace
* remove empty lines at end of file
* remove "?>" where still present
2008-04-14 07:45:50 +00:00
River Tarnell
2ae9780ec4 the correct magic for PDF is "%PDF" 2008-02-09 23:59:26 +00:00
Brion Vibber
fee0f038b8 More file type checks...
* Switch XML type detection/validity check from dipping for XML processing instructions, doctypes, or subtags to just trying to parse it and checking the root element's name and namespace. This lets us properly handle SVG files which specify a namespace but no doctype, as well as rejecting files that aren't well-formed. (See http://meta.wikimedia.org/wiki/SVG_validity_checks for some samples of bad files I encountered.) Non-XML files will abort parsing pretty quickly, so this shouldn't be a big burden on other types that didn't hit a magic check.
* Fix Unicode unix script checks (er.... is that even right? :D), remove the iconv dependency
2008-02-06 01:23:12 +00:00
Brion Vibber
d3ddd6efdb While we're in there, let's remove a dependency on iconv(). Do the UTF-16 to ASCII merging in the XML checks manually. 2008-02-05 23:13:17 +00:00
Brion Vibber
aa3fc2541e More SVG detection fixes based on tests on files downloaded from commons...
* Make the autodetection work for UTF-16LE and UTF-16BE XML, which never worked before due to using the wrong string compare length
* Allow doctype strings to break over newlines
* Detect XML if there's a doctype even if there's no XML header (the xml header isn't required for UTF-8 files)
2008-02-05 22:50:21 +00:00
Brion Vibber
839871e486 Fix for XML type checks... don't look for the closing angle-brace on the root tag, as it may not be in the header chunk we read. Some SVGs have a lot of attributes on the root element! 2008-02-05 22:35:28 +00:00
Brion Vibber
d2722f9351 Make an initial stab at refactoring the mime type detection.
Adds magic header checks for the following types:
* MIDI
* Ogg
* PDF
* XCF
* DOS/Windows, Mach-O, and ELF executables

Locks down detection to prevent uploading different file types for the following extensions:
* mid, ogg, pdf, svg, wmf, xcf

This should now cover all the file types we have uploadable at Wikimedia public sites. (I've disabled the old StarOffice formats.)

Changed priority so our own checks happen in favor of the external checks, since we don't trust that stuff. Would like to see much further work here to replace it all.

Hopefully I haven't broken SVG files; I'm not 100% certain the built-in checks are correct.
2008-02-05 22:11:36 +00:00
Roan Kattouw
2e5d1b0c59 Reverting r29798 on the committer's request, part 1 of 2 2008-01-15 16:04:50 +00:00
ThomasV
764238cca2 fix for IE 2008-01-15 15:53:09 +00:00
Brion Vibber
adb89e7f3b * Compatibility with incorrectly detected old-style DJVU mime types 2007-10-01 20:23:14 +00:00
Tim Starling
164bb322f2 Basic integrated audio/video support, with Ogg implementation.
* JavaScript video player based loosely on Greg Maxwell's player
* Image page text snippet customisation
* Abstraction of transform parameters in the parser. Introduced Linker::makeImageLink2().
* Made canRender(), mustRender() depend on file, not just on handler. Moved width=0, height=0 checking to ImageHandler::canRender(), since audio streams have width=height=0 but should be rendered.

Also:
* Automatic upgrade for oldimage rows on image page view, allows media handler selection based on oi_*_mime
* oi_*_mime unconditionally referenced, REQUIRES SCHEMA UPGRADE
* Don't destroy file info for missing files on upgrade
* Simple, centralised extension message file handling
* Made MessageCache::loadAllMessages non-static, optimised for repeated-call case due to abuse in User.php
* Support for lightweight parser output hooks, with callback whitelist for security
* Moved Linker::formatSize() to Language, to join the new formatTimePeriod() and formatBitrate()
* Introduced MagicWordArray, regex capture trick requires that magic word IDs DO NOT CONTAIN HYPHENS.
2007-08-15 10:50:09 +00:00
Aryeh Gregor
a15c419b3d Remove ?>'s from files. They're pointless, and just asking for people to mess with the files and add trailing whitespace. (Yes, I looked over every one and reverted those that were bogus. Slash-enter a million times in less worked well enough, although it was a bit mind-numbing.) 2007-06-29 01:19:14 +00:00
Tim Starling
5e5d1f684b * Allow the extension used for mime type detection to be different from the temporary file extension
* Fixed detection of script type from shell-style #! line
* When loading type info files, don't rely on $IP being the working directory
* Formatting
2007-06-18 06:33:48 +00:00
Nick Jenkins
bd23ec29c6 Doc tweaks:
* Seems like an opportune time to introduce "@addtogroup Media" documentation tags.
* Merge "@addtogroup Metadata" (used by Exif.php) into "@addtogroup Media".
* Few more moving comment blocks to above classes.
2007-04-24 06:53:31 +00:00
Nick Jenkins
e12bc95fda Tweak for E_STRICT warning "Undefined index: in includes/MimeMagic.php on line 267" on:
curl --silent --include --globoff -F 'f'='..' -F 'w'='1930' -F 'r'='\</rp></dt>' 'http://localhost/wiki/thumb.php'
(Only happens because E_STRICT seems to disable the @ error control operator)
2007-04-23 01:41:19 +00:00
Tim Starling
b15d8cffc4 * Introduced media handler modules for file-type specific operations: thumbnailing, img_metadata, capabilities, etc.
* Deprecated $wgUseImageResize, thumbnailing will be enabled unconditionally.
* Fixed interaction of page parameter to ImagePage with the HTML file cache
* Improved error reporting for image thumbnailing
* Fixed MIME type for SVG files, will be silently changed from image/svg to image/svg+xml after loading from the database.
* Workaround for djvutoxml bug #1704049 (poor performance). Use djvudump instead.
* Fixed odd behaviour in ImagePage on DjVu thumbnailing errors
* Improved error reporting for image thumbnailing
* Added sharpening option for ImageMagick thumbnailing
* Removed Image::selectPage(), added page parameters to getWidth() and getHeight(), deprecated Image::renderThumb() and Image::getThumbnail()
* Changed default contents of img_metadata to empty string instead of a:0:{}
* Moved responsibility for respecting $wgGenerateThumbnailOnParse from the UI to Image.php
2007-04-20 12:31:36 +00:00
Tim Starling
a7c8d93b7e * Fix extension of DJVU output
* Specify output type in ImageMagick SVG rendering command line
* Make some Image functions static, for the benefit of WebStore.
* Fixed SVG MIME type, will be image/svg+xml from now on with both accepted.
2007-03-31 17:15:00 +00:00
Nick Jenkins
f1fb0bc169 * Prevent E_STRICT error when '$wgDebugDumpSql = true', and a path has been defined for $wgDebugLogFile,
but $wgDebugLogFile does not exist yet: "filesize(): stat failed for sql-log.txt in includes/GlobalFunctions.php on line 219"
* Removing unused global $IP.
* Indentation of an if/else block.
* Trivial comment typo.
* Prevent PHP Fatal error: "Call to a member function getText() on a non-object in includes/SpecialListusers.php on line 46", 
  when opening a URL such as http://192.168.0.64/wiki/index.php/Special:Listusers?username=%22%27%3E 
  (i.e. when "Display users starting at:" username supplied in Special:Listusers is not a valid MediaWiki title).
* Fix HTML validation of protection form (i.e. when "action=protect").
2007-03-19 07:08:58 +00:00
Antoine Musso
c771fc9c96 Use Doxygen @addtogroup instead of phpdoc @package && @subpackage 2007-01-20 15:09:52 +00:00
Antoine Musso
b144fcb85d Rename constructors to __constructor 2007-01-20 13:34:31 +00:00
Nick Jenkins
784e69d028 For the "includes/" directory:
* removing unused local vars
* removing used global declarations
* adding FIXMEs against extract() calls and lines that seem to be using uninitialized variables
* adding some array() declarations.
2007-01-12 10:03:51 +00:00
Nick Jenkins
32fd94a8ce Prevent E_STRICT errors on file upload of the following type:
* Strict Standards: Undefined index: application/ogg in includes/MimeMagic.php on line 154
* Strict Standards: Undefined index: ogm in includes/MimeMagic.php on line 163
2007-01-12 05:44:25 +00:00
Nick Jenkins
14c53b728f Code housekeeping stuff (and barring any stuff-ups on my behalf, there should be no changes in behaviour whatsoever after this) -
* removing some unused global declarations.
* removing or commenting out or adding comments for unused local vars.
* Adding one or two local var declarations.
* Declaring $matches array passed to preg_match() / preg_match_all() as array() before using [not required, just have a slight preference for the explicitness].
* remove one or two pass-by-reference function declarations where the value is not modified.
* Adding some braces to if-else blocks.
* In Parser.php, stripstrate is now an object rather than an array as per r17820, so we no longer need ask for a reference to it (as in "$x =& $this->mStripState;"), and in fact it's probably just simpler to get rid of $x altogether.
* Moving some preg regexes from "" quoting to '' quoting to stop static analyzer whinging about bad escape sequences.

... up to "LinksUpdate.php" in the includes/ directory.
2006-11-23 08:25:56 +00:00
Tim Starling
3005679b0e * Removed lots of explicit require_once statements. The autoloader should theoretically be faster, because it always uses an absolute path, eliminating the need for a search, and it is never called unnecessarily. Absolute paths are also more robust in the face of odd configurations or usage patterns. Moved a few constants around to support this, they always have to be available before the method call.
* Deleted DatabaseMysql.php, no longer necessary, database classes are autoloaded. 
* Moved wfGetMimeMagic() to MimeMagic::singleton()
* Fixed a couple of __CLASS__.'::'.__FUNCTION__ things.
2006-10-03 13:00:52 +00:00
Greg Sabino Mullane
8e5cd7fde2 Typo. 2006-09-03 18:13:59 +00:00
Jens Frank
7f7e79022b (bug 6420) Render thumbnails for djvu images, show multipage preview on image page 2006-08-13 17:34:48 +00:00
Brion Vibber
228f96a905 * (bug 6131) Add type detection for DjVu files, allowing them to be uploaded
with validity checking and size detection. No inline thumbnailing yet,
  but could be added in the future.
2006-06-24 07:11:17 +00:00
Ævar Arnfjörð Bjarmason
a26d5a49d7 * s~\t+$~~ 2006-01-07 13:31:29 +00:00
Ævar Arnfjörð Bjarmason
7bbe971aec * s~ +$~~ 2006-01-07 13:09:30 +00:00
Ævar Arnfjörð Bjarmason
d8e90514ab * Documentation: @private => @access private 2006-01-07 12:48:44 +00:00
Tim Starling
4c5d2a12a4 Fix #2 for WMF vulnerability 2006-01-03 02:14:55 +00:00
Brion Vibber
95d571e34f Correction to fix for bug 3641: don't reject on all unrecognized files
which we happen to know an extension -> mime type mapping for. Just do
it for those which can be detected from content by getimagesize() for now.
2005-10-08 05:48:45 +00:00
Antoine Musso
157861bc31 fix some issues with phpdoc 2005-07-05 21:22:25 +00:00
Ævar Arnfjörð Bjarmason
27105c2129 * (bug 898) Mime type autodetection. 2005-05-21 07:46:17 +00:00