Skip to content

service/notifications: validate image-data bounds and honor rowstride - #1555

Open
leierx wants to merge 1 commit into
quickshell-mirror:masterfrom
leierx:fix/notification-image-data
Open

leierx wants to merge 1 commit into
quickshell-mirror:masterfrom
leierx:fix/notification-image-data

Conversation

@leierx

@leierx leierx commented Nov 25, 2026 •

Copy link
Copy Markdown

Describe your changes

Any app on the session bus can send image-data hints over D-Bus, so Quickshell should not trust the claimed width, height, or rowstride without checking the actual byte buffer.

Right now:

  • operator>> warns on bad sampleBits, channels, or rowstride, but keeps the pixmap anyway and never checks width, height, or data.size(). A single Notify call claiming a large size (like 65535x65535) with 16 bytes of data crashes the shell when QImage reads past the buffer.
  • createImage() ignores rowstride, so Qt assumes 32-bit aligned rows and misrenders padded rowstrides or unaligned RGB888 buffers.
  • Notification::updateProperties() still sets imagePath to the pixmap URL when image-data fails to parse, so it does not fall back to image-path.

Details and decisions

  • Clear pixmap before parsing and on any failed check (sampleBits, channels, width <= 0, height <= 0, rowstride < minRowBytes, or data.size() < minBytes), using qint64 so width * channels cannot overflow.
  • Store rowstride on DBusNotificationImage, pass it as bytesPerLine to QImage, and re-check bounds in createImage().
  • The notification spec / GdkPixbuf allows omitting padding after the last row (rowstride * (height - 1) + width * channels), while QImage::copy() reads bytesPerLine * height bytes. For height == 1, pass minRowBytes; for height > 1, zero-pad the buffer to rowstride * height (with an overflow check).
  • Only set imagePath = mImagePixmap.url() if mImagePixmap.hasData() is true, so invalid image-data falls back to image-path.

Tested on my NixOS setup using this patch against 0.3.2 (including tests sending 100x100 and 65535x65535 with 16-byte buffers), plus local Qt 6.12 compile and harness checks on this branch.

Open concerns

None.

Participation

I used Gemini Neon and Claude Opus 5.5 to find this issue (through chaos testing my shell) and write the fix. I understand the code on a surface level, I am no C++ or Qt expert, but the approach looks reasonable to me and I am very open to being corrected.

Validate image-data dimensions, rowstride, and byte length in DBusNotificationImage::operator>> and clear the pixmap on failure so Notification::updateProperties falls back to image-path instead of exposing an invalid image URL.

Store and pass the client's rowstride to QImage::QImage(..., bytesPerLine, format) instead of letting QImage assume 32-bit aligned rows. Pad multi-row buffers whose final row omits trailing rowstride padding (permitted by GdkPixbuf / the notification spec) so QImage deep copies do not read past the buffer, and pass the exact row width for single-row images.

Check buffer bounds in createImage() as well and clear the pixmap before demarshalling so malformed arguments cannot retain stale data.
@leierx
leierx marked this pull request as ready for review November 25, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant