Skip to content

fix(e2ee): refresh during crud operations#17267

Open
alperozturk96 wants to merge 12 commits into
masterfrom
fix/e2ee-counter-check
Open

fix(e2ee): refresh during crud operations#17267
alperozturk96 wants to merge 12 commits into
masterfrom
fix/e2ee-counter-check

Conversation

@alperozturk96

@alperozturk96 alperozturk96 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Issue

Refreshing folder causing crash during crud operations in encrypted folder. Local counter should be only updated after completion of operation.

Changes

  • Consolidates counter updates
  • Updates counter after serializeAndUploadMetadata
  • Waits until current uploads finish then verify metadata during refresh folder operation


parentFolder.setE2eCounter(metadata.metadata.counter)
val storageManager = FileDataStorageManager(user, context.contentResolver)
storageManager.saveFile(parentFolder)

@alperozturk96 alperozturk96 Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be after serializeAndUploadMetadata

metadata,
getStorageManager());

parentFile.setE2eCounter(metadata.getMetadata().getCounter());

@alperozturk96 alperozturk96 Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be after serializeAndUploadMetadata


metadataFile.metadata.files[encryptedFileName] = decryptedFile
metadataFile.metadata.counter++
ocFile.setE2eCounter(metadataFile.metadata.counter)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addFileToMetadata has one caller and that already updates counter. No need to double it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also aligns with other functions such as removeFolderFromMetadata

): DecryptedFolderMetadataFile {
metadataFile.metadata.folders[encryptedFileName] = fileName
metadataFile.metadata.counter++
ocFile.setE2eCounter(metadataFile.metadata.counter)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addFolderToMetadata has one caller and that already updates counter. No need to double it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also aligns with other functions such as removeFolderFromMetadata

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

APK file: https://github.com/nextcloud/android/actions/runs/28519645539/artifacts/8011646161
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@alperozturk96
alperozturk96 force-pushed the fix/e2ee-counter-check branch from a68af81 to 9be910e Compare July 9, 2026 08:16
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

APK file: https://github.com/nextcloud/android/actions/runs/29005173465/artifacts/8193741488
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

boolean isWorkScheduled = WorkManagerExtensionsKt.isWorkScheduled(workManager, tag);
if (isWorkScheduled) {
Log_OC.d(TAG, "Upload worker running for " + user.getAccountName() + "; deferring metadata/counter update to next refresh");
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check if the counter is really correctly updated?
I assume that counter is not correctly updated for upload work and thus it works only if we do the operations one after another.
Please double check.

@alperozturk96 alperozturk96 Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. User tries to upload 5 encrypted files
  2. UploadFileOperation updates counter one by one after each successful upload
  3. User during uploads do the pull-to-refresh
  4. Refresh folder operation uses mLocalFolder and sends old counter e.g. 22
  5. The refresh downloads metadata still at 22, but the upload already pushed the local counter to 23
  6. Crashes because after pull to refresh upload operation at that time didn't push the latest value yet because it received 22 at that time.

This is not related to the updating logic, this is related to the timing and async execution.

Solution:

  1. Don't let the refresh verify metadata for a folder while an upload still in progress
  2. ?

Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>

# Conflicts:
#	app/src/main/java/com/owncloud/android/ui/fragment/FileDetailSharingFragment.java
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
@alperozturk96
alperozturk96 force-pushed the fix/e2ee-counter-check branch from 217f1b1 to 6e52bf6 Compare July 17, 2026 11:12
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
@github-actions

Copy link
Copy Markdown

APK file: https://github.com/nextcloud/android/actions/runs/29577078416/artifacts/8405696732
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
@github-actions

Copy link
Copy Markdown

APK file: https://github.com/nextcloud/android/actions/runs/29578868607/artifacts/8406318076
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
@github-actions

Copy link
Copy Markdown

blue-Light-Screenshot test failed, but no output was generated. Maybe a preliminary stage failed.

@github-actions

Copy link
Copy Markdown

Codacy

SpotBugs

CategoryBaseNew
Bad practice3232
Correctness6665
Dodgy code213213
Experimental11
Malicious code vulnerability22
Multithreaded correctness2525
Performance4141
Security1919
Total399398

@github-actions

Copy link
Copy Markdown

APK file: https://github.com/nextcloud/android/actions/runs/29581557894/artifacts/8407647313
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@github-actions

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants