Sayyiduna Umayr (may Allah be pleased with him), the freed slave of Sayyiduna Abi al-Lahm (may Allah be pleased with him), narrates: I came with my masters, intending to emigrate. When we drew near to Madinah, they left me behind and entered Madinah, and I was struck by severe hunger. He said: Some residents of Madinah passed by me and said: "If only you would enter Madinah and eat from the fruit of its orchards." So I entered one of the orchards of Madinah and picked two bunches of dates. The owner of the orchard came while both bunches were still with me. He seized me and took me to the Prophet (peace and blessings be upon him), who asked me about my situation, and I told him. He (peace and blessings be upon him) asked: "Which of these two bunches is better?" I pointed to one of them. He (peace and blessings be upon him) said: "Take it," and he said to the owner of the orchard: "You take the other bunch." And he let me go.
Note: These hadiths indicate that at a time of necessity another person's property may be eaten, and that giving compensation for someone's property is obligatory when it is taken without its owner's consent. It is like the narration of Sayyiduna Imran bin Husayn (may Allah be pleased with him), in which the Prophet (peace and blessings be upon him) set out on a journey together with the Companions (may Allah be pleased with them). They were struck by severe thirst, so they brought a woman who had two waterskins to the Prophet (peace and blessings be upon him), and they took water from her waterskins; in the end, more was also given to her in her waterskins and her garment.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الضحايا / 19665