Skip to content

Bytes/repeated value not parsed, RangeError #513

@aman-tiwari

Description

@aman-tiwari

Ran into this whilst trying to parse the TensorProtos produced by Tensorflow.
For an example, Tensorflow returns the following protobuf (tensor_shape.dim.size is an int64) for a 1x1 tensor of type float that has value 3.0:
dtype: DT_FLOAT tensor_shape { dim { size: 1 } dim { size: 1 } } float_val: 3.0
with binary encoding as:
[8, 1, 18, 8, 18, 2, 8, 1, 18, 2, 8, 1, 42, 4, 0, 0, 64, 64], in hex:
'0x8 0x1 0x12 0x8 0x12 0x2 0x8 0x1 0x12 0x2 0x8 0x1 0x2a 0x4 0x0 0x0 0x40 0x40
When parsing this with protobufjs 6.0.0, I get RangeError: index out of range: 18 + 1 > 18

However, when parsing with protobufjs 5, the message is parsed correctly.

If I modify TensorProto to be

message TensorProto2 {
  DataType dtype = 1;
  TensorShapeProto tensor_shape = 2;
  int32 version_number = 3;

  bytes tensor_content = 4;

  //repeated float float_val = 5 [packed = true];
}

The message is parsed correctly (but missing the floatVal, as it's been commented out)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions