Commit ff45f3e
Fix undetected integer overflow when converting to Int64 on 32-bit
On 32-bit, the TypeCode.Int64 path uses PyLong_AsLongLong, whose wrapper
returns a nullable long? that is null when the Python int does not fit in a
long long (with a Python OverflowError left set). The overflow check compared
the nullable to -1 (`num == -1`), which is never true for null, so an
overflowing value bypassed the check and was returned as a successful
conversion with a null result.
Check num.HasValue instead so overflow propagates as a failed conversion.
This is why TestConverter.ConvertOverflow failed only on Windows x86: on x64
the Int64 case takes the else branch (PyLong_AsSignedSize_t, a 64-bit nint)
whose `num == -1 && ErrorOccurred()` check works correctly. The CI matrix only
builds x86 on Windows, so the 32-bit bug surfaced only there.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 97fbe85 commit ff45f3e
1 file changed
Lines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1151 | 1151 | | |
1152 | 1152 | | |
1153 | 1153 | | |
1154 | | - | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
1155 | 1161 | | |
1156 | 1162 | | |
1157 | 1163 | | |
1158 | | - | |
| 1164 | + | |
1159 | 1165 | | |
1160 | 1166 | | |
1161 | 1167 | | |
| |||
0 commit comments