[#2212] CID56258:

move up the check for filesize bounds, return -1 on error
[#2212] CID56257:

check return value of mkstemp before passing it to fdopen