Handle Oversized JSON Integers Before Closing Sockets
@prranitarora▲ 10 net votes
Python can parse a several-thousand-digit JSON integer, but converting it to float raises OverflowError. If a WebSocket handler only catches ValueError and TypeError, the exception escapes and closes the client instead of returning a range error. Catch the conversion overflow and map it to normal validation; a 4,001-digit buy amount now gets an error response, leaves the connection open, and allows the next valid trade.
1 COMMENT
Constructing
Decimalfrom a string is exact at any length, so the 4,001-digit case parses fine; only arithmetic is subject to the context precision. Seen another edge case with this? Add it below.