Skip to content

Honor length in Tuple.fromBytes if provided#363

Merged
ajbeamon merged 2 commits intoapple:release-5.2from
alecgrieser:362-honor-length-in-from-bytes
May 10, 2018
Merged

Honor length in Tuple.fromBytes if provided#363
ajbeamon merged 2 commits intoapple:release-5.2from
alecgrieser:362-honor-length-in-from-bytes

Conversation

@alecgrieser
Copy link
Contributor

In Tuple unpack, we were looping until the end of the array rather than to the end of where the user specified. This fixes that. It now passes the little quick test I added within Tuple.java, but testing this more thoroughly would probably require more work in other places.

It also looks like the TLS related network options that were just added to fdb.options weren't added to the generated.go file, so I fixed that (in a separate commit).

This closes #362.

@alecgrieser alecgrieser modified the milestone: 5.2 May 10, 2018
@alecgrieser alecgrieser force-pushed the 362-honor-length-in-from-bytes branch from f2e7491 to e537808 Compare May 10, 2018 22:27
int pos = start;
int end = start + length;
while(pos < bytes.length) {
while(pos < end) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if end is past the end of the bytes array?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, you will get an ArrayIndexOutOfBoundsException on line 351 of TupleUtil when it tries do decode the value out of range:

Arguably, the correct thing is for this method (unpack) to do bounds checking early and then exit right then. I could add that, if we want.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the rest of the Tuple layer do? If it behaves similarly to this, we can leave it and address it later as a whole if we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it generally does bounds checking at the last possible moment (i.e., when it gets the ArrayIndexOutOfBoundsException. That leads to another problem, which is that the decode logic for, say, floats will not necessarily do the right thing. For example:

Tuple.fromBytes(Tuple.from(3.14f).pack(), 0, 3)

will return (3.14f) rather than throwing an error (because it doesn't check that the item is entirely located within the correct range). I think all of the fixed length types are like that, but the variable length things will stop before hitting their terminator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, as we discussed a bit offline, I think we'll go ahead and merge this. If we want, we can raise a new issue to address the concern you just raised.

@ajbeamon ajbeamon merged commit 82a1938 into apple:release-5.2 May 10, 2018
sfc-gh-jfu pushed a commit to sfc-gh-jfu/foundationdb that referenced this pull request Jul 20, 2023
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

Successfully merging this pull request may close these issues.

2 participants