Page MenuHomePhabricator

PHP Notice: Undefined index: frameCount
Open, LowPublic

Description

I receive lots of errors like this everyday on my logs:

2017-08-14 22:12:17 (...) ErrorException from line 104 of .../mediawiki-1.29.0/includes/media/GIF.php: PHP Notice: Undefined index: frameCount
#0 .../mediawiki-1.29.0/includes/media/GIF.php(104): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 .../mediawiki-1.29.0/includes/media/Bitmap.php(180): GIFHandler->isAnimatedImage(LocalWikiDexFile)
#2 .../mediawiki-1.29.0/includes/media/TransformationalImageHandler.php(246): BitmapHandler->transformImageMagick(LocalWikiDexFile, array)
#3 .../mediawiki-1.29.0/includes/filerepo/file/File.php(1141): TransformationalImageHandler->doTransform(LocalWikiDexFile, string, string, array)
#4 .../mediawiki-1.29.0/includes/filerepo/file/File.php(1104): File->generateAndSaveThumb(TempFSFile, array, integer)
#5 .../mediawiki-1.29.0/thumb.php(432): File->transform(array, integer)
#6 .../mediawiki-1.29.0/includes/poolcounter/PoolCounterWorkViaCallback.php(69): {closure}()
#7 .../mediawiki-1.29.0/includes/poolcounter/PoolCounterWork.php(123): PoolCounterWorkViaCallback->doWork()
2017-08-14 22:50:48 (...)  ErrorException from line 93 of .../mediawiki-1.29.0/includes/media/PNG.php: PHP Notice: Undefined index: frameCount
#0 .../mediawiki-1.29.0/includes/media/PNG.php(93): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 .../mediawiki-1.29.0/includes/filerepo/file/File.php(619): PNGHandler->isAnimatedImage(LocalWikiDexFile)
#2 .../mediawiki-1.29.0/includes/page/ImagePage.php(566): File->canAnimateThumbIfAppropriate()
#3 .../mediawiki-1.29.0/includes/page/ImagePage.php(150): ImagePage->openShowImage()
#4 .../mediawiki-1.29.0/includes/actions/ViewAction.php(68): ImagePage->view()
#5 .../mediawiki-1.29.0/includes/MediaWiki.php(499): ViewAction->show()
#6 .../mediawiki-1.29.0/includes/MediaWiki.php(293): MediaWiki->performAction(ImagePage, Title)
#7 .../mediawiki-1.29.0/includes/MediaWiki.php(862): MediaWiki->performRequest()
#8 .../mediawiki-1.29.0/includes/MediaWiki.php(523): MediaWiki->main()
#9 .../mediawiki-1.29.0/index.php(43): MediaWiki->run()
#10 {main}

The wiki was migrated from an old MediaWiki 1.19. Maybe the image metadata needs to be refreshed, but there should be a sanity check that metadata contains the frameCount property.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
matmarex added a subscriber: matmarex.

What is a LocalWikiDexFile, and why are GIFHandler and PNGHandler trying to handle it? :o Perhaps you have some extension that isn't cooperating with MediaWiki right.

Regardless, adding an isset() check in GIFHandler::isAnimatedImage() and PNGHandler::isAnimatedImage() would probably be sensible anyway. I note that SvgHandler::isAnimatedImage() and WebPHandler::isAnimatedImage() both have such a check.

LocalWikiDexFile just extends LocalFile to add a cache buster to image URLs (/latest/(timestamp)/). The only relevant override is getUrlRel:

(doc comments removed)

class LocalWikiDexFile extends LocalFile {
	const VERSION = 101; // cache version

	// Copied from LocalFile to avoid self create a LocalFile class instead of a LocalWikiDexFile class
	static function newFromTitle( $title, $repo, $unused = null ) {
		return new self( $title, $repo );
	}

	// Copied from LocalFile to avoid self create a LocalFile class instead of a LocalWikiDexFile class
	static function newFromRow( $row, $repo ) {
		$title = Title::makeTitle( NS_FILE, $row->img_name );
		$file = new self( $title, $repo );
		$file->loadFromRow( $row );

		return $file;
	}

	// Copied from LocalFile to avoid self create a LocalFile class instead of a LocalWikiDexFile class
	static function newFromKey( $sha1, $repo, $timestamp = false ) {
		$dbr = $repo->getReplicaDB();

		$conds = [ 'img_sha1' => $sha1 ];
		if ( $timestamp ) {
			$conds['img_timestamp'] = $dbr->timestamp( $timestamp );
		}

		$row = $dbr->selectRow( 'image', self::selectFields(), $conds, __METHOD__ );
		if ( $row ) {
			return self::newFromRow( $row, $repo );
		} else {
			return false;
		}
	}

	function __construct( $title, $repo ) {
		$this->repoClass = 'LocalWikiDexRepo';
		parent::__construct( $title, $repo );
	}
	
	function getUrlRel() {
		return $this->getHashPath() . 'latest/' . $this->getTimestamp() . '/' . rawurlencode( $this->getName() );
	}
}

Aaand finally found it's not really a bug, because (without my extension) old files get metadata updated automatically when the file is accessed, and the property is there without causing those errors.

Sadly my overwrite of getUrlRel() was adding the extra stuff in the URL causing internal functions to not find the file to load the metadata. I am surprised by this, because the wiki works without problems since the first day, files and thumbnails get placed to where they belong, and such, but this was failing silently.

Ciencia_Al_Poder triaged this task as Low priority.

Errors are still popping in... Even if loading the file description page makes the database to reload the metadata and save it, the first time it gets loaded and converted the error gets logged.

I've finally run maintenance/refreshImageMetadata.php to avoid them. I though it would take a long time, but it was really fast.

Another thing is that it currently "fixes itself" the metadata information on page view, which is bad for T92357: Fix database master queries from HTTP GET/HEAD before active-active multi-dc. If someone fixes it, then errors will not stop from happening...

Another thing is that it currently "fixes itself" the metadata information on page view, which is bad for T92357: Fix database master queries from HTTP GET/HEAD before active-active multi-dc.

Reported as T179760