Skip to content

Return whole file if range request cannot be granted due to encryption - #10422

Merged
PVince81 merged 1 commit into
masterfrom
dav-disablerangerequestwhennotsupported
Aug 20, 2014
Merged

PVince81 merged 1 commit into
masterfrom
dav-disablerangerequestwhennotsupported

Conversation

@PVince81

Copy link
Copy Markdown
Contributor

Whenenver range headers are set and encryption is enabled, it is not
possible to automatically fseek() to the proper position.

To avoid returning corrupt/invalid data or causing a decryption error,
the range headers are stripped so that the SabreDAV code in httpGet()
returns the whole file.

Fixes #10383

Please review @DeepDiver1975 @icewind1991 @schiesbn @guruz

Whenenver range headers are set and encryption is enabled, it is not
possible to automatically fseek() to the proper position.

To avoid returning corrupt/invalid data or causing a decryption error,
the range headers are stripped so that the SabreDAV code in httpGet()
returns the whole file.
@PVince81

Copy link
Copy Markdown
Contributor Author

Note: this is currently only for the encryption case.
I'll do some tests to see how it behaves with external storage.

@PVince81

Copy link
Copy Markdown
Contributor Author

External storage seems to be unaffected by this issue, see #10383 (comment)

@ghost

ghost commented Aug 14, 2014

Copy link
Copy Markdown

@PVince81 PVince81 added this to the 2014-sprint-01-current milestone Aug 15, 2014
@PVince81 PVince81 self-assigned this Aug 15, 2014
@PVince81

Copy link
Copy Markdown
Contributor Author

To test this, try curl with a range request with and without encryption:
curl --header "Range: bytes=100-200" http://root:admin@localhost/owncloud/remote.php/webdav/afile.txt`

When encryption is disabled you should get 100 bytes and also a Content-Range response header.
When encryption is enabled you should receive the full file and no Content-Range response header.

@schiessle

Copy link
Copy Markdown
Contributor

tested, works... code looks good too 👍

@bantu

bantu commented Aug 17, 2014

Copy link
Copy Markdown

Whenenver range headers are set and encryption is enabled, it is not possible to automatically fseek() to the proper position.

Care to explain why that is the case? E.g. there is https://github.com/owncloud/core/blob/master/apps/files_encryption/lib/stream.php#L224

@PVince81

Copy link
Copy Markdown
Contributor Author

@bantu I think fseek for encryption never worked properly. Someone submit a PR to make it seekable #8390

Also, even if we make encryption's fseek return false to signal an error or "unsupported", SabreDAV will ignore the error.

This PR here is needed in the short term and is intend for backport. The PR above could be used in OC 8 for proper seeking support.

@PVince81 PVince81 closed this Aug 18, 2014
@PVince81 PVince81 reopened this Aug 18, 2014
@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@PVince81

Copy link
Copy Markdown
Contributor Author

@bantu encrypted files are bigger than unencrypted files.
An encrypted block of 8k bytes contains 6k unencrypted bytes which means that it's not a one to one mapping which makes seeking more complex.

@PVince81

Copy link
Copy Markdown
Contributor Author

@bantu @icewind1991 please review, I'd like to get this in 7.0.2 for tomorrow.
Remember that it fixes corrupted files in some cases, so quite important.

@PVince81

Copy link
Copy Markdown
Contributor Author

@owncloud-bot retest this please

@ghost

ghost commented Aug 20, 2014

Copy link
Copy Markdown

looks good 👍

@LukasReschke

Copy link
Copy Markdown
Contributor

IT IS ALIVE!

@ghost

ghost commented Aug 20, 2014

Copy link
Copy Markdown

YES - I AM!

@ghost

ghost commented Aug 20, 2014

Copy link
Copy Markdown

PVince81 pushed a commit that referenced this pull request Aug 20, 2014
…tsupported

Return whole file if range request cannot be granted due to encryption
@PVince81
PVince81 merged commit 36c88e2 into master Aug 20, 2014
@PVince81
PVince81 deleted the dav-disablerangerequestwhennotsupported branch August 20, 2014 16:14
@PVince81

Copy link
Copy Markdown
Contributor Author

@karlitschek backport to stable7 ? (fixes corrupted files with HTTP range requests + encryption)

@PVince81

Copy link
Copy Markdown
Contributor Author

Maybe even stable6 :-/

@PVince81

Copy link
Copy Markdown
Contributor Author

I'm not sure about stable6 as we had another SabreDAV version, might need further testing.

@karlitschek

Copy link
Copy Markdown
Contributor

Please backport if this is properly tested. @dragotin can you help?

@PVince81

Copy link
Copy Markdown
Contributor Author

Just did a manual test as follows:

  1. Apply patch on stable7
  2. Setup a VM with OC on it and lots of data and encryption enabled
  3. Setup a sync client to download that data
  4. During download, tease the sync client by unplugging the VM's virtual cable
  5. Repeat step 4 multiple times on different files
  6. Be nice again and let the sync client finish
  7. Check md5sum of files, all look ok.

I'll do the same test without the fix to confirm that it breaks without it.
And then try the same without encryption (for resuming)

@PVince81

Copy link
Copy Markdown
Contributor Author

@dragotin is it possible to add download resuming tests to your magical automated test suites ?

@karlitschek

Copy link
Copy Markdown
Contributor

O.K. Fine with me than. I only wanted to make sure that we are over careful with last minute backports like that that could affect syncing.

@PVince81

Copy link
Copy Markdown
Contributor Author

Yes of course that makes sense.
Next time I'll try to push people to review faster so it can go in earlier.

@PVince81

Copy link
Copy Markdown
Contributor Author

I'll push the backport once I'm done with testing.

@PVince81

Copy link
Copy Markdown
Contributor Author

Negative test confirmed: resuming gives the expected 500 internal server error.
Switching back to the fix branch heals it 😄

@PVince81

Copy link
Copy Markdown
Contributor Author

Second run of the test with the same files and random unplugging worked as well: MD5 match.

Backported to stable7 as c6e87ac

@PVince81

Copy link
Copy Markdown
Contributor Author

And the last test without encryption: I observed the file being resumed properly multiple times by the sync client and the resulting md5 still matches.
All green 😄

@VincentvgNn

Copy link
Copy Markdown

@PVince81
In a 500MB data test set (3000 files, 300 folders) I find each time 1-3 different files that are stored corrupted in the cloud. After decryption a large part of these files is completely different from the original file. File size and date/time are equal to the original file.
I doesn't matter whether the file is repeatedly downloaded by the client or via the web interface.

Example of a corrupted file (original file at the left side, first 398 lines at the right side are corrupted):
20060223_1358__renasym_cd_no_id3d-corrpted

Does the solution for the current issue also solve the problem of encrypted files getting corrupted during the upload?
Or did I discover a new issue?

Uploaded by OC client v1.6.2
OC server v7.0.1

@PVince81

Copy link
Copy Markdown
Contributor Author

@VincentvgNn I expect this to also fix corrupted files because in your case it was also about resuming encrypted files. Can you try with OC 7.0.2 RC 1 which has the fix ?

@VincentvgNn

Copy link
Copy Markdown

@PVince81
I expect the distribution of OC 7.0.2 around the end of this week. So I'll let the Installatron do the job and then test again.

@VincentvgNn

Copy link
Copy Markdown

@PVince81
Using OC server v7.0.2 and OC client v1.6.3, I uploaded again the 500MB data test set (3000 files, 300 folders) from PC3 (XP). On PC1 (Win7) and PC2 (Win8,1) the download was running.
Again I found one file that was corrupted at the encryption.
Similar to the above picture "17 days ago".

Did I discover a new issue to be reported?
Or was the current fix not right implemented?

@PVince81

PVince81 commented Sep 9, 2014

Copy link
Copy Markdown
Contributor Author

@VincentvgNn hmmm the fix is only for the webdav download interface, not web interface.
It's when downloading parts of encrypted files.

If you did the following:

  1. Upload files with the sync client (no download)
  2. Download the files with the web UI

and still get corrupted files, then you probably discovered another issue 😦

@VincentvgNn

Copy link
Copy Markdown

@PVince81
Downloading via the sync client or via the web interface doesn't make any difference.
The file has got corrupted at the upload + encryption.
I'll do a new 4th test to see if then other or some more files are affected.
After that I will report it as a new issue.

@PVince81

PVince81 commented Sep 9, 2014

Copy link
Copy Markdown
Contributor Author

Okay got it, so it's possibly a corruption at upload time, which is not covered by the fix above.
Did you have a ticket for that already in the mirall repo ?

@VincentvgNn

Copy link
Copy Markdown

@PVince81
It seems that things are going wrong during upload and encryption on the OC server.
When doing the same test without encryption, I cannot reproduce the problem.
Why do you advise to put in in the mirall repo and not the core repo? Thanks.

@PVince81

PVince81 commented Sep 9, 2014

Copy link
Copy Markdown
Contributor Author

Whichever repo as we don't know about the issue yet. On a second thought it is more likely to be a core/server issue since that's where encryption is happening.
Can you make a new ticket and let's continue the discussion there ?

@VincentvgNn

Copy link
Copy Markdown

@PVince81 See new ticket #10975

@jknockaert

Copy link
Copy Markdown
Contributor

I didn't notice this PR until now. I submitted PR #8390. @PVince81 merging it to OC 8 seems like a good idea to me, but #8390 is only tested on OC 6 so far. I will follow up in that PR.
I also submitted a PR to fix SabreDAV for nonseekable streems: https://github.com/fruux/sabre-dav/pull/442 That PR got merged but I'm not sure if it already made its way back to ownCloud.

jknockaert pushed a commit that referenced this pull request Mar 24, 2015
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot download encrypted file with HTTP range request

8 participants