Topic on Extension talk:MsUpload

Receiving Error -200 after Upgrading PHP

5
Summary by Sophivorus

Issue seems to have been due to a regex bug in MediaWiki core, that was fixed in 1.35.2+

193.102.45.21 (talkcontribs)

Hello,

since I updated PHP version from 7.2.18 to 7.4.13 MsUpload throws an "Error -200" when tryíng to upload a file. The "normal" method via specialpage still works fine.

Mediawiki 1.30.1
PHP 7.4.13 (fpm-fcgi)
MariaDB 5.5.57-MariaDB
ICU 64.2
Elasticsearch 5.4.3
MsUpload 12.0 (badbdb1) 2. Jan. 2021, 06:50

The console says, that there is an error 500 from the server:


POST "/mediawiki/api.php" 500

                        "" !== n.responseType && "responseType"in h && (h.responseType = "json" !== n.responseType || u.can("return_response_type", "json") ? n.responseType : "text"),

                        m ? h.sendAsBinary ? h.sendAsBinary(r) : !function() {

                            for (var e = new Uint8Array(r.length), t = 0; t < r.length; t++)

                                e[t] = 255 & r.charCodeAt(t);

                            h.send(e.buffer)

                        }() : h.send(r), <===== here is the breakpoint

                        s.trigger("loadstart")

                    },

                    getStatus: function() {

                        try {

                            if (h)

                                return h.status

                        } catch (e) {}

                        return 0


I´ve already tried different Versions but with no success. When loading the "api.php" site there´s only mentioned that "tokens" are deprecated.


Have you any suggestions?

193.102.45.21 (talkcontribs)

I´ve done some additional "research" and in the php_error_log the following line occurs:


[22-Feb-2021 09:13:12 UTC] PHP Warning:  preg_replace(): Compilation failed: invalid range in character class at offset 4 in /mediawiki/includes/media/FormatMetadata.php on line 1859

this does NOT appear, when uploading a file via special:fileupload. Do you have any further suggestions? I´ve already tried a lot of different versions of MsUpload...


following the codesnippet from "FormatMetadata.php":


protected function sanitizeKeyForAPI( $key ) {

// drop all characters which are not valid in an XML tag name

// a bunch of non-ASCII letters would be valid but probably won't

// be used so we take the easy way

$key = preg_replace( '/[^a-zA-z0-9_:.-]/', '', $key );

// drop characters which are invalid at the first position

>>>>>>>>>>>$key = preg_replace( '/^[\d-.]+/', '', $key ); <<<<<<<<<<<<<<<======== this is line 1859

if ( $key == '' ) {

$key = '_';

}

// special case for an internal keyword

if ( $key == '_element' ) {

$key = 'element';

}

return $key;

}

138.40.68.56 (talkcontribs)

I had issues with line 1860 of ./includes/media/FormatMetadata.php:

$key = preg_replace( '/^[\d-.]+/', '', $key );

Had to escape the '-' so it becomes:

$key = preg_replace( '/^[\d\-.]+/', '', $key );

193.102.45.21 (talkcontribs)

Just tried it.. It Works!


Thank you VERY much for the tip! Could you explain what this exactly means, why does the "-" cause errors?

Sophivorus (talkcontribs)

It looks like in MediaWiki 1.35.2+ this issue was fixed.