Fixed heap overflow caused by length