Hunting for bugs in Telegram’s animated stickers remote attack surface
The rlottie library used by Telegram to parse animated stickers contained multiple memory-safety bugs, including an out-of-bounds heap write caused by an unchecked loop bound. An attacker could send a crafted animated sticker that, when the victim opened the chat, triggered memory corruption or a persistent crash.
At the end of October ‘19 I was skimming the Telegram’s android app code, learning about the technologies in use and looking for potentially interesting features. Just a few months earlier, Telegram had introduced the animated stickers; after reading the blogpost I wondered how they worked under-the-hood and if they…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a loop in the gradient colour-table generator did not check the write position against the fixed buffer size, so a value taken from the sticker file could push writes past the end of the heap buffer.
Impact
A crafted animated sticker could cause memory corruption that, with an additional ASLR bypass, might lead to remote code execution, and could also cause a persistent crash that blocks access to the chat; the attack was limited to secret chats because stickers in normal chats were not delivered during testing.
What the attacker needed
Victim uses an affected Telegram client; attacker can start a secret chat with the victim; victim opens the chat containing the sticker
The fix
Telegram fixed the issues in client updates released in September and October 2020 and introduced a way to reduce this attack surface.
How it was found
- Build a harness that loads a Lottie JSON file with rlottie and renders every frame.
- Collect animated stickers from Telegram channels and Lottie communities to form a seed corpus.
- Run a coverage-guided fuzzer against the harness until crashes appear.
- Triage the crashes and minimise the crashing JSON testcases.
- Analyse the root cause of each crash in the rlottie source code.
- Send a crafted animated sticker to a victim in a secret chat; it is parsed when the chat is opened.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Animated stickers in Telegram are small animation files that the app reads and draws on screen. The code that reads these files did not always check how big the data was, so a specially made sticker file could make the app write past the end of a memory buffer. That can crash the app or, in theory, let an attacker run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.