The insurers of the ship and/or cargo would be paying to salvage whatever value they can extract from the wreck, to reduce their losses. You’re right about the non-zero chance of insurmountable loss, which is why the owner of the ship and the owner of the cargo would both have a shitload of insurance. Read about Lloyd’s and the shipping insurance business. People have been doing this for hundreds of years.