Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StructList size should be checked and throw an exception #25

Open
a-zen opened this issue Mar 10, 2015 · 1 comment
Open

StructList size should be checked and throw an exception #25

a-zen opened this issue Mar 10, 2015 · 1 comment

Comments

@a-zen
Copy link

a-zen commented Mar 10, 2015

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.

@mikehearn
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants