ImageHistoryPseudoPager: Protect against TimestampException from bad user input
authorJames D. Forrester <jforrester@wikimedia.org>
Mon, 24 Sep 2018 18:21:17 +0000 (11:21 -0700)
committerKrinkle <krinklemail@gmail.com>
Wed, 26 Sep 2018 00:32:07 +0000 (00:32 +0000)
Bug: T204796
Change-Id: I17455fef0d899c56ce10f0df0db3457d944e353d

includes/page/ImageHistoryPseudoPager.php

index 20bc614..799c33a 100644 (file)
@@ -18,6 +18,8 @@
  * @file
  */
 
+use Wikimedia\Timestamp\TimestampException;
+
 class ImageHistoryPseudoPager extends ReverseChronologicalPager {
        protected $preventClickjacking = false;
 
@@ -138,6 +140,14 @@ class ImageHistoryPseudoPager extends ReverseChronologicalPager {
                if ( !$this->mImg->exists() ) {
                        return;
                }
+               // Make sure the date (probably from user input) is valid; if not, drop it.
+               if ( $this->mOffset !== null ) {
+                       try {
+                               $sadlyWeCannotPassThisTimestampDownTheStack = $this->mDb->timestamp( $this->mOffset );
+                       } catch ( TimestampException $e ) {
+                               $this->mOffset = null;
+                       }
+               }
                $queryLimit = $this->mLimit + 1; // limit plus extra row
                if ( $this->mIsBackwards ) {
                        // Fetch the file history