Git Product home page Git Product logo

Comments (8)

Dretch avatar Dretch commented on July 23, 2024

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.

shirmin avatar shirmin commented on July 23, 2024

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.

shirmin avatar shirmin commented on July 23, 2024

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.

dcodeIO avatar dcodeIO commented on July 23, 2024

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.

dcodeIO avatar dcodeIO commented on July 23, 2024

Finally also got the zero copy stuff for short inner message lengths working :)

from protobuf.js.

shirmin avatar shirmin commented on July 23, 2024

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.

Dretch avatar Dretch commented on July 23, 2024

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.

dcodeIO avatar dcodeIO commented on July 23, 2024

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.

2769a1f

from protobuf.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.