Add wfUnserialize() wrapper around unserialize to prevent E_NOTICE and use it in ExifBitmap.php. There are probably many more places that could use this. This should fix Platonides' problem at r90421, but also added a check for $wgShowExif to prevent the test from failing.
This commit is contained in:
parent
571916b64d
commit
c87574b7b4
4 changed files with 27 additions and 1 deletions
|
|
@ -3549,3 +3549,17 @@ function wfGetParserCacheStorage() {
|
|||
function wfRunHooks( $event, $args = array() ) {
|
||||
return Hooks::run( $event, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize a string to a PHP value without throwing E_NOTICE. Simply a
|
||||
* wrapper around unserialize()
|
||||
*
|
||||
* @param $data string The serialized string
|
||||
* @return mixed
|
||||
*/
|
||||
function wfUnserialize( $data ) {
|
||||
wfSuppressWarnings();
|
||||
$result = unserialize( $data );
|
||||
wfRestoreWarnings();
|
||||
return $result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class ExifBitmapHandler extends BitmapHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
$exif = unserialize( $metadata );
|
||||
$exif = wfUnserialize( $metadata );
|
||||
if ( !$exif ) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -879,6 +879,12 @@ class GlobalTest extends MediaWikiTestCase {
|
|||
// are less consistent.
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnserialize() {
|
||||
$this->assertEquals( '', wfUnserialize( 's:0:"";') );
|
||||
$this->assertEquals( false, wfUnserialize( '0' ),
|
||||
'Invalid input to unserialize()' );
|
||||
}
|
||||
|
||||
/* TODO: many more! */
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
<?php
|
||||
class FormatMetadataTest extends MediaWikiTestCase {
|
||||
public function testInvalidDate() {
|
||||
global $wgShowEXIF;
|
||||
if ( !$wgShowEXIF ) {
|
||||
$this->markTestIncomplete( "This test needs the exif extension." );
|
||||
}
|
||||
|
||||
$file = UnregisteredLocalFile::newFromPath( dirname( __FILE__ ) .
|
||||
'/broken_exif_date.jpg', 'image/jpeg' );
|
||||
|
||||
// Throws an error if bug hit
|
||||
$meta = $file->formatMetadata();
|
||||
$this->assertNotEquals( false, $meta, 'Valid metadata extracted' );
|
||||
|
||||
// Find date exif entry
|
||||
$this->assertArrayHasKey( 'visible', $meta );
|
||||
|
|
|
|||
Loading…
Reference in a new issue