remove tail invalid bytes