Giter Club home page Giter Club logo

Comments (4)

jdiaz5513 avatar jdiaz5513 commented on July 26, 2024 1

from capnp-ts.

jdiaz5513 avatar jdiaz5513 commented on July 26, 2024

Can you attach the following:

  • first version of capnp file
  • second (failing) version of capnp file
  • dumped message

Please scrub any potentially sensitive information.

from capnp-ts.

smoreinis avatar smoreinis commented on July 26, 2024

I'd rather not share the exact capnp schema I'm working on so I made a simple example to reproduce the issue I've been seeing. Although I initially reported an issue trying to read the newly added field in the new schema version, below I've shown issues even trying to read the old field in the new schema version (which seem related). Let me know if there's anything else I can help with!

Here's foo.capnp (first version):

@0xe0b7ff464fbc7ee1;
struct Foo {
  bar @0 :Text;
}

Here's foo_new.capnp (with a new text field added at the end):

@0xe0b7ff464fbc7ee1;
struct Foo {
  bar @0 :Text;
  baz @1 :Text;
}

Here's some failing code which tries to serialize an old foo message and deserialize it as the new foo message:

  const OldFoo = require('./foo.capnp.js').Foo
  const NewFoo = require('./foo_new.capnp.js').Foo

  const oldMessage = new capnp.Message()
  const oldFoo = oldMessage.initRoot(OldFoo)
  oldFoo.setBar("bar")
  const packed = Buffer.from(oldMessage.toPackedArrayBuffer())
  console.log(packed.toString('base64'))

  const newMessage = capnp.Message.fromPackedBuffer(packed)
  const newFoo = newMessage.getRoot(NewFoo)
  console.log(newFoo.getBar())

The serialized packed message in base64 is EANAAREBIgdiYXI= and I get an error trying to read the old field from the new message: Error: CAPNP-TS024 Attempted to convert pointer Pointer_1@0x00000010,[fc ff ff ff 00 00 02 00],limit:0x7ffffffe to a 1 type. although this doesn't seem to trigger the struct resize I mentioned originally.

Here's a slightly more complicated foo.capnp (first version):

@0xe0b7ff464fbc7ee1;
struct Foo {
  bar @0 :Bar;
}
struct Bar {
  one @0 :Text;
}

Here's foo_new.capnp (with a new text field added at the end):

@0xe0b7ff464fbc7ee1;
struct Foo {
  bar @0 :Bar;
}
struct Bar {
  one @0 :Text;
  two @1 :Text;
}

And here's some failing code which tries to serialize an old foo message and deserialize it as the new foo message:

  const OldFoo = require('./foo.capnp.js').Foo
  const NewFoo = require('./foo_new.capnp.js').Foo

  const oldMessage = new capnp.Message()
  const oldFoo = oldMessage.initRoot(OldFoo)
  oldFoo.getBar().setOne("one")
  const packed = Buffer.from(oldMessage.toPackedArrayBuffer())
  console.log(packed.toString('base64'))

  const newMessage = capnp.Message.fromPackedBuffer(packed)
  const newFoo = newMessage.getRoot(NewFoo)
  console.log(newFoo.getBar().getOne())

The serialized packed message in base64 is EARAAUABEQEiB29uZQ== and this does trigger the struct resize but fails again when trying to read the old field: Error: CAPNP-TS024 Attempted to convert pointer Pointer_1@0x00000010,[fc ff ff ff 00 00 02 00],limit:0x7ffffffd to a 1 type.

from capnp-ts.

jdiaz5513 avatar jdiaz5513 commented on July 26, 2024

Both of these cases trigger pathological far pointer behavior, which admittedly was poorly tested.

Patch incoming along with a pretty big refactor.

from capnp-ts.

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.