add fix for protection of wrong reading if input is invalid
put this file into good format
Merge pull request #1649 from sijchen/fix_trace

[Encoder] fix a potential problem of trace