nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.46k stars 4.08k forks source link

Encryption Error while deleting folder Error: fread(): Read of 8192 bytes failed with errno=21 Is a directory at /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php#860 #21578

Closed AndyXheli closed 3 years ago

AndyXheli commented 4 years ago

How to use GitHub

Steps to reproduce

  1. Create a folder then delete it

Expected behaviour

Tell us what should happen

Actual behaviour

Tell us what happens instead

Error PHP fread(): read of 8192 bytes failed with errno=21 Is a directory at /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php#861

Server configuration

Operating system: Ubunti 18.0.4 Web server: Apache2 Database: MySQL PHP version: 7.4.7 Nextcloud version: (see Nextcloud admin page) 19.0 Updated from an older Nextcloud/ownCloud or fresh install:

Where did you install Nextcloud from:

Signing status:

Signing status ``` Login as admin user into your Nextcloud and access http://example.com/index.php/settings/integrity/failed paste the results here. ```

List of activated apps:

App list Enabled: - accessibility: 1.5.0 - activity: 2.12.0 - admin_audit: 1.9.0 - bruteforcesettings: 1.6.0 - cloud_federation_api: 1.2.0 - comments: 1.9.0 - contactsinteraction: 1.0.0 - dav: 1.15.0 - encryption: 2.7.0 - federatedfilesharing: 1.9.0 - federation: 1.9.0 - files: 1.14.0 - files_external: 1.10.0 - files_pdfviewer: 1.8.0 - files_rightclick: 0.16.0 - files_sharing: 1.11.0 - files_trashbin: 1.9.0 - files_versions: 1.12.0 - files_videoplayer: 1.8.0 - firstrunwizard: 2.8.0 - logreader: 2.4.0 - lookup_server_connector: 1.7.0 - nextcloud_announcements: 1.8.0 - notifications: 2.7.0 - oauth2: 1.7.0 - password_policy: 1.9.1 - photos: 1.1.0 - privacy: 1.3.0 - provisioning_api: 1.9.0 - recommendations: 0.7.0 - richdocuments: 3.7.2 - serverinfo: 1.9.0 - settings: 1.1.0 - sharebymail: 1.9.0 - socialsharing_email: 2.0.0 - support: 1.2.1 - survey_client: 1.7.0 - systemtags: 1.9.0 - text: 3.0.1 - theming: 1.10.0 - twofactor_backupcodes: 1.8.0 - updatenotification: 1.9.0 - viewer: 1.3.0 - workflowengine: 2.1.0 ``` If you have access to your command line run e.g.: sudo -u www-data php occ app:list from within your Nextcloud installation folder ```

Nextcloud configuration:

Config report ``` If you have access to your command line run e.g.: sudo -u www-data php occ config:list system from within your Nextcloud installation folder or Insert your config.php content here. Make sure to remove all sensitive content such as passwords. (e.g. database password, passwordsalt, secret, smtp password, …) ```

Are you using external storage, if yes which one: local/smb/sftp/...

Are you using encryption: yes/no

Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/...

LDAP configuration (delete this part if not used)

LDAP config ``` With access to your command line run e.g.: sudo -u www-data php occ ldap:show-config from within your Nextcloud installation folder Without access to your command line download the data/owncloud.db to your local computer or access your SQL server remotely and run the select query: SELECT * FROM `oc_appconfig` WHERE `appid` = 'user_ldap'; Eventually replace sensitive data as the name/IP-address of your LDAP server or groups. ```

Client configuration

Browser:

Operating system:

Logs

Web server error log

Web server error log ``` Insert your webserver log here ```

Nextcloud log (data/nextcloud.log)

Nextcloud log ``` Insert your Nextcloud log here ```

Browser log

Browser log ``` Insert your browser log here, this could for example include: a) The javascript console log b) The network log c) ... ```

image

AndyXheli commented 4 years ago

Looks like it may have something to do with PHP 7.4.7 I went back to PHP 7.3.19 and did not get that error.

closingin commented 4 years ago

I can confirm this bug. I have the same error using the docker image with PHP 7.4.7.

AndyXheli commented 4 years ago

Hello any updates on this.

Still have this issue

