Skip to content

[bug] decode throws RangeError on empty Uint8Array #198

Closed

Description

@mrl5

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)

Activity

  1. mrl5 commented on Jan 19, 2022

    @mrl5
    Author

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

  2. gfx commented on May 1, 2022

    @gfx
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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