You are jumping to conclusions here. Also just thinking of extremes is not helpful. Acting on your desires to perform sexual acts with children is absolutely pedophilic behavior. So masturbating is just that. It is not just a thought, it is an action. Even though non pedophiles don't even have these thoughts without disgust.
Just ask yourself, would you ever be comfortable leaving a child alone with someone who sexualizes children? My answer would be absolutely not, they are pedophiles and a huge risk to the childs safety.
How to solve this or manage the risk is another way more complicated topic.