Skip to content

Possible divide by zero bugs when using RandomValuePropertySource #26628

@yiyuaner

Description

@yiyuaner

In the class RandomValuePropertySource, we have the following code:

private long getNextLongInRange(String range) {
    String[] tokens = StringUtils.commaDelimitedListToStringArray(range);
    if (tokens.length == 1) {
        // divisor may be zero here!
        return Math.abs(getSource().nextLong() % Long.parseLong(tokens[0])); 
    }
    long lowerBound = Long.parseLong(tokens[0]);
    long upperBound = Long.parseLong(tokens[1]) - lowerBound;
    // divisor may be zero here!
    return lowerBound + Math.abs(getSource().nextLong() % upperBound);
}

If the string tokens parsed from range contain 0 or tokens[0].equals(tokens[1]), we will encounter two divide by zero problems in the above code.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions