We were struck by a year of drought, so I came to Madinah and entered one of its walled gardens. I took some ears of grain, rubbed them, ate from them, and carried some away in my garment. Then the owner of the garden came, beat me, and took my garment. I went to the Messenger of Allah ﷺ and he said to the man, "You did not teach him when he was ignorant, nor did you feed him when he was hungry."He ordered my garment returned to me and instructed that I be given half a wasq, or a wasq, of grain.
حدثنا محمد بن جعفر حدثنا شعبة عن أبي بشر قال سمعت
أصابتنا سنة فأتيت المدينة فدخلت حائطا من حيطانها فأخذت سنبلا ففركته وأكلت منه وحملت في ثوبي فجاء صاحب الحائط فضربني وأخذ ثوبي فأتيت رسول الله ﷺ فقال ما علمته إذ كان جاهلا ولا أطعمته إذ كان ساغبا أو جائعا فرد علي الثوب وأمر لي بنصف وسق أو وسق
Its isnad is sahih. Abu Bishr is Jafar bin Abu Wahshiya, the well-known trustworthy narrator.The hadith was related by Abu Dawud, 3/39, no. 2620, in jihad, on the traveler eating from fruit, by Nasai, 8/240, no. 5409, in the etiquette of judgment, on seeking legal redress, and by Ibn Majah, 2/770, no. 2298, in transactions, on someone passing by a people's livestock or orchard and whether he may partake of it, and by Hakim, 4/133, with Dhahabi concurring with him, and by Bayhaqi, 10/2.