If the insulation is cooked, it usually doesn't go too far back before you find intact insulation, in my experience. If you can find some slack in the wire and are able to pull out enough to work with, you may be able to make a safe connection.
Most of the bad boxes I've run into, the insulation was cooked off the wires by using high wattage bulbs over a good many years.
On some occasions I've been able to pull enough good wire into the box, and paint the bare areas of the wire with a liquid insulating product. Several coats. Not the most desirable scenario, but it works if you take a little time with it to make sure everything's good. Better to go swimming in the attic and resection the wires in junction boxes.