From f66a1c1bb99c09c175135065c98869b8a6adef41 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sun, 19 Jun 2011 21:38:58 +0000 Subject: [PATCH] (bug 29471) Exception thrown for files with invalid date in metadata MediaWiki doesn't handle BC dates nicely, so check for that. --- RELEASE-NOTES-1.19 | 1 + includes/media/FormatMetadata.php | 6 ++--- .../includes/media/FormatMetadataTest.php | 23 ++++++++++++++++++ .../includes/media/broken_exif_date.jpg | Bin 0 -> 3233 bytes 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/includes/media/FormatMetadataTest.php create mode 100644 tests/phpunit/includes/media/broken_exif_date.jpg diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 935f5fe5f3..a66aed07ef 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -107,6 +107,7 @@ production. * Do not try to group together a page creation and edit in the RSS feed of RC. * (bug 29342) Patrol preferences shouldn't be visible to users who don't have patrol permissions +* (bug 29471) Exception thrown for files with invalid date in metadata === API changes in 1.19 === * BREAKING CHANGE: action=watch now requires POST and token. diff --git a/includes/media/FormatMetadata.php b/includes/media/FormatMetadata.php index e830901623..47fc1adc2d 100644 --- a/includes/media/FormatMetadata.php +++ b/includes/media/FormatMetadata.php @@ -104,7 +104,7 @@ class FormatMetadata { $time = wfTimestamp( TS_MW, '1971:01:01 ' . $tags[$tag] ); // the 1971:01:01 is just a placeholder, and not shown to user. - if ( $time ) { + if ( $time && intval( $time ) > 0 ) { $tags[$tag] = $wgLang->time( $time ); } continue; @@ -234,7 +234,7 @@ class FormatMetadata { $val = wfMsg( 'exif-unknowndate' ); } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/D', $val ) ) { $time = wfTimestamp( TS_MW, $val ); - if ( $time ) { + if ( $time && intval( $time ) > 0 ) { $val = $wgLang->timeanddate( $time ); } } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d)$/D', $val ) ) { @@ -243,7 +243,7 @@ class FormatMetadata { . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' ); - if ( $time ) { + if ( $time && intval( $time ) > 0 ) { $val = $wgLang->date( $time ); } } diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php b/tests/phpunit/includes/media/FormatMetadataTest.php new file mode 100644 index 0000000000..98c8013e9b --- /dev/null +++ b/tests/phpunit/includes/media/FormatMetadataTest.php @@ -0,0 +1,23 @@ +formatMetadata(); + + // Find date exif entry + $this->assertArrayHasKey( 'visible', $meta ); + $dateIndex = null; + foreach ( $meta['visible'] as $i => $data ) { + if ( $data['id'] == 'exif-datetimeoriginal' ) { + $dateIndex = $i; + } + } + $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' ); + $this->assertEquals( '0000:01:00 00:02:27', + $meta['visible'][$dateIndex]['value'], + 'File with invalid date metadata (bug 29471)' ); + } +} \ No newline at end of file diff --git a/tests/phpunit/includes/media/broken_exif_date.jpg b/tests/phpunit/includes/media/broken_exif_date.jpg new file mode 100644 index 0000000000000000000000000000000000000000..82f62f5704e8c98a0239847a5cf2159b2fd6538e GIT binary patch literal 3233 zcmeHJYitx%6h3$Eymz+kwp%Fc)^4}OE~GXyvr8Wv36?%!Nj3r^qA?~^L`zHz^#Q(; zQWdJdwu8?`l4T1%_y>w2{!p;K_$Bq#)<3OJH2wfzD1X*-XJ=>H!VmGEp=ajie)r6| zXYY6JIVYPR&rddvhNS=?gO8K|ho}UHMM`a4g*Z#f zTzrg_14SLd2S^A68v}ewu5$4>i8(gtjTrV`4eh3gY2zT`U$_d-&z@f33x3ck(8<(+cs^O`wcxXe(ZdOc~vUCHexn4HyH+)x?v>s=A_XU zG2=-ip43|bst1OPXXknb_PKc5VASI=*x=yX0Wts*dgpc1)HAfmiR;VoF5W#v3O0nJ zFvPh&hb;nX;dETi^7Mx+-qjzm1lRt!CA#>eC3!KkWCx=&OL1@nvFh5NvL0n;V1eMq zvc)rFT(iXUljYplXR_4Ajk(IAA3By>=-H1H{1BD|BL$9_QUC`y$A)3*VO%m{oNMqb z*W$4;LV2yxE>^7DEJe2m&0RzL<+_!JPgJfyeYQT{(>I`~3l>%_ z3N5~-A+}^`Vp(%bYg@9Tv#Wd6>eQMWH{7)G=1sTUddHSKx88Mk@3#Byf8fC#J0E)Z z@h6_#y=U;Lr>(uuJp0`9FT6OM8#!?Bfzn~IlnN!oR7f&F#