Skip to content

The decoding/fromBuffer fails and crashes with this "complex" structure #64

@ItzSiL3Nce

Description

@ItzSiL3Nce

Given this structure:

const PacketFromRestructure = new r.Struct({
  i: r.uint32,
  a: new r.Array(r.uint32),
  sub: new r.Struct({
    subI: r.uint32,
    subArray: new r.Array(r.uint32)
  })
})

The encoding/toBuffer part works fine:

const encoded = PacketFromRestructure.toBuffer({
  i: 0,
  a: [1, 2],
  sub: { subArray: [1, 2, 3], subI: 2 }
})

But its decoding/fromBuffer fails and crashes:

const decoded = PacketFromRestructure.fromBuffer(encoded)

The crash:

node_modules\restructure\dist\src\DecodeStream.js:72
      const ret = this.view[key](this.pos, false);
                                ^
RangeError: Offset is outside the bounds of the DataView
    at DataView.prototype.getUint32 (<anonymous>)
    at $8ae20583b93e4933$export$c18b354bac7948e9.<computed> [as readUInt32BE]
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions