SOLVED: Nextcloud Logs "Trying to access array offset on value of type null" Repeatedly

Yep, and I see that this problem is scheduled for resolution with the Nextcloud 19 Milestone (planned 5/21/20 release date)

Meanwhile (to keep my logfile activity at a sane level), does anyone know how to modify the PHP file in question to stop this error (for me it’s /usr/share/webapps/nextcloud/3rdparty/leafo/scssphp/src/Compiler.php line 5230).

Here’s the function, and line #5230 reads $end = (int) $args[2][1]; below:

protected function libStrSlice($args)
{
    if (isset($args[2]) && $args[2][1] == 0) {
        return static::$nullString;
    }

    $string = $this->coerceString($args[0]);
    $stringContent = $this->compileStringContent($string);

    $start = (int) $args[1][1];

    if ($start > 0) {
        $start--;
    }

    $end    = (int) $args[2][1];
    $length = $end < 0 ? $end + 1 : ($end > 0 ? $end - $start : $end);

    $string[2] = $length
        ? [substr($stringContent, $start, $length)]
        : [substr($stringContent, $start)];

    return $string;
}

I searched for a patch on github, but I didn’t find anything or this file and version

1 Like

I’d definitely like to know that as well. But sorry, @buzz, I do not have the solution here.

I’m no PHP expert, but changing the first line of that function into

if (isset($args[2]) && isset($args[2][1]) && $args[2][1] == 0) {

adds a null check to the $args[2][1] and seems to stop the message from appearing at my instance without any other effects (but how can you be sure in a source with 5000+ lines).

I can’t find this file in the Nextcloud repo on Github. Can someone tell me what this it belongs to so that I can run tests and submit a patch?

EDIT: never mind, found it: https://github.com/scssphp/scssphp

2 Likes

@WhyYes, Thank you! This fixed it for me.

I haven’t been able to find any untoward side effects, and my log file is no longer reporting this error. I really appreciate your solution, and I’m looking forward to the Nextcloud 19 release in May, when scssphp is moved to its new location.

Thank you again!

buzz

@WhyYes: While this looked like a solution yesterday, this morning, my log file is filled with these errors again.

I really appreciate your effort, though! :slight_smile:

I don’t have the time to learn PHP, or I would try to fix this myself. May 21st isn’t that far away, I suppose.

Hi @buzz, yes, you’re right, that’s what happens if I don’t test everthing :sweat_smile:

Anyway, the reason is that my addition only checks if $args[2][1] is set for the remainder of that if statement, so the rest of that ill-written function can still throw null pointers around. So another dirty hack without knowing any side effects would be to bail out at the top when either $args[2] or $args[2][1] isn’t set:

if (!isset($args[2]) || !isset($args[2][1])) {
     return static::$nullString;
}

Again, it seems to work for me, but use at your own peril. I really can’t be bothered to look into PHP testing, sorry.

Thank you. This works for me too.

The odd thing is, strsplice() has been fixed back in August in version 1.0.3. of scssphp (https://github.com/scssphp/scssphp/commit/05a5d11ea7f68c52fdb6a5ca35cf46613b608445), while Nextcloud still uses version 0.7.6 (see src/Version.php in your scssphp folder).

It would be interesting to know what prevents Nextcloud to use an update of this dependency.

It would be interesting to know what prevents Nextcloud to use an update of this dependency.

The odd thing is, strsplice() has been fixed back in August in version 1.0.3. of scssphp

1.0.4 is the version with the fix and also breaking the styling.

So no fix for NC19?! I hope @WhyYes fix won’t cause problems until v20. :slight_smile:

1 Like

Fair enough.

Hello, @WhyYes,

Thanks again for the effort, but after updating with your latest code, I now receive errors on two lines of code in Compiler.php, instead of the single line previously:

Trying to access array offset on value of type null at /usr/share/webapps/nextcloud/3rdparty/leafo/scssphp/src/Compiler.php#2887
Trying to access array offset on value of type null at /usr/share/webapps/nextcloud/3rdparty/leafo/scssphp/src/Compiler.php#2745

Again, thanks for the effort. It looks like this fix is now targeted for NC20, but I’m hoping for a NC19 backport at some point!

buzz

In my case it is one line flooding the php error log with

Trying to access array offset on value of type null at /var/www/nextcloud/3rdparty/leafo/scssphp/src/Compiler.php#5230

using NC 18.0.6 under ubuntu 18.04.4 with PHP 7.4.6

1 Like

I have exactly the same error and the same configuration as chrissi55.

1 Like

It is not working for me with NC 18.0.6, Fedora 32 Server Edition PHP 7.4.6
When I add the changes I get plenty of those errors:

[PHP] Error: Trying to access array offset on value of type int at /var/www/html/nextcloud/lib/private/Files/Node/Node.php#327

After updating Nextcloud, the collabora/code Docker image, and the Nextcloud Collabora app, I no longer have this problem.

Operating system: Linux 5.7.2-arch1-1 #1 SMP PREEMPT Wed, 10 Jun 2020 20:36:24 +0000 x86_64

Webserver: nginx/1.19.0 (fpm-fcgi)

Database: mysql 10.4.13

PHP version: 7.4.7

Modules loaded: Core, date, libxml, openssl, pcre, zlib, ctype, dom, fileinfo, filter, hash, json, mbstring, pcntl, SPL, PDO, apcu, posix, readline, Reflection, session, SimpleXML, standard, tokenizer, xml, xmlreader, xmlwriter, mysqlnd, cgi-fcgi, bcmath, bz2, curl, exif, ftp, gd, gettext, gmp, iconv, imap, intl, mysqli, pdo_mysql, pdo_sqlite, pspell, snmp, sockets, sqlite3, tidy, xmlrpc, xsl, zip, apc, Phar, geoip, igbinary, imagick, pam, redis, smbclient, libsmbclient, Zend OPcache

Nextcloud version: 19.0.0 - 19.0.0.12

Good luck!

buzz

1 Like

For NC 19 but not 18? Because in NC 18 I still have those messages.

Messages still seen by a lot on NC 18.0.7. Please apply fix to NC 18 as well. This is really annoying.

2 Likes

I have this in NC 19.0.3 - so not only NC18 issue.

1 Like

Same error to me after upgrading NC-18.0.10 to PHP-7.2 >> PHP-7.4.11 (HostEurope):

Trying to access array offset on value of type null at /is/htdocs/wp10xxxxxxxxxxxxx/ncw/3rdparty/leafo/scssphp/src/Compiler.php#5230

How to solve this issue?

Thx + regards!