Skip to content

decode() fails silently when passing in a wrong type #695

@tomergg

Description

@tomergg

protobuf.js version: 6.6.5

When passing in a ByteBuffer instead of a Uint8Array, decode fails silently and return an "empty" message. Calling toObject on the message will return an empty object. The expected is to validate the input parameters and throw an exception if it's of an invalid type.

try {
  const pbNotifications = pbRoot.lookup('Notifications');
  const data = new ByteBuffer(...);
  const notification = pbNotifications.Notification.decode(data).toObject();
} catch (error) {
  logger(error);
}

As a side note. I came across this bug after switching from v5 to v6. A part of the code, where the test coverage was not ideal, was failing silently. It was only discovered at functional QA time.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions