Skip to content

Fix send file length always zero#1175

Merged
MGibson1 merged 2 commits intomasterfrom
fix-send-file-length-always-zero
Mar 2, 2021
Merged

Fix send file length always zero#1175
MGibson1 merged 2 commits intomasterfrom
fix-send-file-length-always-zero

Conversation

@MGibson1
Copy link
Member

@MGibson1 MGibson1 commented Mar 1, 2021

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

  • SendsController.cs/SendRequestModel.cs: get request length from the model. To be populated by clients
  • SendService: Validate stream length and update Send to proper length

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.

MGibson1 added 2 commits March 1, 2021 15:50
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
Copy link
Contributor

@cscharf cscharf left a comment

Choose a reason for hiding this comment

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

Looks good. I'm not sure any other length checks outside of what you have are necessary, and a buffer probably not necessary either.

@MGibson1 MGibson1 merged commit c2d34d7 into master Mar 2, 2021
@MGibson1 MGibson1 deleted the fix-send-file-length-always-zero branch March 2, 2021 15:27
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.

2 participants