Skip to content

Commit 9e679a7

Browse files
authored
Ensure that grab regions are valid
1 parent c7457c1 commit 9e679a7

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/mss/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ def grab(self, monitor: Monitor | tuple[int, int, int, int], /) -> ScreenShot:
112112
"height": monitor[3] - monitor[1],
113113
}
114114

115+
if monitor["left"] < 0 or monitor["top"] < 0:
116+
msg = f"Region has negative coordinates: {monitor!r}"
117+
raise ScreenShotError(msg)
118+
if monitor["width"] <= 0 or monitor["height"] <= 0:
119+
msg = f"Region has zero or negative size: {monitor!r}"
120+
raise ScreenShotError(msg)
121+
115122
with lock:
116123
screenshot = self._grab_impl(monitor)
117124
if self.with_cursor and (cursor := self._cursor_impl()):

0 commit comments

Comments
 (0)