r90421 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90420‎ | r90421 | r90422 >
Date:21:38, 19 June 2011
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
(bug 29471) Exception thrown for files with invalid date in metadata
MediaWiki doesn't handle BC dates nicely, so check for that.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/media/FormatMetadata.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/media/FormatMetadataTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/includes/media/broken_exif_date.jpg (added) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -107,6 +107,7 @@
108108 * Do not try to group together a page creation and edit in the RSS feed of RC.
109109 * (bug 29342) Patrol preferences shouldn't be visible to users who don't have
110110 patrol permissions
 111+* (bug 29471) Exception thrown for files with invalid date in metadata
111112
112113 === API changes in 1.19 ===
113114 * BREAKING CHANGE: action=watch now requires POST and token.
Index: trunk/phase3/tests/phpunit/includes/media/FormatMetadataTest.php
@@ -0,0 +1,23 @@
 2+<?php
 3+class FormatMetadataTest extends MediaWikiTestCase {
 4+ public function testInvalidDate() {
 5+ $file = UnregisteredLocalFile::newFromPath( dirname( __FILE__ ) .
 6+ '/broken_exif_date.jpg', 'image/jpeg' );
 7+
 8+ // Throws an error if bug hit
 9+ $meta = $file->formatMetadata();
 10+
 11+ // Find date exif entry
 12+ $this->assertArrayHasKey( 'visible', $meta );
 13+ $dateIndex = null;
 14+ foreach ( $meta['visible'] as $i => $data ) {
 15+ if ( $data['id'] == 'exif-datetimeoriginal' ) {
 16+ $dateIndex = $i;
 17+ }
 18+ }
 19+ $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' );
 20+ $this->assertEquals( '0000:01:00 00:02:27',
 21+ $meta['visible'][$dateIndex]['value'],
 22+ 'File with invalid date metadata (bug 29471)' );
 23+ }
 24+}
\ No newline at end of file
Property changes on: trunk/phase3/tests/phpunit/includes/media/FormatMetadataTest.php
___________________________________________________________________
Added: svn:eol-style
125 + native
Index: trunk/phase3/tests/phpunit/includes/media/broken_exif_date.jpg
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: trunk/phase3/tests/phpunit/includes/media/broken_exif_date.jpg
___________________________________________________________________
Added: svn:mime-type
226 + application/octet-stream
Index: trunk/phase3/includes/media/FormatMetadata.php
@@ -104,7 +104,7 @@
105105
106106 $time = wfTimestamp( TS_MW, '1971:01:01 ' . $tags[$tag] );
107107 // the 1971:01:01 is just a placeholder, and not shown to user.
108 - if ( $time ) {
 108+ if ( $time && intval( $time ) > 0 ) {
109109 $tags[$tag] = $wgLang->time( $time );
110110 }
111111 continue;
@@ -234,7 +234,7 @@
235235 $val = wfMsg( 'exif-unknowndate' );
236236 } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/D', $val ) ) {
237237 $time = wfTimestamp( TS_MW, $val );
238 - if ( $time ) {
 238+ if ( $time && intval( $time ) > 0 ) {
239239 $val = $wgLang->timeanddate( $time );
240240 }
241241 } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d)$/D', $val ) ) {
@@ -243,7 +243,7 @@
244244 . substr( $val, 5, 2 )
245245 . substr( $val, 8, 2 )
246246 . '000000' );
247 - if ( $time ) {
 247+ if ( $time && intval( $time ) > 0 ) {
248248 $val = $wgLang->date( $time );
249249 }
250250 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r90682Per CR on r86169, start adding unit tests for metadata extraction....bawolff23:25, 23 June 2011
r91106Add wfUnserialize() wrapper around unserialize to prevent E_NOTICE and use it...btongminh20:24, 29 June 2011

Comments

#Comment by 😂 (talk | contribs)   22:25, 19 June 2011

Please fix the svn:mime-type on broken_exif_date.jpg

#Comment by Platonides (talk | contribs)   15:19, 21 June 2011

This test fails for me:

1) FormatMetadataTest::testInvalidDate unserialize(): Error at offset 0 of 2 bytes

#Comment by Bryan (talk | contribs)   20:08, 29 June 2011

Probably because you don't have the exif extension enabled cf. r91071.

#Comment by Bryan (talk | contribs)   20:26, 29 June 2011
#Comment by Brion VIBBER (talk | contribs)   21:01, 29 June 2011

This appears to suppress the warning message; since it's using an explicit marker value to indicate that exif metadata is unavailable, it probably should detect it and not try to unserialize in the first place.

Actually getting an unserialize error on a real metadata blob would indicate some sort of problem that probably should be logged.

Status & tagging log