checking for encoding errors and file data out of bounds. closes #3