Prevent int overflow in isolate when handling memory limits