[Bug]: file with size different from 0 in oc_filecache but with size 0 on S3 primary storage
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
We have NC 31.0.9 with a Scality platform as S3 primary storage.
I noticed in NC log a few "Failed to open stream: HTTP request failed! HTTP/1.1 416 Range Not Satisfiable" errors for some files.
After investigating, it is because Nextcloud sends a "Range: bytes=0-" header to the S3 platform (https://github.com/nextcloud/server/blob/master/lib/private/Files/ObjectStore/S3ObjectTrait.php#L46), but the size of the object on the S3 storage platform is 0. And using "Range: bytes=x-x" with AWS S3 SDK seems to always return "416 Range Not Satisfiable" when the object is empty (I tested with aws cli with the same file that Nextcloud was trying to access).
But the "size" column in oc_filecache table for this file has value "138".
awss3api get-object --bucket bucket_name --key urn:oid:5272234 output
{
"AcceptRanges": "bytes",
"LastModified": "2025-11-06T09:24:31+00:00",
"ContentLength": 0,
"ETag": ""d41d8cd98f00b204e9800998ecf8427e"",
"VersionId": "3938323337353738393238343935393939393939524730303120203432342e313134313638383832322e3137323330383330",
"ContentType": "application/octet-stream",
"ServerSideEncryption": "AES256",
"Metadata": {}
}
awss3api get-object --bucket bucket_name --key urn:oid:5272234 --range "bytes=0-" output
An error occurred (InvalidRange) when calling the GetObject operation: The requested range cannot be satisfied.
fileid | storage | path | path_hash | parent | name | mimetype | mimepart | size | mtime | storage_mtime | encrypted | unencrypted_size | etag | permissions | checksum
---------+---------+-------------------------------------------------------------------------------------------+----------------------------------+---------+------------------------+----------+----------+------+------------+---------------+-----------+------------------+---------------+-------------+----------
5272234 | 1 | __groupfolders/39/FOLDER1/FOLDER2/FOLDER3/FOLDER4/FILENAME1.kdbx.FilTFD | 84a55b007b85a1cdcf82a9bc6814c988 | 3521974 | FILENAME1.kdbx.FilTFD | 14 | 3 | 165 | 1762421071 | 1762421071 | 0 | 0 | 690c694fad0db | 27 |
- How can the size field in the DB have a different value than the size of the object on S3 storage?
- Could you try to send a fopen request to S3 storage platform without the Range header, if you sent the first request with "Range: bytes=0-" and received "416 Range Not Satisfiable" as response? And if this second fopen fails, then you throw an exception.
Steps to reproduce
Expected behavior
file size should be consistent across db and s3 storage
check the returned total size from the content-range header against the expected size
Nextcloud Server version
31
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?
None
What user-backends are you using?
- Default user-backend (database)
- LDAP/ Active Directory
- SSO - SAML
- Other
Configuration report
List of activated Apps
Nextcloud Signing status
Nextcloud Logs
Additional info
No response
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 by reading lib/private/Files/ObjectStore/S3ObjectTrait.php around line 46 and trace how the S3 object size and Range request are handled. The issue provides no reproduction steps or test file, so first establish a case where the database size differs from an empty S3 object. Done means the size mismatch and 416 fallback behavior are covered by the relevant tests and the requested consistency check is satisfied.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, php
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100