fix(core): handle Uint8Array subarrays correctly in createFile and encodeByteArray#38144
Open
deyaaeldeen wants to merge 1 commit intomainfrom
Open
fix(core): handle Uint8Array subarrays correctly in createFile and encodeByteArray#38144deyaaeldeen wants to merge 1 commit intomainfrom
deyaaeldeen wants to merge 1 commit intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes silent data corruption when Uint8Array.subarray() is passed through file creation and base64 encoding by ensuring byte offsets/lengths are respected.
Changes:
- Update
createFileto return correctArrayBufferranges and avoid using a subarray’s full backing buffer. - Update
encodeByteArrayto passbyteOffset/byteLengthtoBuffer.from. - Add tests covering subarray handling for multipart file upload and ByteArray serialization.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| sdk/core/core-rest-pipeline/test/internal/formDataPolicy.spec.ts | Adds regression test ensuring createFile handles subarray content correctly. |
| sdk/core/core-rest-pipeline/src/util/file.ts | Fixes createFile.arrayBuffer() and toArrayBuffer() to respect subarray bounds. |
| sdk/core/core-client/test/public/serializer.spec.ts | Adds regression test ensuring ByteArray subarrays serialize correctly. |
| sdk/core/core-client/src/base64.ts | Fixes base64 encoding to respect subarray offsets/lengths. |
sdk/core/core-rest-pipeline/test/internal/formDataPolicy.spec.ts
Outdated
Show resolved
Hide resolved
a82c951 to
997c301
Compare
…codeByteArray createFile's arrayBuffer() returned the full backing ArrayBuffer via content.buffer, ignoring byteOffset/byteLength when content is a subarray. Similarly, toArrayBuffer() returned the original view as-is, causing Blob and File constructors to use the full buffer. encodeByteArray in core-client had the same issue: Buffer.from(value.buffer) ignored the subarray's byteOffset and byteLength. Fixes: - createFile: slice the buffer to the correct range in arrayBuffer() - toArrayBuffer: copy subarrays that don't span the full buffer - encodeByteArray: pass byteOffset and byteLength to Buffer.from() Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
997c301 to
2386ff3
Compare
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.
Problem
createFileandencodeByteArraysilently corrupt data when given aUint8Arraysubarray (via.subarray()). Both read from the full backingArrayBufferinstead of the subarray range.Fix
createFile(core-rest-pipeline): copy subarrays that do not span the full bufferencodeByteArray(core-client): passbyteOffset/byteLengthtoBuffer.from()Tests added for both.