Skip to content
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

Bytes/repeated value not parsed, RangeError #513

Closed
aman-tiwari opened this issue Dec 2, 2016 · 2 comments
Closed

Bytes/repeated value not parsed, RangeError #513

aman-tiwari opened this issue Dec 2, 2016 · 2 comments
Labels

Comments

@aman-tiwari
Copy link

aman-tiwari commented Dec 2, 2016

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)

@aman-tiwari aman-tiwari changed the title Bytes/repeated value not parsed correctly, RangeError Bytes/repeated value not parsed, RangeError Dec 2, 2016
@dcodeIO
Copy link
Member

dcodeIO commented Dec 2, 2016

Seems that there is an issue with packed repeated fields with float / double types.

Can you try to inject the following right before loading your proto?

protobuf.types.packed.double = 1;
protobuf.types.packed.float = 5;

Please let me know if this fixes your issue.

@dcodeIO dcodeIO added the bug label Dec 2, 2016
dcodeIO added a commit that referenced this issue Dec 2, 2016
@aman-tiwari
Copy link
Author

That seems to fix it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants