diff --git a/packages/ani-cursor/CHANGELOG.md b/packages/ani-cursor/CHANGELOG.md index 3e4e7a36..b97f3d56 100644 --- a/packages/ani-cursor/CHANGELOG.md +++ b/packages/ani-cursor/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog for `ani-cursor` +## Next (unreleased) + +### Bug Fixes + +* Prevent "Maximum call stack size exceeded" error when parsing large cursors. + ## 0.0.5 ### Bug Fixes diff --git a/packages/ani-cursor/src/index.ts b/packages/ani-cursor/src/index.ts index a1f5393e..4fc472ca 100644 --- a/packages/ani-cursor/src/index.ts +++ b/packages/ani-cursor/src/index.ts @@ -79,8 +79,12 @@ function readAni(contents: Uint8Array): AniCursorImage { let i = 0; const uniqueId = () => i++; -function base64FromDataArray(dataArray: Uint8Array): string { - return window.btoa(String.fromCharCode(...dataArray)); +export function base64FromDataArray(dataArray: Uint8Array): string { + return window.btoa( + Array.from(dataArray) + .map((byte) => String.fromCharCode(byte)) + .join("") + ); } function curUrlFromByteArray(arr: Uint8Array) { diff --git a/packages/webamp/CHANGELOG.md b/packages/webamp/CHANGELOG.md index 58683693..ee17447b 100644 --- a/packages/webamp/CHANGELOG.md +++ b/packages/webamp/CHANGELOG.md @@ -9,6 +9,7 @@ - Fix a number of edge cases where the close and minimize buttons in the equalizer window could render the wrong sprite [#1046](https://github.com/captbaritone/webamp/pull/1046) - Fix a bug where unminified bundle was accidentally minified. - Treat skin files with forward slashes in their filename as directories [#1052](https://github.com/captbaritone/webamp/pull/1052) +- Prevent "Maximum call stack size exceeded" error when parsing large cursors. ## 1.4.2 diff --git a/packages/webamp/js/utils.ts b/packages/webamp/js/utils.ts index 9027640c..bbaff5ce 100644 --- a/packages/webamp/js/utils.ts +++ b/packages/webamp/js/utils.ts @@ -132,9 +132,13 @@ export const clamp = (value: number, min: number, max: number): number => export const sum = (values: number[]): number => values.reduce((total, value) => total + value, 0); -export const base64FromDataArray = (dataArray: Uint8Array): string => { - return window.btoa(String.fromCharCode(...dataArray)); -}; +export function base64FromDataArray(dataArray: Uint8Array): string { + return window.btoa( + Array.from(dataArray) + .map((byte) => String.fromCharCode(byte)) + .join("") + ); +} export const base64FromArrayBuffer = (arrayBuffer: ArrayBuffer): string => { return base64FromDataArray(new Uint8Array(arrayBuffer));