Skip to content

Commit a2a52b1

Browse files
committed
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.
1 parent c12b0db commit a2a52b1

File tree

8 files changed

+96
-0
lines changed

8 files changed

+96
-0
lines changed

tests/draft2019-09/multipleOf.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,16 @@
5656
"valid": false
5757
}
5858
]
59+
},
60+
{
61+
"description": "invalid instance which must not raise an overflow error when float division = inf",
62+
"schema": {"type": "integer", "multipleOf": 0.123456789},
63+
"tests": [
64+
{
65+
"description": "This should always be invalid, but naive implementations may raise an overflow error",
66+
"data": 1e308,
67+
"valid": false
68+
}
69+
]
5970
}
6071
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity",
4+
"schema": {"type": "integer", "multipleOf": 0.5},
5+
"tests": [
6+
{
7+
"description": "The spec allows this to be valid OR invalid depending on your overflow handling.",
8+
"data": 1e308,
9+
"valid": true
10+
}
11+
]
12+
}
13+
]

tests/draft4/multipleOf.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,16 @@
5656
"valid": false
5757
}
5858
]
59+
},
60+
{
61+
"description": "invalid instance which must not raise an overflow error when float division = inf",
62+
"schema": {"type": "integer", "multipleOf": 0.123456789},
63+
"tests": [
64+
{
65+
"description": "This should always be invalid, but naive implementations may raise an overflow error",
66+
"data": 1e308,
67+
"valid": false
68+
}
69+
]
5970
}
6071
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity",
4+
"schema": {"type": "integer", "multipleOf": 0.5},
5+
"tests": [
6+
{
7+
"description": "The spec allows this to be valid OR invalid depending on your overflow handling.",
8+
"data": 1e308,
9+
"valid": true
10+
}
11+
]
12+
}
13+
]

tests/draft6/multipleOf.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,16 @@
5656
"valid": false
5757
}
5858
]
59+
},
60+
{
61+
"description": "invalid instance which must not raise an overflow error when float division = inf",
62+
"schema": {"type": "integer", "multipleOf": 0.123456789},
63+
"tests": [
64+
{
65+
"description": "This should always be invalid, but naive implementations may raise an overflow error",
66+
"data": 1e308,
67+
"valid": false
68+
}
69+
]
5970
}
6071
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity",
4+
"schema": {"type": "integer", "multipleOf": 0.5},
5+
"tests": [
6+
{
7+
"description": "The spec allows this to be valid OR invalid depending on your overflow handling.",
8+
"data": 1e308,
9+
"valid": true
10+
}
11+
]
12+
}
13+
]

tests/draft7/multipleOf.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,16 @@
5656
"valid": false
5757
}
5858
]
59+
},
60+
{
61+
"description": "invalid instance which must not raise an overflow error when float division = inf",
62+
"schema": {"type": "integer", "multipleOf": 0.123456789},
63+
"tests": [
64+
{
65+
"description": "This should always be invalid, but naive implementations may raise an overflow error",
66+
"data": 1e308,
67+
"valid": false
68+
}
69+
]
5970
}
6071
]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"description": "integer with multipleOf=0.5 may be valid but never raises error despite naive overflow to infinity",
4+
"schema": {"type": "integer", "multipleOf": 0.5},
5+
"tests": [
6+
{
7+
"description": "The spec allows this to be valid OR invalid depending on your overflow handling.",
8+
"data": 1e308,
9+
"valid": true
10+
}
11+
]
12+
}
13+
]

0 commit comments

Comments
 (0)