nextcloud / nextcloud/server

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

Open
#57,219 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage 33-feedback bug feature: dav
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

⚠️ 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 https://github.com/nextcloud/3rdparty/pull/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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in 3rdparty/sabre/dav/lib/DAV/CorePlugin.php, especially httpGet() and the stream_get_meta_data() call around line 179. Reproduce with curl using a HEAD request and Range header against a public DAV PDF endpoint. Done means the request avoids the TypeError and supports the expected partial-content response for efficient loading.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.