Had this happen under a Dilbertian boss.. Other guy was a 'pet' of boss, couldn't make his project work. He told boss it was almost done 1-2 weeks of work left that could be finished off by a less senior coder. The bug he was running into took 3-5 days of run-time / crash to find.
It was multi-threaded/multi-cpu code back in the days BEFORE the Intel Core processor (we used multi-cpu motherboards to allow development of parallelism.
Problem was he had zero experience with parallel or multithreaded design, whereas I did, so I was perceived as the logical choice to find the last few remaining problems..
I didn't realize how much of a poser the other guy was -- and was naive when I agreed to finish it (as though I had a choice).
The project that ended up taking about 2-3 months due to the need to rewrite most of his code He was a new 'senior engineer by pay-grade because he'd been here on an H1B visa and had gotten a permanent residency status. He'd been a "under-the-gun" gung-ho developer while he was under the H1-B, but due this 80-100 hour weeks and desire to have our company sponsor his permanent status (which they did, all at their expense).
After he got it, he hinted he might leave, so to keep him, he was given a senior position in order to quality him for the benefits and salary range he wanted -- as well as not making him finish the code he had no idea how to do.
It took me 3 months to finish his work -- with it being fully tested. My first approach had been to optimize the code so that reproducing the bug could be done in a reasonable time. With over a 10X speed up, the bu could be reproduced in 20-30 minutes, max. It was then traced to his code not releasing locks that he'd acquired -- which seemed to work when the code was very slow.
When my boss wanted to know why I turned 1-2 weeks of work into 3 months, I pointed out the errors. He accused me of shifting blame and finger pointing. I ended up getting the 'review' the other guy should have got next cycle, while he came up smelling like a rose.
That experience and a few others like it really put me off working with other people -- as they, almost universally got stuck in their code with blame shifted to me. In no case was my code at fault -- but that doesn't stop management from blaming you.
Leave -- run, and avoid such situations at all costs. You will never come up with a positive result. The best you can do, usually is to minimize damage with copious amounts of evidence and documentation.