(Gen. 41:1:) "Now it came to pass at the end of two full years that Pharaoh dreamed." This is what Scripture says (Job 28:3): "He sets an end to the darkness, and he searches out every limit." Everything has an end: the mountains, the hills, the wind, and the seas, even to imaginary things, even to the darkness. Whence the mountains? As it is stated (Isa. 40:12): "And he weighs the mountains with a balance, and the hills with scales." Whence the wind? As it is stated (Job 28:25): "To make a weight for the wind." And whence the waters? "And he meted out the waters by measure" (ibid.). Whence the darkness? "He sets an end to the darkness." Each and every thing that comes upon a person, even the afflictions, has an end, as it is stated: "And he searches out every limit" — for the Holy One, blessed be He, sits and searches out whether afflictions are sought for him or not, as it is stated: "And he searches out every limit." Resh Lakish said: Who caused this person that afflictions should come upon him? "[A stone of] gloom and the shadow of death" (Job 28:3). "A stone" — this is the evil inclination, which is likened to a stone, as it is stated (Ezek. 36:26): "And I will remove the heart of stone." Thus, "a stone of gloom and the shadow of death."
Pharaoh's Dream and the End God Sets to Every Darkness
Midrash Tanchuma Buber, Miketz 1:1
ויהי מקץ שנתים ימים ופרעה חלם (בראשית מא א) זש"ה קץ שם לחשך וכל תכלית הוא חוקר (איוב כח ג), לכל יש קץ להרים לגבעות ולרוח ולימים אפילו לדברי הואי, אפילו לחשך. הרים מנין, שנאמר ושוקל בפלס הרים וגבעות במאזנים (ישעיה מ יב), לרוח מנין, שנאמר לעשות לרוח משקל (איוב כח כה). ולמים מנין, ומים תכן במדה (שם). לחשך מנין, קץ שם לחשך, כל דבר ודבר שהוא בא לאדם אפילו היסורין יש להם קץ, שנאמר ולכל תכלית הוא חוקר, שהקב"ה יושב וחוקר אם מתבקשין לו יסורין אם לאו, שנאמר ולכל תכלית הוא חוקר. אמר ריש לקיש מי גרם להאיש הזה שבאו עליו יסורים (ואפילה) [אבן אופל וצלמות] (שם ג), אבן זה יצק הרע שהוא משול באבן שנאמר והסרותי את לב האבן (יחזקאל לו כו), הוי אבן אופל וצלמות.