Upgrade to 2.1: Error in StylesheetUIAssetMerger.php

Upgraded from 1.18 to 2.1 and managed to get the site and DB updated, but the CSS is not downloading properly.

I monitored the HTTP requests with an HTTP debugger, and instead of CSS, the response from that request contains a fragment of HTML with the following error message, plus some binary content (or what appears to be either binary or garbage text). The response is also large, more than 38k.

Here’s the error (I substituted “[my path]” for the specific path used):

Warning: substr_compare(): The start position cannot exceed initial string length in E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger\StylesheetUIAssetMerger.php on line 134

Backtrace -->

#0 Piwik\Error::errorHandler(…) called at [:]
#1 substr_compare(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger\StylesheetUIAssetMerger.php:134]
#2 Piwik\AssetManager\UIAssetMerger\StylesheetUIAssetMerger->countDirectoriesInPathToRoot(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger\StylesheetUIAssetMerger.php:100]
#3 Piwik\AssetManager\UIAssetMerger\StylesheetUIAssetMerger->rewriteCssPathsDirectives(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger\StylesheetUIAssetMerger.php:85]
#4 Piwik\AssetManager\UIAssetMerger\StylesheetUIAssetMerger->processFileContent(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger.php:111]
#5 Piwik\AssetManager\UIAssetMerger->concatenateAssets(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger.php:99]
#6 Piwik\AssetManager\UIAssetMerger->getConcatenatedAssets(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger\StylesheetUIAssetMerger.php:55]
#7 Piwik\AssetManager\UIAssetMerger\StylesheetUIAssetMerger->generateCacheBuster(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger.php:192]
#8 Piwik\AssetManager\UIAssetMerger->getCacheBusterValue(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger.php:155]
#9 Piwik\AssetManager\UIAssetMerger->isFileUpToDate(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger.php:143]
#10 Piwik\AssetManager\UIAssetMerger->shouldGenerate(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager\UIAssetMerger.php:51]
#11 Piwik\AssetManager\UIAssetMerger->generateFile(…) called at [E:\HostingSpaces[my path]\wwwroot\core\AssetManager.php:167]
#12 Piwik\AssetManager->getMergedStylesheet(…) called at [E:\HostingSpaces[my path]\wwwroot\plugins\Proxy\Controller.php:36]
#13 Piwik\Plugins\Proxy\Controller->getCss(…) called at [:]
#14 call_user_func_array(…) called at [E:\HostingSpaces[my path]\wwwroot\core\FrontController.php:521]
#15 Piwik\FrontController->doDispatch(…) called at [E:\HostingSpaces[my path]\wwwroot\core\FrontController.php:84]
#16 Piwik\FrontController->dispatch(…) called at [E:\HostingSpaces[my path]\wwwroot\core\dispatch.php:30]
#17 require_once(…) called at [E:\HostingSpaces[my path]\wwwroot\index.php:47]

Any suggestions for troubleshooting? I tried disabling the asset merging by adding the following to my config.ini.php:

[Debug]
disable_merged_assets = 1

and restarted the web site and app pool (IIS, hosted on a shared server at Arvixe) but it would appear that it’s still merging the assets.

Would appreciate any suggestions for fixing this, as without the styles, the site is completely unreadable.

Thanks!

thanks for the report, that’s a bug! I created a ticket at: Warning: substr_compare(): The start position cannot exceed initial string length · Issue #4948 · matomo-org/matomo · GitHub

and also committed a fix. Can you please try the fix and if you still have the problem please let me know!

Thanks for the suggested fix. I applied the fix to StylesheetUIAssetMerger.php, but it did not resolve the issue. The request:

GET /index.php?module=Proxy&action=getCss&cb=20935c5ad266478e3915995779f8d7a6 HTTP/1.1

now results in a 500 error. Here’s the full code for the function with the bugfix applied (in case I did something wrong…not strong in PHP):


    protected function countDirectoriesInPathToRoot($uiAsset)
    {
        $rootDirectory = realpath($uiAsset->getBaseDirectory());
        if ($rootDirectory != PATH_SEPARATOR
            && substr_compare($rootDirectory, PATH_SEPARATOR, -1)) {
            $rootDirectory .= PATH_SEPARATOR;
        }

        $rootDirectoryLen = strlen($rootDirectory);
        return $rootDirectoryLen;
    }


Is the code above how it should look post-bugfix?

Thanks!

Yes that’s the correct code. Surprising that you get error 500, that means usually a critical error.

First please try to upgrde to 2.2.0-b13 which maybe will fix the issue.

If you still see error 500 with 2.2.0-b13 then we would need the message found in the server error log
(which you can get by asking your webhost. alternatively they often make such error log visible via their web interface)