As has been said yes you could potentially be infracted. That the thread was a spam thread from the get-go doesn't really matter much as by making such posts in it, you just contribute to the spamfest. After all such threads are not meant to be 'on topic', so paradoxically enough you are actually doing what that thread was meant for. If you see a spam thread, you should just report it, ignore it and not post in it.
Even though unlikely, it has happened before that a mod started dealing out infractions to everyone in the thread and a post you just described would definitely be infracted if such a mod would have seen it.