From: Bartosz DziewoƄski Date: Fri, 26 Aug 2016 13:22:09 +0000 (+0200) Subject: ApiUpload: Better handle unreasonably large metadata in 'imageinfo' X-Git-Tag: 1.31.0-rc.0~5874^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=13d2035cbbf3ee74fe2b301148eae993c86cd7e3;p=lhc%2Fweb%2Fwiklou.git ApiUpload: Better handle unreasonably large metadata in 'imageinfo' Bug: T143993 Change-Id: I1fcdbca9981dd034572eeb32070d574cf97a132f --- diff --git a/includes/api/ApiUpload.php b/includes/api/ApiUpload.php index f7ce55214e..54d3c3c30b 100644 --- a/includes/api/ApiUpload.php +++ b/includes/api/ApiUpload.php @@ -109,16 +109,19 @@ class ApiUpload extends ApiBase { // Get the result based on the current upload context: try { $result = $this->getContextResult(); - if ( $result['result'] === 'Success' ) { - $result['imageinfo'] = $this->mUpload->getImageInfo( $this->getResult() ); - } } catch ( UploadStashException $e ) { // XXX: don't spam exception log list( $msg, $code ) = $this->handleStashException( get_class( $e ), $e->getMessage() ); $this->dieUsage( $msg, $code ); } - $this->getResult()->addValue( null, $this->getModuleName(), $result ); + // Add 'imageinfo' in a separate addValue() call. File metadata can be unreasonably large, + // so otherwise when it exceeded $wgAPIMaxResultSize, no result would be returned (T143993). + if ( $result['result'] === 'Success' ) { + $imageinfo = $this->mUpload->getImageInfo( $this->getResult() ); + $this->getResult()->addValue( $this->getModuleName(), 'imageinfo', $imageinfo ); + } + // Cleanup any temporary mess $this->mUpload->cleanupTempFile(); } @@ -445,7 +448,18 @@ class ApiUpload extends ApiBase { } } unset( $progress['status'] ); // remove Status object + $imageinfo = null; + if ( isset( $progress['imageinfo'] ) ) { + $imageinfo = $progress['imageinfo']; + unset( $progress['imageinfo'] ); + } + $this->getResult()->addValue( null, $this->getModuleName(), $progress ); + // Add 'imageinfo' in a separate addValue() call. File metadata can be unreasonably large, + // so otherwise when it exceeded $wgAPIMaxResultSize, no result would be returned (T143993). + if ( $imageinfo ) { + $this->getResult()->addValue( $this->getModuleName(), 'imageinfo', $imageinfo ); + } return false; }