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(encoding/ascii85): fix encode() returns a wrong result with a 4-byte subarray #3310

Merged
merged 3 commits into from
Apr 11, 2023
Merged

fix(encoding/ascii85): fix encode() returns a wrong result with a 4-byte subarray #3310

merged 3 commits into from
Apr 11, 2023

Conversation

babiabeo
Copy link
Contributor

@babiabeo babiabeo commented Apr 9, 2023

Fixes: #3223

@babiabeo babiabeo requested a review from kt3k as a code owner April 9, 2023 15:39
@@ -65,6 +65,8 @@ const Z85 =
* @param [options.delimiter] whether to use a delimiter, if supported by encoding standard
*/
export function encode(uint8: Uint8Array, options?: Ascii85Options): string {
// Create a new Uint8Array from the given uint8 instead of using it
uint8 = new Uint8Array(uint8);
Copy link
Member

Choose a reason for hiding this comment

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

Can you try to fix the line const view = new DataView(uint8.buffer); instead of creating new uint8 array here. This causes unnecessary copy of underlying ArrayBuffer, and makes the function slower.

I think that line should be something like new DataView(uint8.buffer, uint8.byteOffset, uint8.byteLength).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your suggestion!

@kt3k
Copy link
Member

kt3k commented Apr 10, 2023

The test case looks good to me.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@kt3k kt3k merged commit 7d63d59 into denoland:main Apr 11, 2023
@babiabeo babiabeo deleted the fix-ascii85 branch April 11, 2023 10:23
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.

encoding/ascii85.ts: encode() returns a wrong result with a 4-byte subarray
2 participants