Skip to content

[bug] decode throws RangeError on empty Uint8Array #198

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

Closed
mrl5 opened this issue Jan 19, 2022 · 2 comments · Fixed by #209
Closed

[bug] decode throws RangeError on empty Uint8Array #198

mrl5 opened this issue Jan 19, 2022 · 2 comments · Fixed by #209

Comments

@mrl5
Copy link

mrl5 commented Jan 19, 2022

decode() throws RangeError on empty Uint8Array

steps to reproduce

const { decode } = require("@msgpack/msgpack");

decode(new Uint8Array());

expected result

hmm hard to tell, maybe null or undefined.

decode(encode());

returns null

actual result

Uncaught RangeError: Offset is outside the bounds of the DataView
    at DataView.getUint8 (<anonymous>)
    at Decoder.readU8 (/home/kuba/tmp_/node_modules/@msgpack/msgpack/dist/Decoder.js:532:33)
    at Decoder.readHeadByte (/home/kuba/tmp_/node_modules/@msgpack/msgpack/dist/Decoder.js:425:34)
    at Decoder.doDecodeSync (/home/kuba/tmp_/node_modules/@msgpack/msgpack/dist/Decoder.js:169:35)
    at Decoder.decode (/home/kuba/tmp_/node_modules/@msgpack/msgpack/dist/Decoder.js:89:29)
    at decode (/home/kuba/tmp_/node_modules/@msgpack/msgpack/dist/decode.js:14:20)
@mrl5
Copy link
Author

mrl5 commented Jan 19, 2022

workaround is to check if length > 0 and then decode()

@gfx
Copy link
Member

gfx commented May 1, 2022

This is an expected behavior, as JSON.parse("") raises a SyntaxError.

I've clarified the behavior in #209 by adding test cases to make sure this behavior.

fwcd added a commit to ProjectLighthouseCAU/nighthouse that referenced this issue Aug 11, 2022
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 a pull request may close this issue.

2 participants