Page MenuHomePhabricator

Percent in filename breaks thumbnails
Closed, ResolvedPublic

Description

Author: jelle.zijlstra

Description:
See https://secure.wikimedia.org/wikipedia/en/wiki/File:Ex_1%25_ample.jpg. Both of the thumbnails in the file history section do not show up. When I go to the URL of the first thumbnail (http://upload.wikimedia.org/wikipedia/en/thumb/d/db/Ex_1%25_ample.jpg/111px-Ex_1%25_ample.jpg) in my browser, I get the following error:

<blockquote>
Error generating thumbnail

Error creating thumbnail: convert: unable to open image `/mnt/thumbs/wikipedia/en/thumb/d/db/Ex_1%%_ample.jpg/111px-Ex_1%%_ample.jpg': @ error/blob.c/OpenBlob/2498.
</blockquote>

Something is wrong with URL decoding, causing the %25 in the URL to get converted to %% instead of %.

(This originally got reported on [[w:WP:VPT]] (https://secure.wikimedia.org/wikipedia/en/w/index.php?title=Wikipedia:Village_pump_%28technical%29&oldid=448818820#Broken_thumbnail); the problematic file was fixed by renaming it to a title that didn't contain the percent sign.)


Version: unspecified
Severity: normal

Details

Reference
bz30789

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 21 2014, 11:48 PM
bzimport set Reference to bz30789.
bzimport added a subscriber: Unknown Object (MLST).

Ok, so the good news is the bug isn't in thumb-handler.php etc. :)
Seems odd...

With this original URL:

http://upload.wikimedia.org/wikipedia/en/thumb/archive/d/db/20110906223017!Ex_1%25_ample.jpg/111px-Ex_1%25_ample.jpg

it should be getting run via the thumb-handler.php on the upload server's 404 handler:

http://svn.wikimedia.org/viewvc/mediawiki/trunk/tools/upload-scripts/thumb-handler.php?view=markup

which should end up fetching something like:

http://en.wikipedia.org/w/thumb.php?f=20110906223017!Ex_1%25_ample.jpg&width=111&archived=1

This gives the same error when we fetch it directly:

Error generating thumbnail

Error creating thumbnail: convert: unable to open image `/mnt/thumbs/wikipedia/en/thumb/archive/d/db/20110906223017!Ex_1%%_ample.jpg/111px-Ex_1%%_ample.jpg': @ error/blob.c/OpenBlob/2498.

Now, the '1%%' looks wrong -- it should be '1%' here.

So, the good news is:

  • it's not in thumb-handler.php (whew!) since it happens to direct thumb.php calls
  • it does the same for archived and current version files

And in fact I can reproduce it locally simply by uploading a local copy of 'Ex 1% ample.jpg' and trying to see the current-version page. This shows an error right there on the page.

r65467:

/**

  • Escape a string for ImageMagick's output filename. See
  • InterpretImageFilename() in magick/image.c.
	 */

function escapeMagickOutput( $path, $scene = false ) {

		$path = str_replace( '%', '%%', $path );
		return $this->escapeMagickPath( $path, $scene );

}

So... it seems to be doing this on purpose... perhaps that purpose has gone obsolete or something else is funky.

That was added in as a fix for bug 23148 -- originally more simply and only on the comment field.

r65467 later applied the same replacement to other fields including the destination filename, and another special replacement for the input filename.

Possibly this is wrong for the output filename?

Behavior seems to have changed -- if I compile ImageMagick 6.6.9 locally it goes ahead and processes the file, whereas the 6.6.2 that shipped with Ubuntu 11.04 complains about the %% form...

2011-01-10 6.6.7-1 Cristy <quetzlzacatenango@image...>

Bingo!

I've filed an RT ticket internally to request that our deployed ImageMagick get updated: http://rt.wikimedia.org/Ticket/Display.html?id=1444

jelle.zijlstra wrote:

Thanks for the investigation and for finding the solution.

*** This bug has been marked as a duplicate of bug 26233 ***

Bryan.TongMinh wrote:

Percents in file names are perhaps too funky too allow. There are so many things that can break with it; perhaps it is better to just disallow it totally.

jelle.zijlstra wrote:

That makes sense to me, but it would be problematic because there are actually quite a few files with percent signs in their filenames (e.g., http://commons.wikimedia.org/wiki/File:25%25.svg, http://commons.wikimedia.org/wiki/File:25%25.png). Those are either SVGs, which aren't affected by this bug, or PNGs so small that they don't get thumbnailed. I have no idea how many more there may be, since I can't find a way to search for them on-wiki (intitle:% doesn't work, and Googling inurl:%25 doesn't work either).

Gilles triaged this task as Unbreak Now! priority.Dec 4 2014, 10:10 AM
Gilles moved this task from Untriaged to Done on the Multimedia board.
Gilles lowered the priority of this task from Unbreak Now! to Needs Triage.Dec 4 2014, 11:23 AM