Be sure to stop the petting before he shows any aggression. If a display of aggression results in the petting being stopped, then this unacceptable behavior has worked. Each time you work with your cat, try to pet him for slightly longer time periods using the food. A cat exhibits redirected aggression when she is aroused into an aggressive response by one person or animal, but then redirects this aggression onto another person or animal. For example, if two family cats have a spat, the losing cat, still aroused, may walk up and attack the family child.
Cats are however highly territorial, even more so than dogs.
What To Do Check first with your veterinarian to rule out medical causes for the aggressive behavior. Seek professional help. An aggression problem will not go away by itself. Your first priority is to keep everyone safe. You are liable for your cat's behavior.