Page MenuHomePhabricator

"Import failed: XML error at line 1: Validation failed: no DTD found !" on PHP 8.2 when tideways_xhprof is enabled
Closed, ResolvedPublic

Description

PHP 8.2.3 on my dev wiki

Using Special:Import gives Import failed: XML error at line 1: Validation failed: no DTD found !

Not sure if it's a bad export or a problematic import..

"Import from another wiki" similarly broken...

Event Timeline

Seems to be fine on PHP 8.1.16, so PHP 8.2.3 issue...?

Seems to be caused by rMW771219475e11: import: Add a syntax check for xml imports by @Umherirrender.

Top of the backtrace...

/var/www/wiki/mediawiki/core/includes/specials/SpecialImport.php:244:
object(MWException)[999]
  protected 'message' => string 'XML error at line 1: Validation failed: no DTD found !' (length=54)
  private string 'string' (Exception) => string '' (length=0)
  protected 'code' => int 0
  protected string 'file' => string '/var/www/wiki/mediawiki/core/includes/import/WikiImporter.php' (length=61)
  protected int 'line' => int 1372
  private array 'trace' (Exception) => 
    array (size=10)
      0 => 
        array (size=5)
          'file' => string '/var/www/wiki/mediawiki/core/includes/import/WikiImporter.php' (length=61)
          'line' => int 694
          'function' => string 'syntaxCheckXML' (length=14)
          'class' => string 'WikiImporter' (length=12)
          'type' => string '->' (length=2)
      1 => 
        array (size=5)
          'file' => string '/var/www/wiki/mediawiki/core/includes/specials/SpecialImport.php' (length=64)
          'line' => int 239
          'function' => string 'doImport' (length=8)
          'class' => string 'WikiImporter' (length=12)
          'type' => string '->' (length=2)
      2 => 
        array (size=5)
          'file' => string '/var/www/wiki/mediawiki/core/includes/specials/SpecialImport.php' (length=64)
          'line' => int 112
          'function' => string 'doImport' (length=8)
          'class' => string 'SpecialImport' (length=13)
          'type' => string '->' (length=2)
      3 => 
        array (size=5)
          'file' => string '/var/www/wiki/mediawiki/core/includes/specialpage/SpecialPage.php' (length=65)
          'line' => int 700
          'function' => string 'execute' (length=7)
          'class' => string 'SpecialImport' (length=13)
          'type' => string '->' (length=2)
      4 => 
        array (size=5)
          'file' => string '/var/www/wiki/mediawiki/core/includes/specialpage/SpecialPageFactory.php' (length=72)
          'line' => int 1463
          'function' => string 'run' (length=3)
          'class' => string 'SpecialPage' (length=11)
          'type' => string '->' (length=2)
      5 => 
        array (size=5)
          'file' => string '/var/www/wiki/mediawiki/core/includes/MediaWiki.php' (length=51)
          'line' => int 324
          'function' => string 'executePath' (length=11)
          'class' => string 'MediaWiki\SpecialPage\SpecialPageFactory' (length=40)
          'type' => string '->' (length=2)
      6 => 
        array (size=5)
          'file' => string '/var/www/wiki/mediawiki/core/includes/MediaWiki.php' (length=51)
          'line' => int 917
          'function' => string 'performRequest' (length=14)
          'class' => string 'MediaWiki' (length=9)
          'type' => string '->' (length=2)
      7 => 
        array (size=5)
          'file' => string '/var/www/wiki/mediawiki/core/includes/MediaWiki.php' (length=51)
          'line' => int 573
          'function' => string 'main' (length=4)
          'class' => string 'MediaWiki' (length=9)
          'type' => string '->' (length=2)
      8 => 
        array (size=5)
          'file' => string '/var/www/wiki/mediawiki/core/index.php' (length=38)
          'line' => int 50
          'function' => string 'run' (length=3)
          'class' => string 'MediaWiki' (length=9)
          'type' => string '->' (length=2)
      9 => 
        array (size=3)
          'file' => string '/var/www/wiki/mediawiki/core/index.php' (length=38)
          'line' => int 46
          'function' => string 'wfIndexMain' (length=11)
  private ?Throwable 'previous' (Exception) => null
  public 'xdebug_message' => string '<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> MWException: XML error at line 1: Validation failed: no DTD found ! in /var/www/wiki/mediawiki/core/includes/import/WikiImporter.php on line <i>1372</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th'... (length=12300)

If I revert the commit, the import works...

@Reedy What version of ibxml2 is your PHP 8.2.16 using, compared to 8.1.16? Maybe something changed regarding entity loading between the two respective versions?

Seemingly the same...

reedy@ubuntu64-web-esxi:~$ php8.1 -a
Interactive shell

php > echo LIBXML_DOTTED_VERSION;
2.9.14
php > ^Dreedy@ubuntu64-web-esxi:~$ php8.2 -a
Interactive shell