Fatal webdav TypeError: Argument 2 passed to OC\Files\Storage\Wrapper\Encryption::modifyMetaData() must be of the type array, null given, called in /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php on line 208   16 minutes ago
Error PHP Trying to access array offset on value of type null at /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php#208   16 minutes ago
Fatal webdav TypeError: Argument 2 passed to OC\Files\Storage\Wrapper\Encryption::modifyMetaData() must be of the type array, null given, called in /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php on line 208   17 minutes ago
Error PHP Trying to access array offset on value of type null at /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php#208   17 minutes ago
Error PHP fread(): read of 8192 bytes failed with errno=21 Is a directory at /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php#861
AndyXheli commented 4 years ago

Still having this issue on Nextcloud 19.0.1 PHP: Version: 7.4.8

AndyXheli commented 4 years ago

@MorrisJobke Is this something thats being worked on?

fread(): read of 8192 bytes failed with errno=21 Is a directory at /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php#862

AndyXheli commented 4 years ago

@MorrisJobke any updates on this issue?

MorrisJobke commented 4 years ago

@MorrisJobke any updates on this issue?

Not really. I linked just the wrong ticket 🙈

AndyXheli commented 4 years ago

@MorrisJobke Okay thank you for the update. Anyway we can have someone look into this please!

AndyXheli commented 4 years ago

Same issue on NC 19.0.3

toxpal commented 4 years ago

Have exactly the same problem after updating to 19.0.3. All previous versions worked just fine.

RedKage commented 4 years ago

@axheli I do have these errors in the log as well.

And also in the client image

But it doesn't seem to affect Nextcloud beyond these errors. Everythings gets deleted fine, and uploaded fine. Or did I miss something?

Kuphi commented 4 years ago

Please fix asap. Also having this issue on NC 19.0.4 I have an encrypted nextcloud (encrypted for each user separately). The error occurs, when a user tries to delete a folder in a folder, that is shared with him. It also occurs when I try to cut and paste a folder. Error: fread(): read of 8192 bytes failed with errno=21 Is a directory at /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php#862

Operating system: Ubuntu server 18.0.4 Web server: Apache2 Database: MySQL / MariaDB PHP version: 7.4.3 Nextcloud version: (see Nextcloud admin page) 19.0.4 Updated from an older Nextcloud/ownCloud or fresh install: From Nextcloud 18 (Nextcloud 18 was fresh install)

Kuphi commented 4 years ago

Getting dozens of those:

`Error: fread(): read of 8192 bytes failed with errno=21 Is a directory at /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php#862 <>

OC\Log\ErrorHandler::onError()

/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php - line 862:

fread()

/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php - line 930:

OC\Files\Storage\Wrapper\Encryption->readFirstBlock()

/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php - line 961:

OC\Files\Storage\Wrapper\Encryption->getHeader()

/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Encryption.php - line 294:

OC\Files\Storage\Wrapper\Encryption->getEncryptionModule()

/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php - line 278:

OC\Files\Storage\Wrapper\Encryption->rename()

/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php - line 572:

OC\Files\Storage\Wrapper\Wrapper->rename()

/var/www/nextcloud/apps/files_trashbin/lib/Trashbin.php - line 294:

OC\Files\Storage\Wrapper\Wrapper->moveFromStorage()

/var/www/nextcloud/apps/files_trashbin/lib/Trash/LegacyTrashBackend.php - line 108:

OCA\Files_Trashbin\Trashbin::move2trash()

/var/www/nextcloud/apps/files_trashbin/lib/Trash/TrashManager.php - line 103:

OCA\Files_Trashbin\Trash\LegacyTrashBackend->moveToTrash()

/var/www/nextcloud/apps/files_trashbin/lib/Storage.php - line 192:

OCA\Files_Trashbin\Trash\TrashManager->moveToTrash()

/var/www/nextcloud/apps/files_trashbin/lib/Storage.php - line 118:

OCA\Files_Trashbin\Storage->doDelete()

/var/www/nextcloud/lib/private/Files/View.php - line 1161:

OCA\Files_Trashbin\Storage->rmdir()

/var/www/nextcloud/lib/private/Files/View.php - line 350:

OC\Files\View->basicOperation()

/var/www/nextcloud/apps/dav/lib/Connector/Sabre/Directory.php - line 308:

OC\Files\View->rmdir()

/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Tree.php - line 183:

OCA\DAV\Connector\Sabre\Directory->delete()

/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php - line 295:

Sabre\DAV\Tree->delete()

/var/www/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php - line 89:

Sabre\DAV\CorePlugin->httpDelete()

/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 474:

Sabre\DAV\Server->emit()

/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 251:

Sabre\DAV\Server->invokeMethod()

/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php - line 319:

Sabre\DAV\Server->start()

/var/www/nextcloud/apps/dav/lib/Server.php - line 320:

Sabre\DAV\Server->exec()

/var/www/nextcloud/apps/dav/appinfo/v2/remote.php - line 35:

OCA\DAV\Server->exec()

/var/www/nextcloud/remote.php - line 167:

require_once("/var/www/ne ... p")`

