This is why it's so important to grill your interviewers about the reality of working at the company, although I'll admit that I learned which questions to ask from bad experience. Asking those questions also happens to serve as excellent signalling to your technical interviewers, much more effective than being able to solve some silly logic puzzle.
And to be perfectly fair, you do learn so much from working on poorly written projects that are a horror to maintain. Failure teaches you which mistakes to avoid next time.