Open dennis-grunert opened 3 weeks ago
2. On a client (here Linux), create the following files in the sync directory:
Does it make a difference if you upload using the webui?
Does it make a difference if you upload using the webui?
It is also reproducible when uploading the file in the web UI. I have updated the steps to reproduce above and uploaded the file bad A.txt
to this comment.
Can you check the nextcloud log file for any error? Especially things with "app": "encryption"
Can you check the nextcloud log file for any error? Especially things with
"app": "encryption"
There are no logs in the <data directory>/nextcloud.log
during or after upload.
I have the following encryption keys that look good at a first glance.
<data directory>/<username>/files_encryption/keys/files/A.txt/OC_DEFAULT_MODULE/<username>.shareKey
<data directory>/<username>/files_encryption/keys/files/A.txt/OC_DEFAULT_MODULE/recoveryKey_<id>.shareKey
(since I have recovery enabled as suggested by the NextCloud documentation)But I just checked the encrypted file located at
<data directory>/<username>/files/A.txt
and it ended up being just metadata without any encrypted data, see attached (I renamed it to A_encrypted,txt
before uploading). As suspected, the encryption process ended without errors but it returned the wrong data.
I think, I found the issue: As guessed, it is because of a wrong falsely check. All relevant methods are located in class apps/encryption/lib/Crypto/Encryption.php
:
encrypt()
checks if the data chunk remaining to be encrypted is smaller than $this->getUnencryptedBlockSize(true)
, which is obvious true in our case of 1 Byte data. It then writes $data
to $this->writeCache
(see this line).end()
. But there is a check in this line that only encrypts the data if !empty($this->writeCache)
. It is intended to check if the write cache actually contains any data.The use of empty
is wrong here since it not only returns true
when the variable is not set but also if it equals to false
(see the documentation). empty("0")
is true
, which is exactly what happens here. Instead, it should check strlen() > 0
since $this->writeCache
was initiated earlier in begin()
as empty string.
So it should be only this one-liner and a small unit test to fix it. I'm not a PHP developer, so I let this have someone else. Maybe this is also a candidate for the good first issue
label?
Yes I asked because I suspected to see a Encryption Library, symmetrical encryption failed no content given
, because of this line:
Good catch! I guess both places need to be fixed then to be sure.
⚠️ This issue respects the following points: ⚠️
Bug description
A file with the contents
0x30
(i.e., a literal "0" (digit zero as string) without line feed) is not correctly synced to the server when (user-key) encryption is enabled. The content is lost, i.e., the data is corrupted.Important notes:
0x30
seems to trigger it. It seems that it is incorrectly checked if a file content is empty (e.g., in JavaScript, the string "0" would be falsely, but not the string "1").Steps to reproduce
occ encryption:disable-master-key
). Probably it is also reproducible with a server key (default).echo -n -e '\x30' > A.txt
("0")echo -n -e '\x30\x0A' > B.txt
("0" with LF)echo -n -e '\x31' > C.txt
("1")echo -n -e '\x30\x30' > D.txt
("00")echo -n -e '\x20' > E.txt
(space)echo -n -e '\x0A' > F.txt
(LF)echo -n -e '\x00' > G.txt
(null)A.txt
is corrupted:A.txt
in the browser editor of NextCloud, it doesn't show the single character but is displayed as empty.A.txt
via the browser results in a zero byte file being downloaded.A.txt
with the file sync of the Desktop client that doesn't had the file yet results in the error message "The downloaded file is empty, but the server said it should have been 1 B."Expected behavior
File
A.txt
is uploaded correctly to the server like the other files of the above test.Installation method
None
Nextcloud Server version
29
Operating system
Debian/Ubuntu
PHP engine version
PHP 8.1
Web server
Apache (supported)
Database engine version
MariaDB
Is this bug present after an update or on a fresh install?
None
Are you using the Nextcloud Server Encryption module?
Encryption is Enabled
What user-backends are you using?
Configuration report
List of activated Apps
Nextcloud Signing status
Nextcloud Logs
No response
Additional info
No response