r72526 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72525‎ | r72526 | r72527 >
Date:10:43, 7 September 2010
Author:tstarling
Status:ok
Tags:
Comment:
* PagedTiffHandler update for core change r72525, fixes r72025.
* Removed the MIME type check per updated documentation on MediaHandler::verifyUpload(). If the user is stupid enough to do "$wgMediaHandlers['image/jpeg'] = 'PagedTiffHandler'" then they should rightly get errors, PagedTiffHandler shouldn't just let files of other types pass.
Modified paths:
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php
@@ -59,85 +59,75 @@
6060 * - identify-warnings
6161 * - check for running-identify-service
6262 */
63 - function verifyFileHook( $upload, $mime, &$error ) {
 63+ function verifyUpload( $fileName ) {
6464 global $wgTiffMaxEmbedFiles, $wgTiffMaxMetaSize, $wgMaxUploadSize,
6565 $wgTiffRejectOnError, $wgTiffRejectOnWarning, $wgTiffUseTiffReader,
6666 $wgTiffReaderPath, $wgTiffReaderCheckEofForJS;
6767
68 - $tempName = $upload->getTempPath();
69 - $saveName = $upload->getLocalFile()->getName();
70 -
71 - if ( $mime != "image/tiff" ) {
72 - # not a tiff file, do not check
73 - wfDebug( __METHOD__ . ": not a tiff file\n" );
74 - return true;
75 - }
76 -
7768 wfLoadExtensionMessages( 'PagedTiffHandler' );
 69+ $status = Status::newGood();
7870 if ( $wgTiffUseTiffReader ) {
79 - $tr = new TiffReader( $tempName );
 71+ $tr = new TiffReader( $fileName );
8072 $tr->check();
8173 if ( !$tr->isValidTiff() ) {
82 - $error = array( 'tiff_bad_file' );
83 - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" );
84 - return false;
 74+ wfDebug( __METHOD__ . ": bad file\n" );
 75+ $status->fatal( 'tiff_bad_file' );
 76+ } else {
 77+ if ( $tr->checkScriptAtEnd( $wgTiffReaderCheckEofForJS ) ) {
 78+ wfDebug( __METHOD__ . ": script detected\n" );
 79+ $status->fatal( 'tiff_script_detected' );
 80+ }
 81+ if ( !$tr->checkSize() ) {
 82+ wfDebug( __METHOD__ . ": size error\n" );
 83+ $status->fatal( 'tiff_size_error' );
 84+ }
8585 }
86 - if ( $tr->checkScriptAtEnd( $wgTiffReaderCheckEofForJS ) ) {
87 - $error = array( 'tiff_script_detected' );
88 - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" );
89 - return false;
90 - }
91 - if ( !$tr->checkSize() ) {
92 - $error = array( 'tiff_size_error' );
93 - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" );
94 - return false;
95 - }
9686 }
97 - $meta = self::getTiffImage( false, $tempName )->retrieveMetaData();
 87+ $meta = self::getTiffImage( false, $fileName )->retrieveMetaData();
9888 if ( !$meta ) {
99 - $error = array( 'tiff_out_of_service' );
100 - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" );
101 - return false;
102 - }
 89+ wfDebug( __METHOD__ . ": unable to retreive metadata\n" );
 90+ $status->fatal( 'tiff_out_of_service' );
 91+ } else {
 92+ $error = false;
 93+ $ok = self::verifyMetaData( $meta, $error );
10394
104 - $ok = self::verifyMetaData( $meta, $error, $saveName );
105 -
106 - if ( !$ok ) {
107 - wfDebug( __METHOD__ . ": file is ok ($saveName)\n" );
 95+ if ( !$ok ) {
 96+ call_user_func_array( array( $status, 'fatal' ), $error );
 97+ }
10898 }
10999
110 - return $ok;
 100+ return $status;
111101 }
112102
113 - static function verifyMetaData( $meta, &$error, $saveName = '' ) {
 103+ static function verifyMetaData( $meta, &$error ) {
114104 global $wgTiffMaxEmbedFiles, $wgTiffMaxMetaSize;
115105
116106 $errors = PagedTiffHandler::getMetadataErrors( $meta );
117107 if ( $errors ) {
118108 $error = array( 'tiff_bad_file', PagedTiffHandler::joinMessages( $errors ) );
119109
120 - wfDebug( __METHOD__ . ": {$error[0]} ($saveName) " . PagedTiffHandler::joinMessages( $errors, false ) . "\n" );
 110+ wfDebug( __METHOD__ . ": {$error[0]} " . PagedTiffHandler::joinMessages( $errors, false ) . "\n" );
121111 return false;
122112 }
123113
124114 if ( $meta['page_amount'] <= 0 || empty( $meta['page_data'] ) ) {
125115 $error = array( 'tiff_page_error', $meta['page_amount'] );
126 - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" );
 116+ wfDebug( __METHOD__ . ": {$error[0]}\n" );
127117 return false;
128118 }
129119 if ( $wgTiffMaxEmbedFiles && $meta['page_amount'] > $wgTiffMaxEmbedFiles ) {
130120 $error = array( 'tiff_too_much_embed_files', $meta['page_amount'], $wgTiffMaxEmbedFiles );
131 - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" );
 121+ wfDebug( __METHOD__ . ": {$error[0]}\n" );
132122 return false;
133123 }
134124 $len = strlen( serialize( $meta ) );
135125 if ( ( $len + 1 ) > $wgTiffMaxMetaSize ) {
136126 $error = array( 'tiff_too_much_meta', $len, $wgTiffMaxMetaSize );
137 - wfDebug( __METHOD__ . ": {$error[0]} ($saveName)\n" );
 127+ wfDebug( __METHOD__ . ": {$error[0]}\n" );
138128 return false;
139129 }
140130
141 - wfDebug( __METHOD__ . ": metadata is ok ($saveName)\n" );
 131+ wfDebug( __METHOD__ . ": metadata is ok\n" );
142132 return true;
143133 }
144134

Follow-up revisions

RevisionCommit summaryAuthorDate
r72705adoped test cases to interface changes introduced by r72526daniel09:46, 10 September 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r72025use file verification via MediaHandler interface. requires r72024 in core.daniel14:09, 31 August 2010
r72525Fixes for r72024:...tstarling10:38, 7 September 2010

Status & tagging log