Most EPUBs created in most software have a raster cover, i.e. a jpg or png image that is the actual cover image, which is referenced in the first html file of the epub. In properly produced epubs, this is image is unambiguously identified as the cover my a <meta> tag in the opf tat refers to the manifest item corresponding to the cover.
If the epub lacks such unambiguous identification, there is no way to safely replace the cover. You have no way to know if the first html file is a cover, or normal content.
calibre assumes that if there is an entry in the <guide> of the OPF that points to the HTML with type="cover" then the HTML file can be replaced. Otherwise the cover is prepended by inserting a new HTML file at the beginning.
Yeah, cover's in EPUB suck.