Skip to content

[XServer] Library makes program hard crash when monitor is out of bounds #61

@RedFantom

Description

@RedFantom

General information:

  • OS name: Ubuntu (ubuntu-desktop)
  • OS version: 18.04 LTS
  • OS architecture: 64 bits
  • Resolutions:
    • Monitor 1: 1920x1080 (laptop built-in)
    • Monitor 2: 1366x768 (external)
  • Python version: 3.6.5
  • MSS version: 3.2.0

For GNU/Linux users:

  • Display server protocol and version, if known: X server (X.Org version: 1.19.6)
  • Desktop Environment: Gnome 3
  • Composite Window Manager name and version: ??? (The default one, I guess?)

Description of the warning/error

This error occurs when the a monitor that is out of bounds is specified in the grab() call.

from mss import mss

screenshotter = mss()
monitor = {
    "left": -30,
    "top": 0,
    "width": 100,
    "height": 100,
}
try:
    screenshotter.grab(monitor)  # X Error
except BaseException as e:
    # Never reached
    print("Handling error")

Using a monitor like {"left": 0, "top": 0, "width": 10000, "height": 100} has the same result.

Full message

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  73 (X_GetImage)
  Serial number of failed request:  91
  Current serial number in output stream:  91

The message is printed to stderr, then the Python interpreter quits with exit code 1.

Other details

I discovered this because I let my program generate a box based on the location of the cursor. Then I take the screenshot of only the cursor area.

While it might be better for efficiency not to check the bounds of the monitor, I personally don't think causing this type of hard crash is acceptable. It's up to you. If you decide not to check bounds, I think a mention of this in the documentation would be appropriate.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions