Fix crash caused by passing a large integer to ctime()

In addition to verifying the return value of localtime(), correct tm_year if it is out of bounds

Reported by @JDowny