nextcloud / files_antivirus

👾 Antivirus app for Nextcloud Files

Home Page:https://apps.nextcloud.com/apps/files_antivirus

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError Activity\Event::setObject(), null given, called in lib/Item.php on line 111

lars-sh opened this issue · comments

Steps to reproduce

Since some time now the antivirus app writes about 50 errors a day to our server logs.
We don't know, what might cause that type error, therefore there are no known steps to reproduce this problem for now.

Expected behaviour

No unexpected errors in the logs.

Actual behaviour

Unexpected error (see below log entry) in the logs.

Server configuration

Operating system: Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-80-generic x86_64)

Web server: Apache 2.4.41

Database: MariaDB 10.3.29

PHP version: 7.4.3

Nextcloud version: 21.0.3.1

Logs

Nextcloud log

{
	"reqId": "iG4DHkHbDccN370yJ9Ew",
	"level": 3,
	"time": "2021-07-23T20:51:39+00:00",
	"remoteAddr": "",
	"user": "--",
	"app": "core",
	"method": "",
	"url": "/cron.php",
	"message": {
		"Exception": "TypeError",
		"Message": "Argument 3 passed to OC\\Activity\\Event::setObject() must be of the type string, null given, called in /kirche/www/cloud/apps2/files_antivirus/lib/Item.php on line 111",
		"Code": 0,
		"Trace": [{
				"file": "/kirche/www/cloud/apps2/files_antivirus/lib/Item.php",
				"line": 111,
				"function": "setObject",
				"class": "OC\\Activity\\Event",
				"type": "->"
			}, {
				"file": "/kirche/www/cloud/apps2/files_antivirus/lib/Status.php",
				"line": 166,
				"function": "processInfected",
				"class": "OCA\\Files_Antivirus\\Item",
				"type": "->"
			}, {
				"file": "/kirche/www/cloud/apps2/files_antivirus/lib/BackgroundJob/BackgroundScanner.php",
				"line": 337,
				"function": "dispatch",
				"class": "OCA\\Files_Antivirus\\Status",
				"type": "->"
			}, {
				"file": "/kirche/www/cloud/apps2/files_antivirus/lib/BackgroundJob/BackgroundScanner.php",
				"line": 219,
				"function": "scanOneFile",
				"class": "OCA\\Files_Antivirus\\BackgroundJob\\BackgroundScanner",
				"type": "->"
			}, {
				"file": "/kirche/www/cloud/lib/private/BackgroundJob/Job.php",
				"line": 52,
				"function": "run",
				"class": "OCA\\Files_Antivirus\\BackgroundJob\\BackgroundScanner",
				"type": "->"
			}, {
				"file": "/kirche/www/cloud/lib/private/BackgroundJob/TimedJob.php",
				"line": 59,
				"function": "execute",
				"class": "OC\\BackgroundJob\\Job",
				"type": "->"
			}, {
				"file": "/kirche/www/cloud/cron.php",
				"line": 128,
				"function": "execute",
				"class": "OC\\BackgroundJob\\TimedJob",
				"type": "->"
			}
		],
		"File": "/kirche/www/cloud/lib/private/Activity/Event.php",
		"Line": 383,
		"CustomMessage": "Error while running background job (class: OCA\\Files_Antivirus\\BackgroundJob\\BackgroundScanner, arguments: )"
	},
	"userAgent": "--",
	"version": "21.0.3.1"
}

Thanks for your report 👍

I'm not sure how to reproduce this error but $path (that's the 3rd argument for setObject) can be null. Can you apply the patch below. It should fix the actual error and log the path that resolves to null. Please make sure to set the loglevel to 1 to log the message.

Index: lib/Item.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/Item.php b/lib/Item.php
--- a/lib/Item.php	(revision 86a47e75938470922c130098971efc2fdb11b46b)
+++ b/lib/Item.php	(date 1632772059571)
@@ -104,11 +104,15 @@
 		$userFolder = $this->rootFolder->getUserFolder($this->file->getOwner()->getUID());
 		$path = $userFolder->getRelativePath($this->file->getPath());
 
+		if ($path === null) {
+			$this->logger->notice('getRelativePath is null for "' . $this->file->getPath() . '"', ['app' => 'files_antivirus_199']);
+		}
+
 		$activity = $this->activityManager->generateEvent();
 		$activity->setApp(Application::APP_NAME)
 			->setSubject(Provider::SUBJECT_VIRUS_DETECTED_SCAN, [$status->getDetails()])
 			->setMessage($message)
-			->setObject('file', $this->file->getId(), $path)
+			->setObject('file', $this->file->getId(), $path ?? '')
 			->setAffectedUser($this->file->getOwner()->getUID())
 			->setType(Provider::TYPE_VIRUS_DETECTED);
 		$this->activityManager->publish($activity);

Thanks @kesselb, I should have been able to get closer to the problem itself on my own 🤦‍♂️
I'll head back once I have more information.

OK, here we go.

The log output is as follows. I just remove a specific internal portion to avoid it to be public.

getRelativePath is null for "/avagt/files/KG-Oldesloe/[...]/Trash" File: 489783 Account: admin Path: /avagt/files/KG-Oldesloe/[...]/Trash

And this is where that file should be found in the file system, including the ls output for additional information:

ls -al "/mnt/data/data/admin/files/KG Oldesloe/[...]/Trash"
-rw-r--r-- 1 www-data www-data 16521517 May  6  2018 '/mnt/data/data/admin/files/KG Oldesloe/[...]/Trash'

That does not seem to be wrong to me. And just to make it clear: There are other files with similar permissions in the same folder, that do not seem to raise that error.

I just had a look at the method getRelativePath and to me it seems, it fails at https://github.com/nextcloud/server/blob/67e6468b9e5a6fb30638158c7bd558307d5ff747/lib/private/Files/Node/Folder.php#L85 , right?