Skip to content

Commit

Permalink
add a test that triggers buffer overflow on the previous version of s…
Browse files Browse the repository at this point in the history
…etDataPointer()
  • Loading branch information
dwrensha committed Oct 22, 2024
1 parent 28ab5ce commit cfea947
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions compiler/src/test/java/org/capnproto/test/EncodingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -943,4 +943,21 @@ public void testZeroPointerUnderflow() throws DecodeException {
Assert.assertEquals(0L, outputSegments[0].getLong((2 + ii) * 8));
}
}

// This test fails on https://github.com/capnproto/capnproto-java/pull/143,
// illustrating why https://github.com/capnproto/capnproto-java/commit/28ab5ced
// is needed.
@org.junit.Test
public void setDataPointer() {
MessageBuilder message1 = new MessageBuilder();
Test.TestAllTypes.Builder allTypes1 = message1.initRoot(Test.TestAllTypes.factory);
TestUtil.initTestMessage(allTypes1);
MessageBuilder message2 = new MessageBuilder();
Test.TestAllTypes.Builder allTypes2 = message2.initRoot(Test.TestAllTypes.factory);
TestUtil.initTestMessage(allTypes2);

allTypes1.setDataField(allTypes2.asReader().getDataField());
TestUtil.checkTestMessage(allTypes1);
TestUtil.checkTestMessage(allTypes1.asReader());
}
}

0 comments on commit cfea947

Please sign in to comment.