[Bug]: TypeError in ThemingDefaults::getColorPrimary() — preg_match() under PHP 8.4 on unset user primary_color

オープン 初心者向け
#66,249 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
77/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

apps/theming/lib/ThemingDefaults.php の196行目付近から始めます。ここでは getColorPrimary() がユーザーの primary_color を読み取り、preg_match() に渡します。ThemingDefaults 関連のテストと、getColorBackground() が同じ入力処理をしているかを確認してください。色が未設定の場合にエラーなくグローバルのデフォルト値にフォールバックすることを確認し、その後、関連する theming テストを実行してください。

索引モデルが issue の本文から書いたものです。

説明

34-feedback
⚠️ This issue respects the following points: ⚠️
Bug description

When accessing /apps/files/ (or any page initializing user capabilities/theming) under PHP 8.4+, Nextcloud crashes with a fatal TypeError (HTTP 500) if the logged-in user does not have a custom primary_color configured.

In apps/theming/lib/ThemingDefaults.php line 196-197:

$userPrimaryColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'primary_color');
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userPrimaryColor)) {
    return $userPrimaryColor;
}

Under PHP 8.4+, preg_match enforces strict types and no longer tolerates non-string types or certain uninitialized proxy representations from getValueString(), throwing:

TypeError: preg_match(): Argument #2 ($subject) must be of type string, string given at /var/www/html/apps/theming/lib/ThemingDefaults.php#197
Steps to reproduce
  1. Run Nextcloud Server 34.x on PHP 8.4 (e.g. official nextcloud:34.0.5 Apache Docker image).
  2. Log in as an admin or normal user who has never set a custom theming primary color.
  3. Access /apps/files/.
  4. The page fails with HTTP 500 Internal Server Error.
Expected behavior

Nextcloud should fall back gracefully to the global system primary color ($defaultColor) without throwing a fatal TypeError.

Nextcloud Server version

34

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.4

Web server

Apache (supported)

Database engine version

PostgreSQL

Is this bug present after an update or on a fresh install?

Updated from a MINOR version (ex. 32.0.1 to 32.0.2)

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?
  • Default user-backend (database)
Nextcloud Logs
{
  "reqId": "n6FAHxGdzIB0H4OyzO55",
  "level": 3,
  "time": "2026-11-04T03:10:52+00:00",
  "remoteAddr": "x.x.x.x",
  "user": "admin",
  "app": "index",
  "method": "GET",
  "url": "/apps/files/",
  "message": "preg_match(): Argument #2 ($subject) must be of type string, string given",
  "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Safari/605.1.15",
  "version": "34.0.5.1",
  "exception": {
    "Exception": "TypeError",
    "Message": "preg_match(): Argument #2 ($subject) must be of type string, string given",
    "Code": 0,
    "Trace": [
      {
        "function": "preg_match",
        "file": "/var/www/html/apps/theming/lib/ThemingDefaults.php",
        "line": 197,
        "args": ["/^\\#([0-9a-f]{3}|[0-9a-f]{6})$/i", ""]
      },
      {
        "file": "/var/www/html/apps/theming/lib/Capabilities.php",
        "line": 88,
        "function": "getColorPrimary",
        "class": "OCA\\Theming\\ThemingDefaults",
        "type": "->"
      },
      {
        "file": "/var/www/html/lib/private/CapabilitiesManager.php",
        "line": 60,
        "function": "getCapabilities",
        "class": "OCA\\Theming\\Capabilities",
        "type": "->"
      },
      {
        "file": "/var/www/html/lib/private/Template/JSConfigHelper.php",
        "line": 141,
        "function": "getCapabilities",
        "class": "OC\\CapabilitiesManager",
        "type": "->"
      },
      {
        "file": "/var/www/html/lib/private/TemplateLayout.php",
        "line": 251,
        "function": "getConfig",
        "class": "OC\\Template\\JSConfigHelper",
        "type": "->"
      },
      {
        "file": "/var/www/html/apps/files/lib/Controller/ViewController.php",
        "line": 202,
        "function": "dispatchTyped",
        "class": "OC\\EventDispatcher\\EventDispatcher",
        "type": "->"
      }
    ],
    "File": "/var/www/html/apps/theming/lib/ThemingDefaults.php",
    "Line": 197
  }
}
Suggested Fix

Add defensive type checks and explicit casting in apps/theming/lib/ThemingDefaults.php:

--- a/apps/theming/lib/ThemingDefaults.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -194,7 +194,7 @@ class ThemingDefaults extends \OC_Defaults {
 		// user-defined primary color
 		if (!empty($user)) {
 			$userPrimaryColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'primary_color');
-			if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userPrimaryColor)) {
+			if (!empty($userPrimaryColor) && is_string($userPrimaryColor) && preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', (string)$userPrimaryColor)) {
 				return $userPrimaryColor;
 			}
 		}

Similarly for getColorBackground() if applicable.

主要言語
PHP
スター
37.4k
フォーク
5.3k
平均マージ
2日 7時間
マージ済み PR(30日)
744

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nextcloud/server のほかの issue

nextcloud/server の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。