Skip to content

Maximum call stack size exceeded triggered by importImageFileToBase64 #47

@fetimo

Description

@fetimo

Hello!

When passing an ArrayBuffer to scribe.importFiles it throws RangeError: Maximum call stack size exceeded.

My test buffer is 236087 bytes (~236 KB) which isn't massive but I'm running on a shared hosting environment (Vercel) and I suspect that has something to do with it. It works locally with much larger files so I think it is impacted by the environment it's running in.

The line that seems to be causing it is

const binary = String.fromCharCode(...imageUint8);

I believe that because it's spreading in the array it's assigning a lot of resources quickly and is less efficient than some alternatives, like:

const imageUint8 = new Uint8Array(file.buffer, file.byteOffset, file.byteLength);

// Detect format from just the header
const format = detectImageFormat(file.subarray(0, 64));

const binary = file.toString('latin1');

resolve(`data:image/${format};base64,${btoa(binary)}`);
return;

Thanks for your time!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions