On https://www.mediawiki.org/wiki/Topic:U453n0lb207odpid, someone reported a test case that crashes Remex. Here is a slightly different test case:
<div><i><b>foo<b> <b>foo</i>
When run locally, I get this stack trace:
[535b3bb0d1bfa6a399c0f92d] [no req] RemexHtml\TreeBuilder\TreeBuilderError from line 304 of /home/subbu/work/wmf/mediawiki/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/CachingStack.php: RemexHtml\TreeBuilder\CachingStack::replace: cannot find old element in scope cache Backtrace: #0 /home/subbu/work/wmf/mediawiki/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/TreeBuilder.php(489): RemexHtml\TreeBuilder\CachingStack->replace(RemexHtml\TreeBuilder\Element, RemexHtml\TreeBuilder\Element) #1 /home/subbu/work/wmf/mediawiki/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InBody.php(621): RemexHtml\TreeBuilder\TreeBuilder->adoptionAgency(string, integer, integer) #2 /home/subbu/work/wmf/mediawiki/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/Dispatcher.php(392): RemexHtml\TreeBuilder\InBody->endTag(string, integer, integer) #3 /home/subbu/work/wmf/mediawiki/vendor/wikimedia/remex-html/RemexHtml/Tokenizer/Tokenizer.php(1305): RemexHtml\TreeBuilder\Dispatcher->endTag(string, integer, integer) #4 /home/subbu/work/wmf/mediawiki/vendor/wikimedia/remex-html/RemexHtml/Tokenizer/Tokenizer.php(488): RemexHtml\Tokenizer\Tokenizer->handleAttribsAndClose(integer, string, boolean, integer) #5 /home/subbu/work/wmf/mediawiki/vendor/wikimedia/remex-html/RemexHtml/Tokenizer/Tokenizer.php(310): RemexHtml\Tokenizer\Tokenizer->dataState(boolean) #6 /home/subbu/work/wmf/mediawiki/vendor/wikimedia/remex-html/RemexHtml/Tokenizer/Tokenizer.php(152): RemexHtml\Tokenizer\Tokenizer->executeInternal(boolean) #7 /home/subbu/work/wmf/mediawiki/includes/tidy/RemexDriver.php(53): RemexHtml\Tokenizer\Tokenizer->execute(array) #8 /home/subbu/work/wmf/mediawiki/includes/parser/MWTidy.php(52): MediaWiki\Tidy\RemexDriver->tidy(string) #9 /home/subbu/work/wmf/mediawiki/includes/parser/Parser.php(1381): MWTidy::tidy(string) #10 /home/subbu/work/wmf/mediawiki/includes/parser/Parser.php(454): Parser->internalParseHalfParsed(string, boolean, boolean) #11 /home/subbu/work/wmf/mediawiki/maintenance/parse.php(138): Parser->parse(string, Title, ParserOptions) #12 /home/subbu/work/wmf/mediawiki/maintenance/parse.php(85): CLIParser->parse(string) #13 /home/subbu/work/wmf/mediawiki/maintenance/parse.php(77): CLIParser->render(string) #14 /home/subbu/work/wmf/mediawiki/maintenance/doMaintenance.php(94): CLIParser->execute() #15 /home/subbu/work/wmf/mediawiki/maintenance/parse.php(144): require_once(string) #16 {main}
Relatedly, on itwiki, this oldid crashes: https://it.wikipedia.org/wiki/Discussioni_utente:Nicelotus~itwiki?oldid=72298949 which looks like an instance of the same crasher above.