You are correct: the sentence has a different meaning based on context. We generally recognise which meaning is correct by looking at the context -- and that's really the only way.
Only in text-books do sentences appear out of context. In real life, there is always a context.
- For Teachers