The table has a few very specific verbiages and they indicate how the effect happens:
- Controlled by the DM. This is what it means, a monster controlled by the DM appears
- You cast X centered on yourself. This means you cast a spell with the center point of the area of effect being yourself.
- You cast X spell. This means you cast the spell being in full control of the targeting.
- You cast X on yourself. The spell affects you, and you only.
- You cast X on a random creature. A random creature is chosen from the valid targets.
- As far as the size change, it says "for the next minute". With the height change one, you're just as likely to shrink, and you'd have to grow (or shrink) several times (like 10ish?) without a corresponding shrink roll to actually change size categories.
Wild magic is supposed to be unpredictable, that means sometimes you get to control the targetting, sometimes you don't Specifically with Magic Missile and the result where up to 3 creatures get lightning damage, the sorcerer is in control.
This could only work for some effects.
Dispel Magic will only mitigate some Wild Magic Surge effects; specifically those that have a persistent effect on you personally. For example, dispel magic won't help against a fireball you cast on yourself. Fireball would need to be counterspelled, but contingency only works spells with a casting time of one action, and counterspell has a casting time of one reaction.
Another important thing to note about dispel magic is that it's indiscriminate:
Choose one creature, object, or magical effect within range. Any spell of 3rd level or lower on the target ends. For each spell of 4th level or higher on the target, make an ability check using your spellcasting ability. The DC equals 10 + the spell’s level. On a successful check, the spell ends.
A spellcaster doesn't get to pick and choose which effects get dispelled, so the contingent dispel magic will also affect any defensive or protective spells that are affecting them.
Further, while there are no limits in the PHB on the complexity of the condition that can be defined for contingency, the DM might not allow overly long or convoluted conditions. For example, in order to prevent abuse, they might require that a player whose character is casting contingency verbally express the triggering condition without recourse to notes. Or they might only allow simple conditions without any kind of logical conjunctions (and, or, if, etc).
In this particular case, the DM might rule that the player doesn't know all of the possible outcomes from a Wild Magic Surge, and so there's no way they can enumerate them all in order to protect themselves.
... "what if the condition instead was: if Wild Magic Surge affects me or my allies in a harmful or disadvantageous way, except a self-fireball?"
The DM might also limit the amount of decision-making that a contingency can perform. Conditions that include phrases like "in a harmful or disadvantageous way" might not be possible, or (worse) not be reliable; the contingency spell might (for example) decide that turning into a potted plant is advantageous under some circumstances.
Additionally, remember that contingency only casts the spell on the caster, not on any other targets. If you really want to cast dispel magic on yourself any time a Wild Magic Surge affects your allies, you can, but that's probably not what you want.
Best Answer
Assuming you meet all the prerequisites, you can counterspell your own spell.
These are: