From: Brian Wolff Date: Fri, 23 May 2014 00:00:21 +0000 (-0300) Subject: Make sure DjVu files do not attempt metadata extraction repeatedly X-Git-Tag: 1.31.0-rc.0~15604^2 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=4a3ee339e40e194b026e6b4da892827af7085b0c Make sure DjVu files do not attempt metadata extraction repeatedly If a file is broken, we don't want to spend time trying to find its metadata over and over again. Bug: 41090 Change-Id: Iad63b8942af99e1ec44530599a43ec1d6b2b8a62 --- diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php index 566efb2b6e..200d52651c 100644 --- a/includes/media/DjVu.php +++ b/includes/media/DjVu.php @@ -278,7 +278,14 @@ class DjVuHandler extends ImageHandler { $unser = unserialize( $metadata ); wfRestoreWarnings(); if ( is_array( $unser ) ) { - return $unser['xml']; + if ( isset( $unser['error'] ) ) { + return false; + } elseif ( isset( $unser['xml'] ) ) { + return $unser['xml']; + } else { + // Should never ever reach here. + throw new MWException( "Error unserializing DjVu metadata." ); + } } // unserialize failed. Guess it wasn't really serialized after all, @@ -364,7 +371,8 @@ class DjVuHandler extends ImageHandler { $xml = $this->getDjVuImage( $image, $path )->retrieveMetaData(); if ( $xml === false ) { - return false; + // Special value so that we don't repetitively try and decode a broken file. + return serialize( array( 'error' => 'Error extracting metadata' ) ); } else { return serialize( array( 'xml' => $xml ) ); } diff --git a/tests/phpunit/includes/media/DjVuTest.php b/tests/phpunit/includes/media/DjVuTest.php index 537c124d61..5657a5ac4f 100644 --- a/tests/phpunit/includes/media/DjVuTest.php +++ b/tests/phpunit/includes/media/DjVuTest.php @@ -64,7 +64,8 @@ class DjVuTest extends MediaWikiTestCase { } public function testInvalidFile() { - $this->assertFalse( + $this->assertEquals( + 'a:1:{s:5:"error";s:25:"Error extracting metadata";}', $this->handler->getMetadata( null, $this->filePath . '/README' ), 'Getting Metadata for an inexistent file should returns false' );