Skip to content

[Bug]: occ preview:generate-all yields Malformed state response from server #57275

@goforthanddie

Description

@goforthanddie

⚠️ This issue respects the following points: ⚠️

Bug description

Hi there,

first: thanks for all your effort :).

This might be related to #305 from the previewgenerator repository. But since the issue did not seem to have any further relevance and the advice was to post results here, I decided to post my findings here.

I was running occ preview:generate-all -vvv and at some point got an Icewind\SMB\Exception\Exception: "Malformed state response from server".

I narrowed the problem down to specific folders with a certain amount of subfolders and a certain amount of files. The check if a file ".nomedia" exists leads in those cases to the exception (none of my folders contains a ".nomedia" file). It should yield an "OCP\Files\NotFoundException". To circumvent using occ preview:generate-all -vvv every time, the following command can also be used to produce the error (I have tried to generalize the folder structure as far as possible):

www-data@387d966aeb93:~/html$ php occ preview:generate-all -vvv -p /samy/files/09iMAGES/12345678/12345678/1234/12345678901234567890/123456/.nomedia
2025-12-28T12:13:55+00:00 Specifications: [{"width":64,"height":64,"crop":true},{"width":256,"height":256,"crop":true},{"width":1024,"height":1024,"crop":true},{"width":64,"height":64,"crop":false,"mode":"fill"},{"width":256,"height":256,"crop":false,"mode":"fill"},{"width":1024,"height":1024,"crop":false,"mode":"fill"},{"width":-1,"height":64,"crop":false},{"width":-1,"height":256,"crop":false},{"width":-1,"height":1024,"crop":false},{"width":64,"height":-1,"crop":false},{"width":256,"height":-1,"crop":false},{"width":1024,"height":-1,"crop":false}]
2025-12-28T12:13:55+00:00
2025-12-28T12:13:55+00:00 In Parser.php line 156:
2025-12-28T12:13:55+00:00
2025-12-28T12:13:55+00:00   [Icewind\SMB\Exception\Exception]
2025-12-28T12:13:55+00:00   Malformed state response from server
2025-12-28T12:13:55+00:00
2025-12-28T12:13:55+00:00
2025-12-28T12:13:55+00:00 Exception trace:
2025-12-28T12:13:55+00:00   at /var/www/html/3rdparty/icewind/smb/src/Wrapped/Parser.php:156
2025-12-28T12:13:55+00:00  Icewind\SMB\Wrapped\Parser->parseStat() at /var/www/html/3rdparty/icewind/smb/src/Wrapped/Share.php:216
2025-12-28T12:13:55+00:00  Icewind\SMB\Wrapped\Share->stat() at /var/www/html/apps/files_external/lib/Lib/Storage/SMB.php:169
2025-12-28T12:13:55+00:00  OCA\Files_External\Lib\Storage\SMB->getFileInfo() at /var/www/html/apps/files_external/lib/Lib/Storage/SMB.php:645
2025-12-28T12:13:55+00:00  OCA\Files_External\Lib\Storage\SMB->file_exists() at /var/www/html/lib/private/Files/Storage/Wrapper/Wrapper.php:115
2025-12-28T12:13:55+00:00  OC\Files\Storage\Wrapper\Wrapper->file_exists() at /var/www/html/lib/private/Files/Storage/Wrapper/Wrapper.php:115
2025-12-28T12:13:55+00:00  OC\Files\Storage\Wrapper\Wrapper->file_exists() at n/a:n/a
2025-12-28T12:13:55+00:00  call_user_func_array() at /var/www/html/lib/private/Files/Storage/Wrapper/Availability.php:83
2025-12-28T12:13:55+00:00  OC\Files\Storage\Wrapper\Availability->handleAvailability() at /var/www/html/lib/private/Files/Storage/Wrapper/Availability.php:150
2025-12-28T12:13:55+00:00  OC\Files\Storage\Wrapper\Availability->file_exists() at /var/www/html/lib/private/Files/Storage/Wrapper/Wrapper.php:115
2025-12-28T12:13:55+00:00  OC\Files\Storage\Wrapper\Wrapper->file_exists() at /var/www/html/lib/private/Files/View.php:1383
2025-12-28T12:13:55+00:00  OC\Files\View->getCacheEntry() at /var/www/html/lib/private/Files/View.php:1424
2025-12-28T12:13:55+00:00  OC\Files\View->getFileInfo() at /var/www/html/lib/private/Files/Node/Root.php:178
2025-12-28T12:13:55+00:00  OC\Files\Node\Root->get() at /var/www/html/lib/private/Files/Node/Folder.php:108
2025-12-28T12:13:55+00:00  OC\Files\Node\Folder->get() at /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php:235
2025-12-28T12:13:55+00:00  OCA\PreviewGenerator\Command\Generate->generatePathPreviews() at /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php:185
2025-12-28T12:13:55+00:00  OCA\PreviewGenerator\Command\Generate->executeDefault() at /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php:124
2025-12-28T12:13:55+00:00  OCA\PreviewGenerator\Command\Generate->execute() at /var/www/html/3rdparty/symfony/console/Command/Command.php:326
2025-12-28T12:13:55+00:00  Symfony\Component\Console\Command\Command->run() at /var/www/html/3rdparty/symfony/console/Application.php:1078
2025-12-28T12:13:55+00:00  Symfony\Component\Console\Application->doRunCommand() at /var/www/html/3rdparty/symfony/console/Application.php:324
2025-12-28T12:13:55+00:00  Symfony\Component\Console\Application->doRun() at /var/www/html/3rdparty/symfony/console/Application.php:175
2025-12-28T12:13:55+00:00  Symfony\Component\Console\Application->run() at /var/www/html/lib/private/Console/Application.php:187
2025-12-28T12:13:55+00:00  OC\Console\Application->run() at /var/www/html/console.php:90
2025-12-28T12:13:55+00:00  require_once() at /var/www/html/occ:33
2025-12-28T12:13:55+00:00
2025-12-28T12:13:55+00:00 preview:generate-all [-p|--path [PATH]] [-w|--workers [WORKERS]] [--] [<user_id>...]
2025-12-28T12:13:55+00:00

