Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Content is larger than the available bytes in the stream #138

Merged
merged 1 commit into from
Nov 28, 2019

Conversation

dpakach
Copy link
Contributor

@dpakach dpakach commented Nov 28, 2019

Fix for sending response of ranged streams when the content length provided is larger than the total number of bytes remaining in the stream.
In such cases the operation completes successfully but the loop never exits as stream_copy_to_stream() returns negative value.

This PR fixes this by checking the return value of stream_copy_to_stream() and returning when the return value is negative.

@codecov
Copy link

codecov bot commented Nov 28, 2019

Codecov Report

Merging #138 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #138      +/-   ##
============================================
+ Coverage     93.61%   93.64%   +0.03%     
- Complexity      256      257       +1     
============================================
  Files            15       15              
  Lines           830      834       +4     
============================================
+ Hits            777      781       +4     
  Misses           53       53
Impacted Files Coverage Δ Complexity Δ
lib/Sapi.php 96.29% <100%> (+0.1%) 40 <0> (+1) ⬆️
lib/functions.php 95.55% <0%> (+0.03%) 0% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd3958b...943e6c4. Read the comment docs.

@staabm
Copy link
Member

staabm commented Nov 28, 2019

Thx for the PR. Did you verify this fixes the reported owncloud problems?

@vfreex
Copy link
Contributor

vfreex commented Nov 28, 2019

I would interpret the mismatch between Content-Length and length of content is bug. We should definitely raise an exception (or use assert) if they are not equal rather than silently ignore this.

When user is requesting a larger range than expected, the server need to return HTTP 416 (Range Not Satisfiable) per https://tools.ietf.org/html/rfc7233#section-4.2

@phil-davis
Copy link
Contributor

The previous code never checked the return value of stream_copy_to_stream in any way.
So this "worked" in the previous code. The available/existing bytes in the input stream did get copied to the output stream - they were just less than what Content-Length said. And so "it worked for the user" - they actually received the proper file contents.

The problem is seen when an old version of a file in restored and the old version was shorter in length. When we ask for the file from S3, it tells that the length is the (longer) length of what was the "current" file. But the actual file data is correctly the shorter length of the restored version.

Now the question is what to do when sabre/http gets something like this. IMO for now this PR restores the previous behavior, so we do that for a patch release.

@phil-davis
Copy link
Contributor

This code does fix the CPU loop problem observed in ownCloud tests.

@phil-davis
Copy link
Contributor

IMO for now this PR restores the previous behavior, so we do that for a patch release.

And then someone can think through exactly what exception to throw and whether such a change in behaviour is a patch, minor or major version break.

@staabm staabm merged commit 2f00e9e into sabre-io:master Nov 28, 2019
@staabm
Copy link
Member

staabm commented Nov 28, 2019

Merging because it fixes a bc break .. whether this is the correct behavior or not can be discussed and fixed in the next major release

@staabm
Copy link
Member

staabm commented Nov 28, 2019

Thank you guys for working on the problem. Very appreciated

@phil-davis
Copy link
Contributor

Thank you guys for working on the problem. Very appreciated

No problem - we use this, so happy to help!

@dpakach dpakach deleted the fix-invalid-contentLength branch November 29, 2019 03:24
@phil-davis
Copy link
Contributor

sabre/http 5.0.5 has been merged to owncloud core in PR owncloud/core#36490
Looks good, see comment owncloud/files_primary_s3#274 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants