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

[BUG] Potential Unhandled exception in PolarisEntityResolver.java #327

Open
1 task done
dbosco opened this issue Sep 30, 2024 · 4 comments
Open
1 task done

[BUG] Potential Unhandled exception in PolarisEntityResolver.java #327

dbosco opened this issue Sep 30, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@dbosco
Copy link

dbosco commented Sep 30, 2024

Is this a possible security vulnerability?

  • This is NOT a possible security vulnerability

Describe the bug

In the following code:

PolarisEntityActiveRecord activeEntityRecord = activeRecordIt.next();

for (PolarisEntityCore resolveEntity : toResolve) {
  // get associate active record
  PolarisEntityActiveRecord activeEntityRecord = activeRecordIt.next();

  // if this entity has been dropped (null) or replaced (<> ids), then fail validation
  if (activeEntityRecord == null || activeEntityRecord.getId() != resolveEntity.getId()) {
    return false;
  }
}

If there are no elements in activeRecordIt, calling .next() will throw an exception before reaching the activeEntityRecord == null check.

Should we add a .hasNext() check before calling .next()?

If this is indeed an issue, it seems like a trivial fix, and I’d be happy to address it.

PolarisEntityActiveRecord activeEntityRecord = activeRecordIt.next();

` for (PolarisEntityCore resolveEntity : toResolve) {
// get associate active record
PolarisEntityActiveRecord activeEntityRecord = activeRecordIt.next();

  // if this entity has been dropped (null) or replaced (<> ids), then fail validation
  if (activeEntityRecord == null || activeEntityRecord.getId() != resolveEntity.getId()) {
    return false;
  }
}`

If there are no elements in activeRecordIt, then the .next() will throw an exception before reaching below.
activeEntityRecord == null
Should we check for .hasNext() before calling .next().

If it is indeed an issue, it seems to be an trivial fix and I am happy to do it. Please assign it to me.

To Reproduce

No response

Actual Behavior

No response

Expected Behavior

No response

Additional context

No response

System information

No response

@dbosco dbosco added the bug Something isn't working label Sep 30, 2024
@eric-maynard
Copy link
Contributor

I think the issue goes a little deeper than a missing hasNext. The code seems to assume that toResolve will always have the same length as activeRecordIt and that they will always be aligned (e.g. the Nth element in one corresponds to the Nth element in the other).

If this assumption is true, then we don't need the hasNext check, though we could maybe clarify this with a comment or improve readability.

If this assumption isn't true, the code needs to be fixed in more ways than with just a hasNext check.

I think the issue is this: whether or not the above assumption is true depends on the metastore implementation. Perhaps we could make lookupEntityActiveBatch return a Map, but I'm not sure whether or not we want to change the interface for this. Another approach we could take is adding a test to ensure the assumption is always true.

@dbosco
Copy link
Author

dbosco commented Oct 1, 2024

@eric-maynard yes your correct. Assuming, the below call returns everything in the same order and length, it should be fine.
// now lookup all these entities by name Iterator<PolarisEntityActiveRecord> activeRecordIt = ms.lookupEntityActiveBatch(callCtx, entityActiveKeys).iterator();
If there is anything you want me to do, then let know. Thanks

@eric-maynard
Copy link
Contributor

Personally I like the idea of making lookupEntityActiveBatch return a Map (or some other associative data structure) but I am probably more comfortable breaking APIs than some others. Without doing this, I'm not sure if there's any fix we can do right now.

@dbosco
Copy link
Author

dbosco commented Oct 10, 2024

@eric-maynard I agree, the risk is too low. We could close this for now and revisit this at a later time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants