BUG: Raise exceptions when an invalid file position is returned.

(cherry picked from commit b6f7d848ec8f5c7dfdeb9d2b4c9e25bf3db9525a)