Laws on using lethal force against an attacking dog vary by jurisdiction. Lethal force should generally be a last resort and is typically justified only when there is imminent danger of serious harm or death. If possible, escape or avoid the situation.
If you must act, use the minimum force necessary and report the incident to police immediately. Seek medical attention for any injuries.