Repository navigation
Conversation
The generated range checks fail a value only when it compares past the
bound, for example `if data < 1`. Every comparison with NaN is false, so
NaN passed minimum, maximum, exclusiveMinimum and exclusiveMaximum in
all drafts. json.loads accepts NaN by default, so a schema such as
{"type": "number", "minimum": 1, "maximum": 100} accepted
json.loads('NaN').
Generate the checks as `if not data >= 1` and so on, so a value has to
compare inside the bound to pass. The bytecode is the same length, the
`not` only flips the jump.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
minimum,maximumand the exclusive bounds accept NaNThe generated checks raise only when the value compares past the bound (
if data < 1), and every comparison with NaN is false.json.loads(and so Flask'srequest.get_json()) accepts theNaNliteral by default:The same happens with
exclusiveMinimum/exclusiveMaximumin every draft. Code that relies on the schema for the range then gets a value for whichamount > balanceandamount <= 0are both false.The checks are now generated as
if not data >= 1and so on, so a value has to compare inside the bound to pass. Over 1200 value/schema combinations (ints, floats, infinity,Decimal, each keyword in draft 04 and 07) the only results that change are float NaN going from accepted to rejected, and the bytecode is the same length (thenotonly flips the jump). The new test intests/test_number.pyfails onmasterand passes here, the full suite passes on Python 3.11 and 3.13, and pylint output is unchanged.CHANGELOG.txthas an entry under UNRELEASED.