capnproto-java
capnproto-java copied to clipboard
StructList size should be checked and throw an exception
When using a StructList the size is not checked when adding new entries. For example:
StructList.Builder<PhoneNumber.Builder> personPhones
= person.initPhones(0);
personPhones.get(0).setNumber("08031/12345");
personPhones.get(0).setType(PhoneType.WORK);
personPhones.get(1).setNumber("0160/9876543");
personPhones.get(1).setType(PhoneType.MOBILE);
Will give no error or exception but the data is not written.
Or worste if you have a bit of space:
StructList.Builder<PhoneNumber.Builder> personPhones
= person.initPhones(1);
personPhones.get(0).setNumber("08031/12345");
personPhones.get(0).setType(PhoneType.WORK);
personPhones.get(1).setNumber("0160/9876543");
personPhones.get(1).setType(PhoneType.MOBILE);
You get the following:
work phone: 031/12
So your data is destroyed.
In both cases I would expect an exception.
There's a related issue: indexes aren't checked on reading either. So you can get a C++ style out of bounds read when reading lists! This is not intuitive.