Worm larvae in over-ripe Guava fruit

We have a guava tree at home. We frequently observe worm larvae floating around in the core/soft part in the center of over ripe guava fruit. What is this pest? How to treat it? Are the unripe fruits safe to consume?

Most likely guava fruit fly.
It lays eggs in near ripe fruit and the larvae hatch and develop inside the fruit before finally emerging as flies. If you have a small number of fruits, you could wrap a thick paper around each fruit as it begins forming.