fix encoder crash at end of input