I buy flour in boxes, rather than bags, and there seem to be less bug-related incidents. Don't know why, as they have to be in the flour already - how else could they get into sealed bags?
The worst we ever had was some gram flour, which I had decanted into a tin. I don't use it a lot, just when I'm making some Indian recipes, and when I opened it, it was full of winged things like moths! I screamed, slammed the lid back on and threw the whole thing away. It was many years ago, and I now keep a close eye on any gram flour in my possession.