-
Notifications
You must be signed in to change notification settings - Fork 233
Fix wrong buffer size calculation. #494
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 wrong buffer size calculation. #494
Conversation
|
@buptliuhs Thank you for the contribution! |
|
|
hi @nikithauc, What I did to reproduce the issue is that uploading a tiny jpeg file whose size is 747 bytes. In this case, Because of this, the http header will be like: It's likely to happen when the buffer size is less than the I'll see how to add a unit test to cover this change. Cheers, |
|
@nikithauc I had to move some code out of the |
|
hi @nikithauc , are you happy with the change? |
|
@buptliuhs the changes look good. I changed the base to dev for this PR. Can you please resolve this? I should have noticed the base setting before. I apologize for the inconvenience. |
|
Hi @nikithauc, I was initially looking for a fix in v2, which branch should the change be based on? I can create another PR to propagate the fix to dev too to fix the same issue in v3. |
|
@buptliuhs Can you please branch off dev? The fix will be reflected in 3.x versions. |
6fca47e to
ca737ac
Compare
|
Hi @nikithauc , I've done the rebase on the branch and now the branch is based on
Again, I'm also looking for the same fix on 2.x since 3.x is still in the preview stage. Is 2.x still in maintenance mode? If yes, which branch should I target? Thanks! Cheers, |
|
@buptliuhs 3.0.0 is released - https://www.npmjs.com/package/@microsoft/microsoft-graph-client/v/3.0.0. 2.x version will no longer be seeing any changes. |
ca737ac to
bf5ef40
Compare
492b0a7 to
5487143
Compare
|
Just did a final tidy-up. |
|
@buptliuhs Thank you for this contribution! Merging this right now :) |
|
@nikithauc hello again! Do we have a plan for a new release, e.g. 3.0.1, to include the fixes for 3.0.0? Thanks! |
|
@buptliuhs yes. Please expect 3.0.1 soon |
Summary
The calculation of Buffer size is incorrect (in both v2 and v3).
Motivation
When using
OneDriveLargeFileUploadTaskto upload small files (usually < 8KB, Buffer.poolSize), buffer size and slice are not calculated correctly, which causes upload failure.Example of the issue
When uploading a tiny jpeg file whose size is 747 bytes.
Buffer passed in OneDriveLargeFileUploadTask is:
{ byteOffset: 5808, byteLength: 747, length: 747, poolSize: 8192 }In this case,
byteOffsetis5808andbyteLengthis747.The old code calculates size =
byteLength - byteOffset, which is obviously incorrect.Because of this, the HTTP header that is used later to upload slices will be like:
And it causes a 400 response.
It's likely to happen when the buffer size is less than the pollSize. When buffer is large, byteLength is usually 0.
Test plan
Upload small files (< 8KB) using
OneDriveLargeFileUploadTask.Types of changes
Checklist