Reduced test case:
[subbu@earth:~/work/wmf/parsoid] cat /tmp/wt *<div>{{1x| *c }}</div>d [subbu@earth:~/work/wmf/parsoid] php bin/parse.php --wt2wt < /tmp/wt *<div>{{1x| *c }}</div>dd [subbu@earth:~/work/wmf/parsoid] php bin/parse.php < /tmp/wt <ul about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"dsr":[0,24,0,0],"firstWikitextNode":"UL","pi":[[{"k":"1"}]]}' data-mw='{"parts":["*<div>",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"\n*c\n"}},"i":0}},"</div>d"]}'><li><div></div></li> <li>c<meta typeof="mw:Placeholder/StrippedTag"/></li></ul><span about="#mwt1"> </span><p data-parsoid='{"dsr":[24,24,0,0]}'>d</p>
The list has got offset [0,24] whereas it should be [0,23]. If that 'd' was a multi-byte character, then template wrapping would try to take a substring in the middle of the character causing it to trigger a UTF-8 error.
See below:
[subbu@earth:~/work/wmf/parsoid] cat /tmp/wt *<div>{{1x| *c }}</div>の [subbu@earth:~/work/wmf/parsoid] php bin/parse.php < /tmp/wt Wikimedia\Assert\InvariantException from line 224 of /home/subbu/work/wmf/parsoid/vendor/wikimedia/assert/src/Assert.php: Invariant failed: Bad UTF-8 at end of string (3 byte sequence) #0 /home/subbu/work/wmf/parsoid/src/Utils/PHPUtils.php(218): Wikimedia\Assert\Assert::invariant() #1 /home/subbu/work/wmf/parsoid/src/Wt2Html/PP/Processors/WrapTemplates.php(963): Wikimedia\Parsoid\Utils\PHPUtils::safeSubstr() #2 /home/subbu/work/wmf/parsoid/src/Wt2Html/PP/Processors/WrapTemplates.php(1226): Wikimedia\Parsoid\Wt2Html\PP\Processors\WrapTemplates::encapsulateTemplates() #3 /home/subbu/work/wmf/parsoid/src/Wt2Html/PP/Processors/WrapTemplates.php(1239): Wikimedia\Parsoid\Wt2Html\PP\Processors\WrapTemplates::wrapTemplatesInTree() #4 /home/subbu/work/wmf/parsoid/src/Wt2Html/DOMPostProcessor.php(158): Wikimedia\Parsoid\Wt2Html\PP\Processors\WrapTemplates->run() #5 /home/subbu/work/wmf/parsoid/src/Wt2Html/DOMPostProcessor.php(837): Wikimedia\Parsoid\Wt2Html\DOMPostProcessor->Wikimedia\Parsoid\Wt2Html\{closure}() #6 /home/subbu/work/wmf/parsoid/src/Wt2Html/DOMPostProcessor.php(887): Wikimedia\Parsoid\Wt2Html\DOMPostProcessor->doPostProcess() #7 /home/subbu/work/wmf/parsoid/src/Wt2Html/DOMPostProcessor.php(904): Wikimedia\Parsoid\Wt2Html\DOMPostProcessor->process() #8 /home/subbu/work/wmf/parsoid/src/Wt2Html/ParserPipeline.php(178): Wikimedia\Parsoid\Wt2Html\DOMPostProcessor->processChunkily() #9 /home/subbu/work/wmf/parsoid/src/Wt2Html/ParserPipelineFactory.php(310): Wikimedia\Parsoid\Wt2Html\ParserPipeline->parseChunkily() #10 /home/subbu/work/wmf/parsoid/src/Core/WikitextContentModelHandler.php(106): Wikimedia\Parsoid\Wt2Html\ParserPipelineFactory->parse() #11 /home/subbu/work/wmf/parsoid/src/Parsoid.php(162): Wikimedia\Parsoid\Core\WikitextContentModelHandler->toDOM() #12 /home/subbu/work/wmf/parsoid/src/Parsoid.php(194): Wikimedia\Parsoid\Parsoid->parseWikitext() #13 /home/subbu/work/wmf/parsoid/bin/parse.php(327): Wikimedia\Parsoid\Parsoid->wikitext2html() #14 /home/subbu/work/wmf/parsoid/bin/parse.php(584): Parse->wt2Html() #15 /home/subbu/work/wmf/parsoid/tools/doMaintenance.php(53): Parse->execute() #16 /home/subbu/work/wmf/parsoid/bin/parse.php(620): require_once('/home/subbu/wor...') #17 {main}
This is probably another source of UTF-8 production error logged in T269749: WrapTemplates: UTF-8 errors