From a2a52b14b5e2797224ee52ad646504aebce61136 Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Sat, 3 Oct 2020 14:04:52 +1000 Subject: [PATCH] Check for multipleOf overflow The spec says that instances are valid if "dividing by this value results in an integer". This allows integers to be invalid for `multipleOf: 0.5` if float division overflows to infinity (a non-integer); alternatively implementations may choose to implement logic which defines all integers as multiples of 0.5. Either way, however, implementations must not raise an error due to the overflow of a legal value against a legal schema. --- tests/draft2019-09/multipleOf.json | 11 +++++++++++ tests/draft2019-09/optional/float-overflow.json | 13 +++++++++++++ tests/draft4/multipleOf.json | 11 +++++++++++ tests/draft4/optional/float-overflow.json | 13 +++++++++++++ tests/draft6/multipleOf.json | 11 +++++++++++ tests/draft6/optional/float-overflow.json | 13 +++++++++++++ tests/draft7/multipleOf.json | 11 +++++++++++ tests/draft7/optional/float-overflow.json | 13 +++++++++++++ 8 files changed, 96 insertions(+) create mode 100644 tests/draft2019-09/optional/float-overflow.json create mode 100644 tests/draft4/optional/float-overflow.json create mode 100644 tests/draft6/optional/float-overflow.json create mode 100644 tests/draft7/optional/float-overflow.json diff --git a/tests/draft2019-09/multipleOf.json b/tests/draft2019-09/multipleOf.json index ca3b7618..b0cf3c50 100644 --- a/tests/draft2019-09/multipleOf.json +++ b/tests/draft2019-09/multipleOf.json @@ -56,5 +56,16 @@ "valid": false } ] + }, + { + "description": "invalid instance which must not raise an overflow error when float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "This should always be invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] } ] diff --git a/tests/draft2019-09/optional/float-overflow.json b/tests/draft2019-09/optional/float-overflow.json new file mode 100644 index 00000000..c29b796e --- /dev/null +++ b/tests/draft2019-09/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "The spec allows this to be valid OR invalid depending on your overflow handling.", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft4/multipleOf.json b/tests/draft4/multipleOf.json index ca3b7618..b0cf3c50 100644 --- a/tests/draft4/multipleOf.json +++ b/tests/draft4/multipleOf.json @@ -56,5 +56,16 @@ "valid": false } ] + }, + { + "description": "invalid instance which must not raise an overflow error when float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "This should always be invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] } ] diff --git a/tests/draft4/optional/float-overflow.json b/tests/draft4/optional/float-overflow.json new file mode 100644 index 00000000..c29b796e --- /dev/null +++ b/tests/draft4/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "The spec allows this to be valid OR invalid depending on your overflow handling.", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft6/multipleOf.json b/tests/draft6/multipleOf.json index ca3b7618..b0cf3c50 100644 --- a/tests/draft6/multipleOf.json +++ b/tests/draft6/multipleOf.json @@ -56,5 +56,16 @@ "valid": false } ] + }, + { + "description": "invalid instance which must not raise an overflow error when float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "This should always be invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] } ] diff --git a/tests/draft6/optional/float-overflow.json b/tests/draft6/optional/float-overflow.json new file mode 100644 index 00000000..c29b796e --- /dev/null +++ b/tests/draft6/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "The spec allows this to be valid OR invalid depending on your overflow handling.", + "data": 1e308, + "valid": true + } + ] + } +] diff --git a/tests/draft7/multipleOf.json b/tests/draft7/multipleOf.json index ca3b7618..b0cf3c50 100644 --- a/tests/draft7/multipleOf.json +++ b/tests/draft7/multipleOf.json @@ -56,5 +56,16 @@ "valid": false } ] + }, + { + "description": "invalid instance which must not raise an overflow error when float division = inf", + "schema": {"type": "integer", "multipleOf": 0.123456789}, + "tests": [ + { + "description": "This should always be invalid, but naive implementations may raise an overflow error", + "data": 1e308, + "valid": false + } + ] } ] diff --git a/tests/draft7/optional/float-overflow.json b/tests/draft7/optional/float-overflow.json new file mode 100644 index 00000000..c29b796e --- /dev/null +++ b/tests/draft7/optional/float-overflow.json @@ -0,0 +1,13 @@ +[ + { + "description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity", + "schema": {"type": "integer", "multipleOf": 0.5}, + "tests": [ + { + "description": "The spec allows this to be valid OR invalid depending on your overflow handling.", + "data": 1e308, + "valid": true + } + ] + } +]