Skip to content

fix(number validation): Don't target NaN, Infinity, -Infinity, or > 2^53 #228

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

Merged
merged 5 commits into from
Nov 5, 2018

Conversation

msohailhussain
Copy link
Contributor

No description provided.

Copy link
Contributor

@thomaszurkan-optimizely thomaszurkan-optimizely left a comment

Choose a reason for hiding this comment

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

LGTM

@Test
public void gtMatchConditionEvaluatesNullWithInvalidAttr() throws Exception {
BigInteger bigInteger = new BigInteger("33221312312312312");
Double infiniteDouble = 1.2/0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically this evaluates to NaN, not infinity. It's probably cleaner use Double.NaN, Double.POSITIVE_INFINITY, and Double.NEGATIVE_INFINITY where needed

@@ -72,6 +70,16 @@ else if (conditionValue instanceof Boolean) {
return new MatchType(matchType, new NullMatch());
}

private static boolean isValidNumber(Object conditionValue) {
if (conditionValue instanceof Integer || conditionValue instanceof Double) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If conditionValue instanceof Integer, can we also add a restriction that Math.abs(value) <= 1e53? Technically it's unnecessary since Java ints can't be that large, but since this is a reference SDK, it might be helpful to set an example for other SDKs.

@coveralls
Copy link

coveralls commented Oct 17, 2018

Pull Request Test Coverage Report for Build 722

  • 11 of 13 (84.62%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.04%) to 89.226%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core-api/src/main/java/com/optimizely/ab/internal/EventTagUtils.java 1 3 33.33%
Totals Coverage Status
Change from base Build 719: -0.04%
Covered Lines: 2501
Relevant Lines: 2803

💛 - Coveralls

@nchilada
Copy link
Contributor

@msohailhussain do you know when you might be able to merge this? @mikeng13 it might be nice to get this into the first official 3.0 release.

Copy link
Contributor

@loganlinn loganlinn left a comment

Choose a reason for hiding this comment

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

minor suggestion to simplify statements

return true;
} else if (conditionValue instanceof Double) {
Double value = ((Number) conditionValue).doubleValue();
if (value.isNaN() || value.isInfinite()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (value.isNaN() || value.isInfinite()) {
return !(value.isNaN() || value.isInfinite());

@@ -72,6 +70,21 @@ else if (conditionValue instanceof Boolean) {
return new MatchType(matchType, new NullMatch());
}

private static boolean isValidNumber(Object conditionValue) {
if (conditionValue instanceof Integer) {
if (Math.abs((Integer) conditionValue) > 1e53) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (Math.abs((Integer) conditionValue) > 1e53) {
return Math.abs((Integer) conditionValue) <= 1e53;

@mikeproeng37 mikeproeng37 merged commit 1e90b56 into master Nov 5, 2018
@nchilada nchilada deleted the mnoman/ValidAttrInfiniteCheck branch November 5, 2018 23:02
@nchilada nchilada changed the title fix(NaN/Ifinity): Don't target/track NaN, Infinity, or -Infinity fix(NaN/Infinity): Don't target NaN, Infinity, or -Infinity Jan 15, 2019
@nchilada nchilada changed the title fix(NaN/Infinity): Don't target NaN, Infinity, or -Infinity fix(number validation): Don't target NaN, Infinity, -Infinity, or > 2^53 Jan 15, 2019
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.

7 participants