Repository navigation
Commit 5be57b7
committed
Fix SystemError when convert()'ing an out-of-range int to float
msgspec.convert(obj, float) converts a python int to a C double via
PyLong_AsDouble without checking for overflow. For an int too large to
represent as a float, PyLong_AsDouble sets OverflowError but still
returns -1.0, and that value was passed straight through to
ms_decode_float and returned to the interpreter with the exception
still set - which surfaces as SystemError: <built-in function convert>
returned a result with an exception set, bypassing the documented
ValidationError contract entirely.
json.decode already handles the equivalent case correctly, raising
ValidationError: Number out of range. Apply the same
value-error-with-path check convert() already uses elsewhere in this
file (e.g. _constr_as_f64) so the overflow is reported the same way,
for both bare and nested (e.g. dict[str, float]) targets, under both
strict and lax mode.
Fixes #1122.1 parent f51f378 commit 5be57b7
2 files changed
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20937 | 20937 | | |
20938 | 20938 | | |
20939 | 20939 | | |
20940 | | - | |
| 20940 | + | |
| 20941 | + | |
| 20942 | + | |
| 20943 | + | |
| 20944 | + | |
| 20945 | + | |
| 20946 | + | |
| 20947 | + | |
20941 | 20948 | | |
20942 | 20949 | | |
20943 | 20950 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
432 | 443 | | |
433 | 444 | | |
434 | 445 | | |
| |||
0 commit comments