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

minimum/maximum validation of integral numbers prone to overflow #132

Closed
kosty opened this issue Apr 8, 2019 · 1 comment
Closed

minimum/maximum validation of integral numbers prone to overflow #132

kosty opened this issue Apr 8, 2019 · 1 comment

Comments

@kosty
Copy link
Contributor

kosty commented Apr 8, 2019

Description

Currently both MaximumValidator and MinimumValidator both rely on double as their base type. This causes some omissions for integer numbers, e.g. 9223372036854775807 and 9223372036854775806 are both rounded up to 9223372036854776000 which leads to bug in validation when former is the value validated and latter is the maximum threshold in schema. Corresponding issues is demonstrated by -9223372036854775808 and -9223372036854775807 for minimum.

Sample test

    @Test
    public void testIntegralMaximum() throws IOException {
        ObjectMapper m = new ObjectMapper();

        String schema = "{ \"$schema\":\"http://json-schema.org/draft-04/schema#\", \"type\": \"integer\", \"maximum\": 9223372036854775806 }";
        JsonSchema v = JsonSchemaFactory.getInstance().getSchema(m.readTree(schema));
        JsonNode doc = m.readTree("9223372036854775807");

        Set<ValidationMessage> messages = v.validate(doc);
        assertFalse(messages.isEmpty());
    }

Notes

Since json-schema-validator is optimized for speed of validation, conditional statements inside validate method are not desirable. Similarly, comparison of primitive numeric types is preferred to BigInteger / BigDecimal.

@stevehu
Copy link
Contributor

stevehu commented Apr 10, 2019

@stevehu @jiachen1120 Thanks a lot for the effort. I have released a new version 1.0.6 minutes ago and upgraded light-4j framework with the new version with light-bot.

https://github.com/networknt/json-schema-validator/releases

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