fix: raise ValidationError for out-of-range int→float in convert - #1129
Closed
Solaris-star wants to merge 1 commit into
Closed
fix: raise ValidationError for out-of-range int→float in convert#1129Solaris-star wants to merge 1 commit into
Solaris-star wants to merge 1 commit into
Conversation
PyLong_AsDouble sets OverflowError for ints outside the finite double range. convert_int previously passed that value straight into ms_decode_float without checking PyErr_Occurred, which leaked a SystemError to callers. Surface the same "Number out of range" ValidationError that json.decode already uses. Fixes #1122
Solaris-star
had a problem deploying
to
docs-preview
July 21, 2026 03:41 — with
GitHub Actions
Failure
Member
|
There is already a PR attached to this: #1128. If you have suggestions for a different way to fix it, please attach them to that PR. |
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.
Summary
msgspec.convert(big_int, float)for integers outside the finite double range leaked aSystemError(<built-in function convert> returned a result with an exception set) instead of raisingmsgspec.ValidationError.Root cause:
convert_intcalledPyLong_AsDouble(obj)and passed the result intoms_decode_floatwithout checkingPyErr_Occurred(). When the C conversion overflows, Python setsOverflowErrorbut the unchecked path still returns a value, and the interpreter surfaces that asSystemError.json.decodealready reports the same case asValidationError: Number out of range.Fix
In
convert_int'sMS_TYPE_FLOATbranch:PyLong_AsDouble(obj)x == -1.0 && PyErr_Occurred(), clear the exception and returnms_error_with_path("Number out of range%U", path)Test plan
pytest tests/unit/test_convert.py::TestFloat -q→ 8 passedconvert(10**400, float)and nesteddict[str, float]raiseValidationError: Number out of rangeconvert(5, float) == 5.0still worksjson.decode(str(10**400).encode(), type=float)error class/messageFixes #1122