Dr. Marawan Shahin, Professor of Hadith and its Sciences, Faculty of Usul Ad-Din (Theology),Al-Azhar Univ. states: “As far as Islamic Shari`ah is concerned, we are not allowed to eat any haram food, i.e. food containing haram ingredients, as soon as it comes to your knowledge that it contains unlawful ingredients such as pork or alcohol.
Having said this, if you got any food containing haram ingredients, you are not allowed to eat such food as long as it comes to your knowledge that it contains haram, irrespective of the way you have gotten that food whether you have purchased it accidentally or you have been gifted it, or the like.