php > echo LIBXML_DOTTED_VERSION;
2.9.14
php > ^Dreedy@ubuntu64-web-esxi:~$ php8.0 -a
Interactive mode enabled

php > echo LIBXML_DOTTED_VERSION;
2.9.14

Guess it's in the php innards then, somewhere in xmlreader and friends...

I will also note that I don't remember if I've tried an XML import to my dev wiki since I switched it to PHP 8.2; so it's possible this may have been the case since 8.2.0, or it could be new in 8.2.3.

  • The new code does not call XmlReader::isValid which is for validation against DTD or XSD
  • The new code is reading the xml and checking the structure of the tags, not validation.
  • The error message is not found in the php source, it seems it is generated by c or the os.
  • When running the provided file as part of the ImportFailureTest test with php8.2 it works for me.
  • When using the provided file via Special:Import it works for me with php8.2.3, but I am on windows, libxml is at 2.10.3
Reedy triaged this task as High priority.May 21 2023, 11:40 AM

Could do with deciding what to do about this... Revert out of 1.40, pending a fix in master?

Change 931710 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@master] Revert "import: Add a syntax check for xml imports"

https://gerrit.wikimedia.org/r/931710

Change 931711 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_40] Revert "import: Add a syntax check for xml imports"

https://gerrit.wikimedia.org/r/931711

PHP 8.2.7 seems to work fine for me now, even though no change in the major libxml version...

php > echo LIBXML_DOTTED_VERSION;
2.9.14
php >
ii  libxml2:amd64                         2.9.14+dfsg-0.1+ubuntu22.04.1+deb.sury.org+1                         amd64        GNOME XML library

It's entirely possible it was fixed between 8.2.3 being released and 8.2.7... Whether a PHP bug or a sury related packaging (dependant library) issue.

https://github.com/php/php-src/compare/php-8.2.3...php-8.2.7

Would be nice to know, especially if there's "good reason" we should add some versions less than 8.2.7 as a "known bad" version in PHPVersionCheck.

I suspect, though, as it's working on the latest patch release of the branch, there's no reason to actually merge the revert.

Change 931710 abandoned by Reedy:

[mediawiki/core@master] Revert "import: Add a syntax check for xml imports"

Reason:

PHP 8.2.3 didn't work, PHP 8.2.7 seems to...

https://gerrit.wikimedia.org/r/931710

Change 931711 abandoned by Reedy:

[mediawiki/core@REL1_40] Revert "import: Add a syntax check for xml imports"

Reason:

PHP 8.2.3 didn't work, PHP 8.2.7 seems to...

https://gerrit.wikimedia.org/r/931711

Reedy renamed this task from Import failed: XML error at line 1: Validation failed: no DTD found ! to "Import failed: XML error at line 1: Validation failed: no DTD found !" on PHP 8.2.3.Jun 24 2023, 2:06 PM
Reedy moved this task from Blocker to Not a blocker on the MW-1.40-release board.

I was able to reproduce this with the current php8.2 ondrej package (8.2.7).

The bug only occurs when tideways_xhprof is enabled.

I filed https://github.com/php/php-src/issues/11548

A workaround is to call XMLReader::open() statically.

Change 933699 had a related patch set uploaded (by Tim Starling; author: Tim Starling):

[mediawiki/core@master] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/933699

Aklapper renamed this task from "Import failed: XML error at line 1: Validation failed: no DTD found !" on PHP 8.2.3 to "Import failed: XML error at line 1: Validation failed: no DTD found !" on PHP 8.2 when tideways_xhprof is enabled.Jun 28 2023, 8:32 AM

Change 933699 merged by jenkins-bot:

[mediawiki/core@master] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/933699

Change 933644 had a related patch set uploaded (by Reedy; author: Tim Starling):

[mediawiki/core@REL1_40] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/933644

Change 933645 had a related patch set uploaded (by Reedy; author: Tim Starling):

[mediawiki/core@REL1_39] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/933645

Change 934006 had a related patch set uploaded (by Reedy; author: Tim Starling):

[mediawiki/core@REL1_38] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/934006

Change 934007 had a related patch set uploaded (by Reedy; author: Tim Starling):

[mediawiki/core@REL1_35] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/934007

Change 933644 merged by jenkins-bot:

[mediawiki/core@REL1_40] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/933644

Change 934007 merged by jenkins-bot:

[mediawiki/core@REL1_35] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/934007

Change 934006 merged by jenkins-bot:

[mediawiki/core@REL1_38] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/934006

Change 933645 merged by jenkins-bot:

[mediawiki/core@REL1_39] Work around argument corruption bug in XMLReader::open

https://gerrit.wikimedia.org/r/933645

Reedy assigned this task to tstarling.

Thanks Tim!