[Bug]: Push::encodeNotif() can compute a negative subject budget → endless loop in Util::shortenMultibyteString(), PHP request hangs until max_execution_time

Ouverte
#67,099 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
67/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
php
Domaine
backend

Piste de recherche

Start by reading lib/Push.php around Push::encodeNotif() and the Util::shortenMultibyteString() behavior described in the issue. Check existing tests for push payload encoding and multibyte string shortening, then reproduce with a proxy push payload whose link is 95–127 characters. Done means the request terminates and the subject or link is adjusted so the encoded payload fits.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

0. Needs triage 34-feedback bug needs info
⚠️ 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

Versions

  • Nextcloud server: 34.0.6
  • notifications app:
  • activity app:
  • PHP:
  • Office: Nextcloud Office (richdocuments) with Collabora Online

Summary
Since the update to 34.0.6, some WOPI PutFile requests (saving a document in Nextcloud Office) hang until max_execution_time (3600 s) is reached. Collabora aborts the save after ~30 s, the file stays locked for one hour (subsequent saves return 423 Locked) and the user gets "Document changed in storage (size mismatch after a failed upload)".

Root cause (analysis)
In lib/Push.php, encodeNotif():

$maxDataLength = $maxLength - strlen((string)json_encode($data)) - 2;
$data['subject'] = Util::shortenMultibyteString($notification->getParsedSubject(), $maxDataLength);

$data now includes link if strlen($link) < 128. For proxy push $maxLength is < 240. With a link of ~95–127 characters (plus json_encode escaping every / as \/) the encoded $data can exceed $maxLength - 2, so $maxDataLength becomes negative.

OCP\Util::shortenMultibyteString() loops while ((strlen(json_encode($temp)) - 2) > $dataLength). With a negative $dataLength the condition is always true (even for an empty string), so the loop never terminates.

Evidence
The notification is triggered by the activity "file changed" notification created during PutFile. In our logs, every hanging PutFile matches an activity_notification (app files) created at the same second with a link length of 95–101 characters, and a PHP fatal "Maximum execution time of 3600 seconds exceeded at lib/public/Util.php#605" exactly 3600 s later. Notifications with link length 82 (budget still positive) and 157 (link omitted because ≥ 128) did not hang.

Steps to reproduce

Steps to reproduce

  1. Have a user with a device registered for proxy push.
  2. Trigger a notification for that user whose link is ~95–127 characters long (e.g. activity "file changed" on a file in a deeper folder, saved via Nextcloud Office).
  3. The request creating the notification hangs until max_execution_time.
Expected behavior

Expected
The subject is shortened (or the link dropped) so the payload fits; the request never hangs.
Expected
The subject is shortened (or the link dropped) so the payload fits; the request never hangs.

Workaround we applied (local hotfix)
Directly after the budget calculation:

if ($maxDataLength < 20 && isset($data['link'])) {
    unset($data['link']);
    $maxDataLength = $maxLength - strlen((string)json_encode($data)) - 2;
}
$maxDataLength = max(0, $maxDataLength);

Additionally, Util::shortenMultibyteString() should probably guard against $dataLength < 0 itself.

Nextcloud Server version

34

Operating system

Debian/Ubuntu

PHP engine version

PHP 8.5

Web server

Nginx

Database engine version

