Skip to content

Detect keyboard stickers by image content instead of URI. - #15048

Open
actuallyrisk wants to merge 1 commit into
signalapp:mainfrom
actuallyrisk:keyboard-sticker-alpha-detection
Open

actuallyrisk wants to merge 1 commit into
signalapp:mainfrom
actuallyrisk:keyboard-sticker-alpha-detection

Conversation

@actuallyrisk

Copy link
Copy Markdown

Since 7.41.0 an image committed by the keyboard is treated as a sticker only if its URI contains "sticker" or the SwiftKey share path. Keyboards that use other paths, such as Samsung Keyboard's Galaxy AI stickers (.../cache/temp_content/ai_expression/.png), end up in the media editor and are sent as regular images with a bubble.

Keep the URI check as a fast path and additionally treat an image as a sticker when it is at most 1024 px on the long side, roughly square (aspect ratio up to 1.5) and carries an alpha channel. The alpha check reads only the PNG IHDR/tRNS or WebP VP8X/VP8L header, so unlike the pre-7.41 pixel check it does not decode the image and cannot time out. GIFs are not inspected and keep relying on the URI fast path.

Fixes #15035

First time contributor checklist

Contributor checklist

  • Samsung Galaxy S26 Ultra (SM-S948B), Android 17 (One UI 9.0), Samsung Keyboard 5.9.40.74
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #15035 syntax

Description

Since 7.41.0 (2e50699) an image committed by the keyboard is a sticker only if its URI contains sticker or the SwiftKey share path. Samsung Keyboard commits its Galaxy AI stickers as content://com.samsung.android.honeyboard.provider/root/storage/emulated/0/Android/data/com.samsung.android.honeyboard/cache/temp_content/ai_expression/<millis>.png, so they open the media editor and are sent as regular images with a bubble (#15035).

Rather than adding one URI pattern per keyboard, this keeps the URI check as a fast path and additionally treats an image as a sticker when it is at most 1024 px on the long side, has an aspect ratio of at most 1.5 and carries an alpha channel. The alpha check (ImageAlphaSniffer) reads only the PNG IHDR/tRNS or WebP VP8X/VP8L header: a few bytes, no decoding, nothing that can time out like the pre-7.41 Glide pixel check. GIFs are not inspected and keep relying on the URI fast path. Only the sending client changes, the borderless flag already travels in the message.

Trade-off: a small transparent PNG from the keyboard's clipboard is also sent borderless and skips the editor.

Testing

  • ImageAlphaSnifferTest, 23 cases: all PNG color types, tRNS after PLTE/gAMA/large metadata chunks and beyond the 64 KiB scan limit, VP8X/VP8L/VP8 headers, truncated and non-image input, PNGs encoded by ImageIO. ktlint 1.5.0 clean.
  • Sniffer run over 6000 PNG files from a Windows installation: the result matched ImageIO's decoded color model in 5998 cases, 2 files were unreadable by ImageIO, 0 mismatches. 887 WebP files: 222 reported alpha, 35 files without a valid RIFF/WEBP signature reported opaque.
  • Not yet tested on any other device. The Samsung URI above and the 720x720 PNG dimensions were captured on the device from Samsung Keyboard: Galaxy AI stickers are sent as regular images since 7.41.0 #15035 with adb shell dumpsys activity -p org.thoughtcrime.securesms permissions.

Since 7.41.0 an image committed by the keyboard is treated as a sticker
only if its URI contains "sticker" or the SwiftKey share path. Keyboards
that use other paths, such as Samsung Keyboard's Galaxy AI stickers
(.../cache/temp_content/ai_expression/<id>.png), end up in the media
editor and are sent as regular images with a bubble.

Keep the URI check as a fast path and additionally treat an image as a
sticker when it is at most 1024 px on the long side, roughly square
(aspect ratio up to 1.5) and carries an alpha channel. The alpha check
reads only the PNG IHDR/tRNS or WebP VP8X/VP8L header, so unlike the
pre-7.41 pixel check it does not decode the image and cannot time out.
GIFs are not inspected and keep relying on the URI fast path.

Fixes signalapp#15035
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.

Samsung Keyboard: Galaxy AI stickers are sent as regular images since 7.41.0

1 participant