[Bug]: TypeError in Sabre CorePlugin when handling public DAV HEAD range (master , stable32 and previous...) breaks fast PDF loading
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
⚠️ This issue respects the following points: ⚠️
- This is a bug, not a question or a configuration/webserver/proxy issue.
- This issue is not already reported on Github OR Nextcloud Community Forum (I've searched it).
- Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
- I agree to follow Nextcloud's Code of Conduct.
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
- Create a public share link for a single PDF file (not folder).
- Access the public DAV endpoint (e.g. viewer or
HEADrequest on/public.php/dav/files/<token>). - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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