[Bug]: Unified search returns HTTP 500 on PHP 8 when the `cursor` parameter is empty ("Unsupported operand types: string + int")

未关闭 适合新手
#66,623 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php
领域
backend

调研方向

五个崩溃位置已列在表格中:apps/files/lib/Search/FilesSearchProvider.php(约第 143 行)、apps/dav/lib/Search/ContactsSearchProvider.php、apps/dav/lib/Search/EventsSearchProvider.php、apps/dav/lib/Search/TasksSearchProvider.php 和 apps/systemtags/lib/Search/TagSearchProvider.php。先在提供者搜索接口上使用空的 cursor 复现 500 错误,然后找出每个提供者在哪里根据 getCursor() 计算下一个游标。完成标准是:每个提供者对空游标都返回 200,并且维护者已在各提供者自行转换与在 SearchQuery::getCursor() 中统一规范化之间作出选择。

由索引模型根据 Issue 内容生成。

描述

0. Needs triage 35-feedback bug
⚠️ This issue respects the following points: ⚠️
  • This is not a troubleshooting question, general support matter, or webserver/proxy problem, but likely a bug (if unsure, ask the Community Help Forum).
  • This issue is not already reported on Github OR solved at the Community Help Forum (I've searched!).
  • I'm using a maintained major version of Nextcloud Server and tested against the latest patch level. (Supported major versions and current patch levels).
  • I agree to follow Nextcloud's Code of Conduct.
  • I've tried my best to provide clear reproduction steps that someone unfamiliar with this bug could use to reproduce it.
Bug description

Unified search is completely broken on PHP 8: every search request returns HTTP 500 and the UI shows "No matches found" even when matching files exist.

Every search provider computes the next cursor as:

$query->getCursor() + <int>

When the web frontend sends an empty cursor query parameter (which it does on the first search), getCursor() returns an empty string. On PHP 8, '' + int throws a TypeError instead of coercing to 0 as PHP 7 did. The provider crashes, the OCS endpoint returns 500, and the frontend - which receives an error rather than an empty result set - renders "No matches found".

This affects five providers across three apps, so file, contacts, calendar, tasks and tag search all break at once. Because unified search queries every provider, a single failing one is enough to make the whole search look empty.

File Line Code
apps/files/lib/Search/FilesSearchProvider.php 143 $query->getCursor() + $query->getLimit()
apps/dav/lib/Search/ContactsSearchProvider.php 130 $query->getCursor() + count($formattedResults)
apps/dav/lib/Search/EventsSearchProvider.php 207 $query->getCursor() + count($uniqueResults)
apps/dav/lib/Search/TasksSearchProvider.php 139 $query->getCursor() + count($searchResults)
apps/systemtags/lib/Search/TagSearchProvider.php 149 $query->getCursor() + $query->getLimit()
Steps to reproduce
  1. Run Nextcloud 35.x on PHP 8 (reproduced on PHP 8.5.4).
  2. Log in to the web UI and open the Files app.
  3. Type into the unified search bar any term matching an existing file.
  4. The dropdown shows "No matches found" even though the file exists.
  5. The browser console shows: unified-search: Unexpected AxiosError "Request failed with status code 500".

The failure can be isolated with direct requests. The empty cursor is the only variable that changes between 200 and 500:

# 200, returns results:
/ocs/v2.php/search/providers/files/search?term=<term>&from=%2Fapps%2Ffiles%2Ffiles

# 200, returns results:
/ocs/v2.php/search/providers/files/search?term=<term>&from=%2Fapps%2Ffiles%2Ffiles&cursor=0

# 500:
/ocs/v2.php/search/providers/files/search?term=<term>&from=%2Fapps%2Ffiles%2Ffiles&cursor=
Expected behavior

An empty cursor should be treated as "no cursor" (i.e. 0) and the search should return results normally, as it did on PHP 7.

Actual behaviour: the provider throws, the endpoint returns HTTP 500, and the UI reports no matches.

Nextcloud Server version

35

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.5

Web server

Apache (supported)

Database engine version

MariaDB

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

Upgraded to a MAJOR version (ex. 31 to 32)

Are you using the Nextcloud Server Encryption module?

Encryption is Disabled

What user-backends are you using?
  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report

List of activated Apps

Nextcloud Signing status

Nextcloud Logs
Exception: Unsupported operand types: string + int in file
'/var/www/html/apps/dav/lib/Search/EventsSearchProvider.php' line 207

URL: /ocs/v2.php/search/providers/calendar/search?term=<term>&from=%2Fapps%2Ffiles%2Ffiles&cursor=

The same exception is raised by each affected provider at the line listed in the description.
Additional info
Suggested fix

Cast the cursor before the addition, so an empty value becomes 0:

(int)$query->getCursor() + $query->getLimit()

Applying that one-line change to the five files listed above restores unified search completely. Verified locally: all nine registered providers return HTTP 200 afterwards, including with &cursor= empty.

A more central alternative would be to normalise the value in SearchQuery::getCursor() itself, or when the OCS controller parses the request, so providers never receive an empty string.

Notes
  • The regression is invisible on PHP 7, where '' + int evaluates to the integer with only a notice. It only surfaces once the server runs PHP 8, which makes it easy to miss and hard for users to attribute: the search simply looks like it finds nothing.
  • Reproduced on 35.0.2 and again on 35.0.3. The 35.0.3 update overwrote a local patch and the bug returned, so the affected code is unchanged between those releases.
App versions of the affected apps
  • files: 3.0.0
  • dav: 2.0.1
  • systemtags: 2.0.0
主要语言
PHP
星标
37.5k
派生
5.4k
平均合并
1 天 14 小时
30 天内合并 PR
648

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nextcloud/server 的其他 Issue

查看 nextcloud/server 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。