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

Bug: RangeError: Invalid array length (and fix) #56

Open
7freaks-otte opened this issue Oct 8, 2024 · 0 comments
Open

Bug: RangeError: Invalid array length (and fix) #56

7freaks-otte opened this issue Oct 8, 2024 · 0 comments

Comments

@7freaks-otte
Copy link

7freaks-otte commented Oct 8, 2024

Affected Platform(s):

  • Web (Chrome)

Current Behavior

When sharing a 200MB ZIP-File Chrome fails with RangeError: Invalid array length at WebUtils.toByteArray (web-utils.js:7:27). This seems to work on iOS and macOS Safari without problems.

I don't know if this is a memory issue as the same code is working with smaller files without problems even on Chrome, but I found a simple fix:

Fix

If I replace the following code

    static toByteArray(base64Data) {
        const byteCharacters = atob(base64Data);
        const byteNumbers = new Array(byteCharacters.length);
        for (let i = 0; i < byteCharacters.length; i++) {
            byteNumbers[i] = byteCharacters.charCodeAt(i);
        }
        return new Uint8Array(byteNumbers);
    }

with

    static toByteArray(base64Data) {
        const byteCharacters = atob(base64Data);
        const byteNumbers = new Uint8Array(new ArrayBuffer(byteCharacters.length));
        for (let i = 0; i < byteCharacters.length; i++) {
            byteNumbers[i] = byteCharacters.charCodeAt(i);
        }
        return byteNumbers;
    }

sharing just works fine.

Note: The following one-liner (which seems even more straight forward) makes Chrome crash due to memory issues:

return Uint8Array.from(atob(base64Data), (v) => v.charCodeAt(0));
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

No branches or pull requests

1 participant