MySQL

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)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report
{
    "system": {
        "htaccess.RewriteBase": "\/",
        "overwrite.cli.url": "https:\/\/nextcloud.XX.de",
        "overwritehost": "nextcloud.XX.de",
        "default_language": "de_DE",
        "default_locale": "de_DE",
        "default_phone_region": "DE",
        "remember_login_cookie_lifetime": 1296000,
        "session_lifetime": 7200,
        "session_keepalive": true,
        "auto_logout": false,
        "allow_local_remote_servers": true,
        "loglevel": 3,
        "apps_paths": [
            {
                "path": "\/var\/www\/html\/apps",
                "url": "\/apps",
                "writable": false
            },
            {
                "path": "\/var\/www\/html\/custom_apps",
                "url": "\/custom_apps",
                "writable": true
            }
        ],
        "memcache.local": "\\OC\\Memcache\\APCu",
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "filelocking.enabled": "true",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "port": 6379
        },
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "onlyoffice": {
            "jwt_secret": "***REMOVED SENSITIVE VALUE***",
            "jwt_header": "Authorization",
            "verify_peer_off": true
        },
        "trusted_domains": [
            "nextcloud.XX.de",
            "XXXXapp.XX.de",
            "office.XX.de"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "tempdirectory": "\/var\/www\/tmp",
        "dbtype": "mysql",
        "version": "34.0.6.2",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "3306",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "ldapIgnoreNamingRules": false,
        "skeletondirectory": "\/var\/www\/html\/core\/.skel\/",
        "mail_smtpmode": "smtp",
        "mail_sendmailmode": "smtp",
        "mail_from_address": "***REMOVED SENSITIVE VALUE***",
        "mail_domain": "***REMOVED SENSITIVE VALUE***",
        "mail_smtphost": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpport": 22525,
        "maintenance": false,
        "maintenance_window_start": 1,
        "theme": "",
        "ebug": "true",
        "share_folder": "geteilte-Dateien",
        "filesystem_check_changes": 1,
        "updater.server.url": "***REMOVED SENSITIVE VALUE***",
        "app_install_overwrite": [],
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "serverid": "0",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "mail_smtpsecure": "",
        "mail_smtpauth": false
    }
}
List of activated Apps
Enabled:
  - activity: 7.0.0
  - admin_audit: 1.24.0
  - appointments: 2.9.0
  - appstore: 1.0.0
  - bruteforcesettings: 7.0.0
  - calendar: 6.7.0
  - circles: 34.0.0
  - cloud_federation_api: 1.18.0
  - comments: 1.24.0
  - contacts: 8.10.0
  - contactsinteraction: 1.15.0
  - dashboard: 7.14.0
  - dav: 1.40.0
  - deck: 1.18.7
  - federatedfilesharing: 1.24.0
  - federation: 1.24.0
  - files: 2.6.0
  - files_downloadlimit: 5.2.0
  - files_external: 1.26.0
  - files_linkeditor: 1.1.27
  - files_lock: 34.0.1
  - files_pdfviewer: 7.0.1
  - files_reminders: 1.7.0
  - files_sharing: 1.26.1
  - files_trashbin: 1.24.0
  - files_versions: 1.27.0
  - firstrunwizard: 7.0.0-dev.0
  - forms: 5.4.3
  - groupfolders: 22.0.6
  - guests: 4.10.1
  - logreader: 7.0.0
  - lookup_server_connector: 1.22.0
  - nextcloud_announcements: 6.0.0
  - notes: 6.1.1
  - notifications: 7.0.0-dev.1
  - notify_push: 1.4.2
  - oauth2: 1.22.0
  - office: 1.0.0
  - password_policy: 6.0.0-dev.0
  - photos: 7.0.0
  - polls: 9.3.0
  - privacy: 6.0.0-dev.1
  - XXXXdomainpolicy: 1.0.0
  - profile: 1.3.0
  - provisioning_api: 1.24.0
  - recommendations: 7.0.0
  - richdocuments: 11.1.3
  - serverinfo: 6.0.0
  - settings: 1.17.0
  - sharebymail: 1.24.0
  - spreed: 24.0.8
  - support: 6.0.0
  - survey_client: 6.0.0-dev.0
  - suspicious_login: 12.0.0-dev.0
  - systemtags: 1.24.0
  - tasks: 0.18.1
  - text: 8.0.1
  - theming: 2.9.0
  - twofactor_backupcodes: 1.23.0
  - twofactor_totp: 16.0.0
  - updatenotification: 1.24.0
  - user_status: 1.14.0
  - viewer: 7.0.0-dev.0
  - weather_status: 1.14.0
  - webhook_listeners: 1.6.0
  - workflowengine: 2.16.0
Disabled:
  - app_api: 34.0.0 (installed 34.0.0)
  - encryption: 2.22.0 (installed 2.15.0)
  - files_antivirus: 6.4.0 (installed 6.4.0)
  - integration_excalidraw: 3.1.1 (installed 3.1.1)
  - related_resources: 5.0.0-dev.0 (installed 1.0.3)
  - twofactor_nextcloud_notification: 8.0.0
  - user_ldap: 1.25.0 (installed 1.8.0)
  - whiteboard: 1.5.9 (installed 1.5.9)
Nextcloud Signing status
No errors have been found.
Nextcloud Logs

Additional info

Versions

  • Nextcloud server: 34.0.6
  • notifications app: 7.0.0-dev.1 (as shipped with 34.0.6)
  • activity app: 7.0.0
  • PHP: 8.5.13
  • Office: Nextcloud Office (richdocuments) with Collabora Online
Langage dominant
PHP
Étoiles
37.6k
Forks
5.4k
Merge moyen
1 j 13 h
PR mergées (30 j)
623

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de nextcloud/server

Toutes les issues de nextcloud/server

Issues similaires

Plus d'issues PHP

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.