Fix earlier fix for PHP-375

Properly validate the types of the variables we are working with to
avoid invalid reads.
Also bail out if we can't determin a value to avoid another invalid
read.
And fix a memory leak when we overflow the filesize