The Wayback Machine - https://web.archive.org/web/20210913162507/https://github.com/SheetJS/sheetjs/issues/2316
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

ArrayBuffer not being supported correctly #2316

Open
codan84 opened this issue Jun 18, 2021 · 2 comments
Open

ArrayBuffer not being supported correctly #2316

codan84 opened this issue Jun 18, 2021 · 2 comments

Comments

@codan84
Copy link

@codan84 codan84 commented Jun 18, 2021

I believe there is a bug here:

if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), opts);

If the input data was an ArrayBuffer but opts would not have a type set we would essentially convert the ArrayBuffer to Uint8Array and call readSync again but without setting appropriate opts.type. This then leads to few lines below
if(!o.type) o.type = (has_buf && Buffer.isBuffer(data)) ? "buffer" : "base64";
setting opts.type to base64 which results in errors later on.
This can be replicated by using the library in a browser app, reading a file, using File.arrayBuffer (https://developer.mozilla.org/en-US/docs/Web/API/File) and passing this buffer as a source of data:

const onFileLoad = async (event) => {
    const file = event.target.files[0]
    file
      .arrayBuffer()
      .then(buffer => XLSX.read(buffer))
      .then(workbook => {/*do something with the file*/})
}

Easy fix (on line 69):

if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data),{...opts, type: 'array'});
@SheetJSDev
Copy link
Contributor

@SheetJSDev SheetJSDev commented Aug 14, 2021

ES6 issues aside (can't use spread), that looks reasonable and we'd accept a PR.

@mani9896
Copy link

@mani9896 mani9896 commented Aug 17, 2021

@SheetJSDev Hey can i work on this issue , if available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants