improve file buffer boundary checking; more verbose logging of errors