Merged
Conversation
We also need to create the send prior to saving the stream so we have well defined save location. Solve chicken-and-egg problem by saving the Send twice. This also allows for validation that the stream received is the same length as that promissed by the content-length header
This was referenced Mar 1, 2021
cscharf
approved these changes
Mar 2, 2021
Contributor
cscharf
left a comment
There was a problem hiding this comment.
Looks good. I'm not sure any other length checks outside of what you have are necessary, and a buffer probably not necessary either.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Fixes issue introduced in #1174
Moving Send file saving to after Send creation allowed for referencing the Send's Id in the storage location, but I forgot that the HttpStream's length is 0 until it is read out. This results in file length of 0 for all Send files.
This is a chicken-and-egg problem who's solution is to save the send twice. I'm saving the Send to get an Id, saving the file, verifying the file length, and updating the Send's file data to contain the proper length.
The verification step is a nice addition since there is no guarantee that a Content-Length header we're using as the request length to verify storage bytes is equal to the actual stream length uploaded.
If the actual stream's length is larger than that requested we throw back an error and delete the Send. This results in a failure in the client and a toast explaining the reason.
One potential issue: Do we want to provide a pad at all for slightly larger files? I haven't seen any examples where that can happen and the idea is that the requested length should be equal to the already encrypted data
Files Changed
Testing Done
I've created files and verified their lengths, as well as intercepted save requests, monkeying with the promised file lengths. Files which are shorter than expected save file and register the proper length. Files which are actually longer fail to save.