there is a way to avoid it. if you apply for registration of the trademark first and get approval, it won't be illegal in law.
However, theoretically, it is possible that the other party will object to copyright infringement or apply for revocation, which is highly probable in practice. It is difficult for the other party to defend their rights.