AndyXheli commented 4 years ago

Based on what i can see its happening on PHP 7.4 if you downgrade to 7.3 i dont see this error, but that's not a solutions. There should be a fix of this.

Kuphi commented 4 years ago

Based on what i can see its happening on PHP 7.4 if you downgrade to 7.3 i dont see this error, but that's not a solutions. There should be a fix of this.

Hopefully for NC 19.0.6 and 20.0.3. This error is crowding my logfiles for weeks already.

AndyXheli commented 4 years ago

@MorrisJobke any updates on this issue?

Not really. I linked just the wrong ticket 🙈

Can you please unlink this since you liked it to the wrong ticket so we can get a fix for this?

MorrisJobke commented 4 years ago

Can you please unlink this since you liked it to the wrong ticket so we can get a fix for this?

There is no such thing as unlink. I mentioned it and then it will be shown in here. Deleting the mention also still keeps the entry in here. So not much I can do here.

Kuphi commented 3 years ago

@axheli Why did you close this? There is no fix yet, is there?

AndyXheli commented 3 years ago

Hey i opened a new ticket #24646 this one i think was not being seen since it was tagged on an issue that had nothing to do with it

jknockaert commented 3 years ago

This error actually happens every time a folder is renamed, deleted or moved to a different location. These are all cases of a rename at the filesystem level (basically modifying the path). What basically happens (when encryption is on) is that a rename (of a file or folder) is handled by the encryption wrapper at https://github.com/nextcloud/server/blob/87e917ca74ae98253e68317de79e060cbbcf7272/lib/private/Files/Storage/Wrapper/Encryption.php#L279 The function first handles the rename of the file, and then there's some logic to handle the encryption keys. Part of this process is to determine the encryption module: https://github.com/nextcloud/server/blob/87e917ca74ae98253e68317de79e060cbbcf7272/lib/private/Files/Storage/Wrapper/Encryption.php#L294 The input used to determine the encryption module is located in the first block (8192 bytes) of the file, which is read here: https://github.com/nextcloud/server/blob/87e917ca74ae98253e68317de79e060cbbcf7272/lib/private/Files/Storage/Wrapper/Encryption.php#L862 PHP up to version 7.3 wouldn't complain about attempting to fread a folder, but version 7.4 seems not to be happy being instructed to do so. So where to fix this? I'm happy to prepare a PR, but I would first like to discuss it a bit further in order not to introduce regressions. My first suggestion would be to have a look at the getHeader function: https://github.com/nextcloud/server/blob/87e917ca74ae98253e68317de79e060cbbcf7272/lib/private/Files/Storage/Wrapper/Encryption.php#L923 Ideally we should insert some logic to catch directories before readFirstBlock is called. What happens with 7.3 is that $result is initialised as an empty array when calling parseRawHeader, and then further down it is determined that encrypted===false in the cache so eventually the empty array is returned. I would suggest that we rework the logic such that the cache is consulted before the call to readFirstBlock. I don't think we need to account here for cases where the cache is inconsistent with the presence of a header. The current setup is actually counterproductive; imagine the case where the encryption module is enabled, and an unencrypted text file for whatever reasons start with a sequence that corresponds valid encryption header. That would result in an error because of trying to decrypt an unencrypted file. That is actually the reason why daisychaining doesn't work with nextcloud. So we probably should always first check the cache. Or is that too expensive?

jknockaert commented 3 years ago

@nextcloud/encryption Anyone any advise on the suggested approach?

AndyXheli commented 3 years ago

@jknockaert hopefully this fixes it and someone from support will help with this this ticket has been open for long time now

jknockaert commented 3 years ago

While I was debugging I noticed that getHeader is being evaluated many times every second with files_encryption/OC_DEFAULT_MODULE/pubShare_[edited].publicKey as argument. That seems wasteful. I couldn't determine the trigger, but it's definitely useless to get the first 8192 bytes of a keyfile, as there's nothing to see there for getHeader. Perhaps we can eliminate these calls as well while we're at it?

RedKage commented 3 years ago

@jakobsack I am not a maintainer, but I suspect this issue here is related/causing this issue https://github.com/nextcloud/server/issues/16419 Maybe this can help you