The last folder "123456" contains exactly 51 files. If I remove one file, it works:

www-data@387d966aeb93:~/html$ php occ preview:generate-all -vvv -p /samy/files/09iMAGES/12345678/12345678/1234/12345678901234567890/123456/.nomedia
2025-12-28T12:22:14+00:00 Specifications: [{"width":64,"height":64,"crop":true},{"width":256,"height":256,"crop":true},{"width":1024,"height":1024,"crop":true},{"width":64,"height":64,"crop":false,"mode":"fill"},{"width":256,"height":256,"crop":false,"mode":"fill"},{"width":1024,"height":1024,"crop":false,"mode":"fill"},{"width":-1,"height":64,"crop":false},{"width":-1,"height":256,"crop":false},{"width":-1,"height":1024,"crop":false},{"width":64,"height":-1,"crop":false},{"width":256,"height":-1,"crop":false},{"width":1024,"height":-1,"crop":false}]
2025-12-28T12:22:15+00:00
2025-12-28T12:22:15+00:00 In Root.php line 182:
2025-12-28T12:22:15+00:00
2025-12-28T12:22:15+00:00   [OCP\Files\NotFoundException]
2025-12-28T12:22:15+00:00   /samy/files/09iMAGES/12345678/12345678/1234/12345678901234567890/123456/.nomedia
2025-12-28T12:22:15+00:00
2025-12-28T12:22:15+00:00
2025-12-28T12:22:15+00:00 Exception trace:
2025-12-28T12:22:15+00:00   at /var/www/html/lib/private/Files/Node/Root.php:182
2025-12-28T12:22:15+00:00  OC\Files\Node\Root->get() at /var/www/html/lib/private/Files/Node/Folder.php:108
2025-12-28T12:22:15+00:00  OC\Files\Node\Folder->get() at /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php:235
2025-12-28T12:22:15+00:00  OCA\PreviewGenerator\Command\Generate->generatePathPreviews() at /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php:185
2025-12-28T12:22:15+00:00  OCA\PreviewGenerator\Command\Generate->executeDefault() at /var/www/html/custom_apps/previewgenerator/lib/Command/Generate.php:124
2025-12-28T12:22:15+00:00  OCA\PreviewGenerator\Command\Generate->execute() at /var/www/html/3rdparty/symfony/console/Command/Command.php:326
2025-12-28T12:22:15+00:00  Symfony\Component\Console\Command\Command->run() at /var/www/html/3rdparty/symfony/console/Application.php:1078
2025-12-28T12:22:15+00:00  Symfony\Component\Console\Application->doRunCommand() at /var/www/html/3rdparty/symfony/console/Application.php:324
2025-12-28T12:22:15+00:00  Symfony\Component\Console\Application->doRun() at /var/www/html/3rdparty/symfony/console/Application.php:175
2025-12-28T12:22:15+00:00  Symfony\Component\Console\Application->run() at /var/www/html/lib/private/Console/Application.php:187
2025-12-28T12:22:15+00:00  OC\Console\Application->run() at /var/www/html/console.php:90
2025-12-28T12:22:15+00:00  require_once() at /var/www/html/occ:33
2025-12-28T12:22:15+00:00
2025-12-28T12:22:15+00:00 preview:generate-all [-p|--path [PATH]] [-w|--workers [WORKERS]] [--] [<user_id>...]
2025-12-28T12:22:15+00:00

It also works if any of the folder names is one character shorter, e.g.:

php occ preview:generate-all -vvv -p /samy/files/09iMAGES/12345678/12345678/1234/12345678901234567890/12345/.nomedia

or if calling it on a folder without content (234567)

php occ preview:generate-all -vvv -p /samy/files/09iMAGES/12345678/12345678/1234/12345678901234567890/234567/.nomedia.

I could narrow this down to the Icewind\SMB\Wrapped::stat function and more precisely the therein called Icewind\SMB\Wrapped::dir function and even more precisely the therein called $output = $this->execute('dir').

I have tried to manually reconstruct what is happening in the smbclient tool, but even with the provided environment variables for the proc_open command in the RawConnection.php I do not succeed in producing a faulty behavior of smbclient. What I could debug so far is that the Icewdind\SMB\Wrapped\Connection::read function does not return the prompt "smb:" after calling $this->execute('cd /') in Icewind\SMB\Wrapped::dir, which it does return for working paths. Also, I could see that the responses from calls to smbclient seem to be delayed by "one call". Meaning that after calling the dir command, for subsequent commands the corresponding response is read only after the next call which leads to the problem - in my opinion.

However, when exchanging the call $output = $this->execute('dir') with $output = $this->execute('dir ' . substr($escapedPath, 0, -1).'\*"'); and thus making it an explicit dir call on the content of the path, everything works. So this would be a solution, but I do not know what is actually breaking after the normal dir call.

While writing this I notice that the issue is likely with the 3rdparty library. If this issue would be better placed there I will be glad to post it there. I was just following the lead from the issue that I found to be similar to this one.

Thanks

Samy

Steps to reproduce

  1. Login to the docker container as user www-data using docker exec -itu www-data container_id /bin/bash
  2. Call php occ preview:generate-all -vvv -p /samy/files/09iMAGES/12345678/12345678/1234/12345678901234567890/123456/.nomedia (the file ".nomedia" should not exist)

Expected behavior

Should return an OCP\Files\NotFoundException.

Nextcloud Server version

32

Operating system

Debian/Ubuntu in a docker container

PHP engine version

PHP 8.3

Web server

Apache (supported)

Database engine version

MariaDB

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

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?

  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other

Configuration report

{
    "system": {
        "htaccess.RewriteBase": "\/",
        "memcache.local": "\\OC\\Memcache\\APCu",
        "filelocking.enabled": true,
        "memcache.distributed": "\\OC\\Memcache\\Redis",
        "memcache.locking": "\\OC\\Memcache\\Redis",
        "apps_paths": [
            {
                "path": "\/var\/www\/html\/apps",
                "url": "\/apps",
                "writable": false
            },
            {
                "path": "\/var\/www\/html\/custom_apps",
                "url": "\/custom_apps",
                "writable": true
            }
        ],
        "upgrade.disable-web": true,
        "instanceid": "***REMOVED SENSITIVE VALUE***",
        "passwordsalt": "***REMOVED SENSITIVE VALUE***",
        "secret": "***REMOVED SENSITIVE VALUE***",
        "trusted_domains": [
            "*",
            "*",
            "*"
        ],
        "datadirectory": "***REMOVED SENSITIVE VALUE***",
        "dbtype": "mysql",
        "version": "32.0.3.2",
        "overwrite.cli.url": "***REMOVED SENSITIVE VALUE***",
        "overwriteprotocol": "https",
        "dbname": "***REMOVED SENSITIVE VALUE***",
        "dbhost": "***REMOVED SENSITIVE VALUE***",
        "dbport": "",
        "dbtableprefix": "oc_",
        "mysql.utf8mb4": true,
        "dbuser": "***REMOVED SENSITIVE VALUE***",
        "dbpassword": "***REMOVED SENSITIVE VALUE***",
        "installed": true,
        "maintenance": false,
        "loglevel": 3,
        "maintenance_window_start": "1",
        "trusted_proxies": "***REMOVED SENSITIVE VALUE***",
        "default_phone_region": "DE",
        "redis": {
            "host": "***REMOVED SENSITIVE VALUE***",
            "password": "***REMOVED SENSITIVE VALUE***",
            "port": 6379
        },
        "enabledPreviewProviders": [
            "OC\\Preview\\Imaginary"
        ],
        "preview_imaginary_url": "***REMOVED SENSITIVE VALUE***",
        "preview_max_x": 1024,
        "preview_max_y": 1024
    }
}

List of activated Apps

Enabled:
  - activity: 5.0.0-dev.0
  - bruteforcesettings: 5.0.0-dev.0
  - calendar: 6.1.2
  - circles: 32.0.0
  - cloud_federation_api: 1.16.0
  - contacts: 8.1.2
  - contactsinteraction: 1.13.1
  - dashboard: 7.12.0
  - dav: 1.34.2
  - federatedfilesharing: 1.22.0
  - files: 2.4.0
  - files_downloadlimit: 5.0.0-dev.0
  - files_external: 1.24.0
  - files_pdfviewer: 5.0.0-dev.0
  - files_reminders: 1.5.0
  - files_sharing: 1.24.1
  - files_trashbin: 1.22.0
  - files_versions: 1.25.0
  - logreader: 5.0.0-dev.0
  - lookup_server_connector: 1.20.0
  - nextcloud_announcements: 4.0.0-dev.0
  - notifications: 5.0.0-dev.0
  - oauth2: 1.20.0
  - password_policy: 4.0.0-dev.0
  - passwords: 2025.12.21
  - photos: 5.0.0-dev.1
  - previewgenerator: 5.11.0
  - privacy: 4.0.0-dev.0
  - profile: 1.1.0
  - provisioning_api: 1.22.0
  - recommendations: 5.0.0-dev.0
  - related_resources: 3.0.0-dev.0
  - serverinfo: 4.0.0-dev.0
  - settings: 1.15.1
  - sharebymail: 1.22.0
  - support: 4.0.0-dev.0
  - text: 6.0.1
  - theming: 2.7.0
  - twofactor_backupcodes: 1.21.0
  - updatenotification: 1.22.0
  - user_status: 1.12.0
  - viewer: 5.0.0-dev.0
  - weather_status: 1.12.0
  - webhook_listeners: 1.3.0
  - workflowengine: 2.14.0
Disabled:
  - admin_audit: 1.22.0
  - app_api: 32.0.0 (installed 4.0.6)
  - comments: 1.22.0 (installed 1.20.1)
  - encryption: 2.20.0
  - federation: 1.22.0 (installed 1.20.0)
  - firstrunwizard: 5.0.0-dev.0 (installed 3.0.0)
  - survey_client: 4.0.0-dev.0 (installed 2.0.0)
  - suspicious_login: 10.0.0-dev.0
  - systemtags: 1.22.0 (installed 1.20.0)
  - twofactor_nextcloud_notification: 6.0.0-dev.0
  - twofactor_totp: 14.0.0
  - user_ldap: 1.23.0

Nextcloud Signing status

No errors have been found.

Nextcloud Logs

Additional info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triagePending check for reproducibility or if it fits our roadmapbug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions