fix bug in length snipping which could overshorten files