Comments (8)
I think I have run into the same bug. Here is a test case:
too-long-bug.proto:
message Foo {
required Bar bar = 1;
}
message Bar {
required string blah = 1;
}
too-long-bug.html:
<html>
<head>
<script src="http://raw.github.com/dcodeIO/Long.js/master/Long.js"></script>
<script src="http://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.js"></script>
<script src="http://raw.github.com/dcodeIO/ProtoBuf.js/master/ProtoBuf.js"></script>
<script type="text/javascript">
var builder = dcodeIO.ProtoBuf.protoFromFile("too-long-bug.proto");
var fooCls = builder.build("Foo");
var barCls = builder.build("Bar");
var foo = new fooCls(new barCls("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
var fooEncoded = foo.encode();
var fooDecoded = fooCls.decode(fooEncoded);
</script>
</head>
<body></body>
</html>
When the above file is opened in Chrome 26.0.1410.65 on OS X then the following javascript error occurs:
Uncaught Error: Illegal field id in Message .Bar#decode: 0
If the long string of "a...." is shorter (e.g. with a length of 3) then the error does not occur.
from protobuf.js.
I check the binary buffer of encoding message which contain field of another message type.
When the child message over 128 bytes, the package length encode to 0x80(if 128 bytes) which should be encode as 2 bytes(in Varints).
That's why exception occurs.
from protobuf.js.
I changed the ProtoBuf.js file to work temporarily, and hope author could fix it. Thanks.
from line: 1912
var bb = new ByteBuffer();
this.resolvedType.encode(value, bb);
var messageBytes = bb.offset;
buffer.writeVarint32(messageBytes);
buffer.append(bb);
} else {
// We should never end here
from protobuf.js.
Thank you everyone for pointing this out! I've implemented shirmin's fix and created a test case to ensure that it'll work from now on.
from protobuf.js.
Finally also got the zero copy stuff for short inner message lengths working :)
from protobuf.js.
I'm afraid the latest version still has bug here...
E:\nodejs\node_modules\protobufjs\node_modules\bytebuffer\ByteBuffer.js:582
throw("Cannot read uint8 from "+this+": Capacity overflow");
^
Cannot read uint8 from ByteBuffer(offset=770,markedOffset=-1,length=771,capacity
=771): Capacity overflow
from protobuf.js.
Thanks for fixing my test case. 👍
I concur with @shirmin that there is still an issue somewhere. My original test case is now fixed, but this new test case fails.
too-long-bug-2.proto:
message Foo {
required Bar bar = 1;
required Baz baz = 2;
}
message Bar {
required string blah = 1;
}
message Baz {
required string blah = 1;
}
too-long-bug-2.html:
<html>
<head>
<script src="http://raw.github.com/dcodeIO/Long.js/master/Long.js"></script>
<script src="http://raw.github.com/dcodeIO/ByteBuffer.js/master/ByteBuffer.js"></script>
<script src="http://raw.github.com/dcodeIO/ProtoBuf.js/master/ProtoBuf.js"></script>
<script type="text/javascript">
var str = "";
for (var i=0; i<200; i++) {
str += 'a';
}
var builder = dcodeIO.ProtoBuf.protoFromFile("too-long-bug-2.proto");
var fooCls = builder.build("Foo");
var barCls = builder.build("Bar");
var bazCls = builder.build("Baz");
var foo = new fooCls(new barCls(str), new bazCls(str));
var fooEncoded = foo.encode();
var fooDecoded = fooCls.decode(fooEncoded);
</script>
</head>
<body></body>
</html>
When the above file is opened in Chrome 26.0.1410.65 on OS X then the following javascript error occurs:
Error: Illegal field id in Message .Foo#decode: 25
I guess this is the same underlying issue, because it seems to be related to the size of child messages. Changing the size of the str variable in the above example (to say, 100) makes the issue go away.
from protobuf.js.
Ok, that's bad. I've reverted the zero copy stuff (it's actually not worth the trouble) and verified that your new test case works.
from protobuf.js.
Related Issues (20)
- Cannot read properties of undefined (reading 'indexOf')
- Missing valuesOptions in fromJSON parser function
- Sometimes a single message is split into two
- KeepCase should default to true HOT 1
- Typescript declarations are missing interfaces HOT 3
- fromObject is not takin all arguments. HOT 1
- pbjs gives "Error: duplicate name 'Http' in Namespace .google.api"
- feat: add support for absolute imports HOT 1
- Error on proto files with external dependencies on protobuf.js version: 7.2.6
- Generation of types.d.ts breaks when the types.js is too big
- pbts produces incorrect typings for `message Object`
- Version `7.2.6` breaks build and throws an error `Error: ENOENT: no such file or directory, open ...` HOT 2
- Editions Suport
- Error: invalid wire type 6 at offset 297 is reported in the parsing field
- decode(new Uint8Array(data)) RangeError: index out of range: 97045 + 1 > 97045 HOT 1
- glob < 9 pulls in insecure depedendency, inflight HOT 1
- how to define protofile for [[1, 2, 3]]
- [Bug]Can not encode the embedded "oneof" keywords issue with sparkplugB schema
- Does it support running on quickjs?
- Prototype Pollution vulnerability HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf.js.