Skip to content

[Bug]: TypeError in Sabre CorePlugin when handling public DAV HEAD range (master , stable32 and previous...) breaks fast PDF loading #57219

@hubimuc

Description

@hubimuc

⚠️ This issue respects the following points: ⚠️

Bug description

TypeError in Sabre CorePlugin when handling public DAV HEAD range (master, stable32 and previous) breaks fast PDF loading

relates my PR nextcloud/3rdparty#2241

Affected versions

  • stable32 (32.0.3.2) and earlier stable branches (stable31/stable30/...)
  • master (current)

Environment

  • Nextcloud: 32.0.3.2 (stable32)
  • PHP: PHP 8.3.28
  • Webserver: (apache/nginx)
  • Client: PDF viewer / curl

Steps to reproduce

Steps to reproduce

  1. Create a public share link for a single PDF file (not folder).
  2. Access the public DAV endpoint (e.g. viewer or HEAD request on /public.php/dav/files/<token>).
  3. Observe slow load and server log TypeError.

Expected behavior

Expected behavior

Public DAV HEAD/range requests should not throw; range support should work for efficient PDF streaming.

Nextcloud Server version

master

Operating system

None

PHP engine version

None

Web server

None

Database engine version

None

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

None

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

fails with master, stable32 and previous
see additional info...

Nextcloud Signing status

Technical information
=====================
The following list covers which files have failed the integrity check. Please read
the previous linked documentation to learn more about the errors and how to fix
them.

Results
=======
- files_mindmap
	- EXCEPTION
		- OC\IntegrityCheck\Exceptions\InvalidSignatureException
		- Certificate is not valid.

Raw output
==========
Array
(
    [files_mindmap] => Array
        (
            [EXCEPTION] => Array
                (
                    [class] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
                    [message] => Certificate is not valid.
                )

        )

)

Nextcloud Logs

Additional info

Actual behavior

stream_get_meta_data() is called with a string body ("") during HEAD, causing a TypeError and breaking range loading.

Log excerpt (stable32)

"app":"webdav","method":"HEAD","url":"/public.php/dav/files/<token>",
"message":"stream_get_meta_data(): Argument #1 ($stream) must be of type resource, string given",
"File":"/var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","Line":179

Log excerpt (master)

"app":"webdav","method":"HEAD","url":"/public.php/dav/files/<token>",
"message":"stream_get_meta_data(): Argument #1 ($stream) must be of type resource, string given",
"File":"/var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","Line":179

Analysis

CorePlugin::httpGet() sets $body = '' for HEAD but does not convert it to a stream. Later, range handling calls stream_get_meta_data($body) which fails on string bodies. This breaks range support used by PDF viewers, causing very slow loads.

Proposed fix

Convert string body to stream regardless of request method:

line 86++

if (is_string($body)) {
    $stream = fopen('php://temp', 'r+');
    fwrite($stream, $body);
    rewind($stream);
    $body = $stream;
}

This preserves range handling while avoiding the TypeError. Guarding stream_get_meta_data() with is_resource() in line 179 would avoid the crash but may skip proper range handling.

Behavior before/after patch

Before patch (stable32 / master)

curl -I -H "Range: bytes=0-1023" http://localhost:8080/public.php/dav/files/<token>
HTTP/1.1 500 Internal Server Error

After patch

curl -I -H "Range: bytes=0-1023" http://localhost:8080/public.php/dav/files/<token>
HTTP/1.1 206 Partial Content
Content-Range: bytes 0-1023/<filesize>
Content-Length: 1024

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions