jenkins-bot has submitted this change and it was merged.

Change subject: Make sure DjVu files do not attempt metadata extraction 
repeatedly
......................................................................


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
---
M includes/media/DjVu.php
M tests/phpunit/includes/media/DjVuTest.php
2 files changed, 12 insertions(+), 3 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php
index 566efb2..200d526 100644
--- a/includes/media/DjVu.php
+++ b/includes/media/DjVu.php
@@ -278,7 +278,14 @@
                $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 @@
 
                $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 537c124..5657a5a 100644
--- a/tests/phpunit/includes/media/DjVuTest.php
+++ b/tests/phpunit/includes/media/DjVuTest.php
@@ -64,7 +64,8 @@
        }
 
        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'
                );

-- 
To view, visit https://gerrit.wikimedia.org/r/134976
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iad63b8942af99e1ec44530599a43ec1d6b2b8a62
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <bawolff...@gmail.com>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Tpt <thoma...@hotmail.fr>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to