Skip to content

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

Open

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

Activity

  1. added
    0. Needs triage
    on Dec 21, 2025
  2. added theissue type on Dec 21, 2025
  3. hubimuc commented on Dec 28, 2025

    @hubimuc
    Author

    Please refer to issue: sabre-io/dav#1618

  4. Kalle2018 commented on Jun 5, 2026

    @Kalle2018

    Please look at this thread:
    https://help.nextcloud.com/t/typeerror-desktop-version/232197

    Why is the Bug not fixed?

    The user "transdata" write there:

    I got it! I’m just surprised that not everyone has this problem. In /3rdparty/sabre/dav/lib/DAV/CorePlugin.php, the following needs to be added or replaced on line 179:

    if (is_resource($body) && (!stream_get_meta_data($body)[‘seekable’] || -1 === fseek($body, $start, SEEK_SET))) {

    The specified code section in the httpGet method attempts to retrieve the file type (Content-Type) of a stream. The error is that the code calls stream_get_meta_data() directly on the stream handle ($body) without first checking whether $body is actually a stream.

    The error occurs because $body can sometimes be a stream handle (Resource) and sometimes a string (when the HTTP method is HEAD). However, the stream_get_meta_data() function introduced in PHP 7 always expects a stream handle.

    The fix is ​​to ensure that $body is a valid stream before calling stream_get_meta_data(), or to use the correct function for strings if it is a string.

    Since the code already ensures that $body is either a stream handle or an empty string (‘’), only one additional check needs to be added.

  5. susnux commented on Dec 2, 2026

    @susnux
    Contributor

    Thanks for the detailed analysis! This was fixed upstream in sabre/dav 4.7.1, where Range headers are now ignored for non-GET requests (sabre-io/dav#1618). Nextcloud still ships 4.7.0; the update is pending in #62405 / #63032, with backports in #67025, #67026 and #67027, so this will be resolved once those are merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0. Needs triage33-feedbackbugfeature: dav

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions