"Catching up" after two years in the wrong school
First of all, nothing is off the table. You are still in the very beginning of your academic path and nothing is closed off irrevocably. You are correct in thinking that a CS degree will require you to catch up on fundamentals. The question is how much time and effort would you like to invest in this endeavor. I don't think that dropping out of the engineering program is necessary. A lot of people transition from engineering to CS, you are by no means the first to want to make the switch. 

So what are the options of a master of engineering holder to get into a CS PhD? 


Doing nothing: You can probably get into some CS PhD program right now if your research statement/references are good, though you are not likely to get into one of the top international programs. School rank does not matter in PhD as much as your ability to find a good advisor with whom you are able to publish! This is a function of your mutual fit and joint capability, not the school's ranking. 
Getting a master in CS: if you want to get some foundational knowledge and have time to familiarize yourself with the field, you can just take 2 years to complete another master's degree. The downside here is that it takes time and money, the upside is that you get another degree to your name and time to gain the necessary experience.
Getting a CS undergraduate degree: this is really resetting your academic clock to some degree. It will take you a while (though you may have the option of getting credits for your existing classes, depending on where you take your undergraduate degree). There's nothing wrong with going back to basics, but it is a bit extreme. 


To conclude, what you want to do is not easy, but certainly within the realm of plausibility. I would say that the current hype around AI/ML is not playing in your favor. The competition for these programs can be quite fierce, especially in top schools, so if your life dream is joining them it may require you getting some professional training via a masters at least.