Added buffer overflow protection for filename.