Fix a file read/write bug for undef file