On this issue there we end up with a bad encryption state in the oc_filecache table.

jknockaert commented 3 years ago

@RedKage It doesn't seem to be directly related (and definitely not caused by). But fixing #16419 should definitely be handled by properly accounting for that case in rename at https://github.com/nextcloud/server/blob/87e917ca74ae98253e68317de79e060cbbcf7272/lib/private/Files/Storage/Wrapper/Encryption.php#L279 But that one is likely more complex to fix.

AndyXheli commented 3 years ago

@jknockaert are you working on a fix for this :)

jknockaert commented 3 years ago

@axheli yes I finished a PR. It's a small fix, so I expect it to be merged quite soon. Not sure if still in time for the next point release.

AndyXheli commented 3 years ago

@jknockaert I applied the below fix and im not getting the errors anymore

image

mre-gi commented 3 years ago

Still getting this error with NC Version 20.0.5, PHP 7.4.10.

Is it recommended to manually change it?

AndyXheli commented 3 years ago

Pull Request #24966 is still under review so yes i think you'll have to manually change it or wait until its released.

RedKage commented 3 years ago

Hello, I'm reporting back on PR #24966 I have made the change locally on my instance, and everything works fine now. I used to be plagued with encryption errors (for 4 years now), and now it's been a week and I have had none.

This PR is a godsend. This will make possible for me to recommend nextcloud to my relative AND at my work since there should should be no dataloss anymore.

Cheers!

toxpal commented 3 years ago

I still experience this issue with 21.0.8, but not as often as previously.

AndyXheli commented 3 years ago

I still experience this issue with 21.0.8, but not as often as previously.

You mean 20.0.8 ?

toxpal commented 3 years ago

Sorry, my bad. Yes, I mean 20.0.8

talesam commented 3 years ago

I have the NC 21 running on docker, latest version and I have the same problem, removing, moving or deleting a folder appears an error.

Delete

Error: fread(): read of 8192 bytes failed with errno=21 Is a directory at /var/www/html/lib/private/Files/Storage/Wrapper/Encryption.php#864

Move

Error: fread(): read of 8192 bytes failed with errno=21 Is a directory at /var/www/html/lib/private/Files/Storage/Wrapper/Encryption.php#864
jknockaert commented 3 years ago

The fix is now merged and I guess it will be included in the next point release of NC 21.

AndyXheli commented 3 years ago

Thank you everyone wohoooo!! 🎉🎉

Sent from my iPhone

On Apr 6, 2021, at 6:49 AM, Jasper Knockaert @.***> wrote:

 The fix is now merged and I guess it will be included in the next point release of NC 21.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

AndyXheli commented 3 years ago

24966 should be fixed in the next 21 release

jknockaert commented 3 years ago

Fixed in #24966

AndyXheli commented 3 years ago

@jknockaert sorry must of opened it on accident

AndyXheli commented 3 years ago

@jknockaert This is still an issue on 21.0.3 looks like the #24966 fix has not been added can you please add this?

jknockaert commented 3 years ago

@andyxheli I am no longer using the encryption app (I disabled it) and I do no longer support any code I wrote including #24966. Maybe someone else can help you.

AndyXheli commented 3 years ago

@jknockaert Thank you for your effort. Since this is not fixed can you please reopen this ticket ?

jknockaert commented 3 years ago

@andyxheli You can reopen it or create a new one. For me the issue is gone.

AndyXheli commented 3 years ago

@jknockaert Thank you very much.

RedKage commented 3 years ago

I have just updated to 21.0.3 And the file Encryption.php hasn't changed since @jknockaert fix. There's just some additional comments, that's all. So the fix should still work. I'm applying it, and we will see

AndyXheli commented 3 years ago

@RedKage I did apply the fix and it still dose work. Someone just need to backport it

RedKage commented 3 years ago

Seems like this patch is live on version 21.0.5 Which is kinda weird as I don't remember seeing this in the changelog https://nextcloud.com/changelog#21-0-5

dzaziz commented 1 year ago

I have similar issue, not sure what cause the error in the logfile.

Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 -- | -- | -- | -- | -- Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:16+0800 Error | PHP | Error: hash_file(): Read of 8192 bytes failed with errno=21 Is a directory at /snap/nextcloud/32871/htdocs/lib/private/Files/Storage/Local.php#390 |   | 2022-12-22T08:33:15+0800
afzl-wtu commented 1 year ago

LOL Issue is still present in 27.1.3