Topic on Project:Support desk

Jump to navigation Jump to search


Summary by MarkAHershberger
Sandman616 (talkcontribs)

Hey MW Community,

I’ve got a problem with my new Mediawiki installation on my WindowsServer2016.

When I’m trying to insert a file with the build in MW tool, there is thrown an UploadStashBadPathException.

The correct Message is:

Could not store upload in the stash (UploadStashBadPathException): "Key "hereStandsTheKeyWhichDidn'tWor.k.tmp" is not in a proper format.".

I've googled around, but didn't find a solution. Uploads are enabled in the associated files and the extensions are also entered.

It runs over IIS 10.0 and got a MySQL 8.0 DB under it.

PHP version is 7.3.1 and the MW version is 1.31.1.

Hope you could help.


MarkAHershberger (talkcontribs)

Does enabling $wgShowExceptionDetails provide any more information about the error? A backtrace would probably be very helpful.

Sandman616 (talkcontribs)

Hi Mark,

unfortunately enabling $wgShowExceptionDetails not bring any more details. The error message I was posting above is the only info I could get..

Ciencia Al Poder (talkcontribs)

Check that $wgUploadDirectory is correctly set. Also try to upload a filename without special characters like apostrophes.

Sandman616 (talkcontribs)

Hi Ciencia,

sorry, I forgot to mention, that the $wgUploadDirectory is also set correctly and all my files that I want to upload haven’t special characters in it.. I've got still no luck...

Ciencia Al Poder (talkcontribs)

Can you post the real key instead of a hereStandsTheKeyWhichDidn'tWor.k.tmp? That would give more information, since the format of that string is exactly the issue here.

Sandman616 (talkcontribs)

I think the key name is not very helpful, because as far as I understand, it was generated together with a timestamp, so every time I start another upload, the key changes.

But I can give better information’s now. I have read the debug manual and had generated a Logfile.

This is the part, where the UploadStash failure happened:

UploadStash::stashFile stashing file at '...\Temp\php2F21.tmp'
[error] [add76eab3e626d15dc4f62d8] /mediawiki/api.php   ErrorException from line 249 of ...\mediawiki\includes\upload\UploadStash.php: PHP Warning: preg_match(): Compilation failed: invalid range in character class at offset 4
#0 [internal function]: MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 ...\mediawiki\includes\upload\UploadStash.php(249): preg_match(string, string)
#2 ...\mediawiki\includes\upload\UploadBase.php(1124): UploadStash->stashFile(string, string)
#3 ...\mediawiki\includes\upload\UploadFromChunks.php(124): UploadBase->doStashFile(User)
#4 ...\mediawiki\includes\upload\UploadBase.php(1070): UploadFromChunks->doStashFile(User)
#5 ...\mediawiki\includes\upload\UploadFromChunks.php(76): UploadBase->tryStashFile(User, boolean)
#6 ...\mediawiki\includes\api\ApiUpload.php(315): UploadFromChunks->tryStashFile(User, boolean)
#7 ...\mediawiki\includes\api\ApiUpload.php(212): ApiUpload->performStash(string)
#8 ...\mediawiki\includes\api\ApiUpload.php(132): ApiUpload->getChunkResult(array)
#9 ...\mediawiki\includes\api\ApiUpload.php(104): ApiUpload->getContextResult()
#10 ...\mediawiki\includes\api\ApiMain.php(1579): ApiUpload->execute()
#11 ...\mediawiki\includes\api\ApiMain.php(535): ApiMain->executeAction()
#12 ...\mediawiki\includes\api\ApiMain.php(506): ApiMain->executeActionWithErrorHandling()
#13 ...\mediawiki\api.php(94): ApiMain->execute()
#14 {main} (talkcontribs)

I haven't changed the UploadStash.php yet.

The KEY_FORMAT_REGEX is still '/^[\w-\.]+\.\w*$/'; and the $key is still in this Format:

$key = Wikimedia\base_convert( $sec . $usec, 10, 36 ) .
    Wikimedia\base_convert( mt_rand(), 10, 36 ) .
    $this->userId . '.' . $extension;

The failure happens at preg_match i think:

if ( !preg_match( self::KEY_FORMAT_REGEX, $key )) {
    throw new UploadStashBadPathException(
        wfMessage( 'uploadstash-bad-path-bad-format', $key )

The Filename would be test.txt or something like that.

But I didn't really understand the preg_match function, I think.

MarkAHershberger (talkcontribs)

Thanks for pasting the code. That regex looks really, really wonky to me.

The error you're getting (Compilation failed: invalid range in character class at offset 4) echos what I'm thinking: "What does the character range of 'all word characters' to 'a literal dot' mean?"

I just ran the following one-liner against php 5.6, php 7.2 and php 7.3:

 php -r '$file="a.bcd"; $key="/^[\w-\.]+\.\w*$/"; var_dump(preg_match($key, $file));'

php 5.6 and 7.2 ate it up and returned "int(1)".

php 7.3 balked:

 PHP Warning:  preg_match(): Compilation failed: invalid range in character class at offset 4 in Command line code on line 1
Clump (talkcontribs)

PHP used to recognize when - was used in a range specification in a character class, but was not actually a valid range operator and just treat it as a normal character in the class. Now it complains. Thus [\w-\.] is likely supposed to be equivalent to [\w\.-].

MarkAHershberger (talkcontribs)

On phabricator, @Umherirrender points out that this is already fixed in master and will be in 1.31.2.

Sandman616 (talkcontribs)

Ah yes, thank you very much!

I have finally upgrade the Mediawiki version to 1.32 and after a few other problems, which I could handle with, the core problem with the Regex format is solved :)

Thanks to all who had replied. Great community :)