Skip to content

Fix infinite GIF reader loop on zero-frame streams - #2315

Open
XXcipherX wants to merge 1 commit into
TelegramMessenger:masterfrom
XXcipherX:fix/gif-reader-infinite-loop
Open

XXcipherX wants to merge 1 commit into
TelegramMessenger:masterfrom
XXcipherX:fix/gif-reader-infinite-loop

Conversation

@XXcipherX

Copy link
Copy Markdown

BatchVideoRenderingContext repeatedly reopened an FFmpeg reader when a stream reached EOF without producing any frames. This caused a synchronous decoding loop, sustained CPU usage, and blocked GIF rendering.

Track whether the reader has produced a frame. Restart it only after it has produced at least one frame; treat zero-frame EOF as a decoding failure.

Testing

Verified with the focused BatchVideoRenderingTests regression harness on GitHub Actions using Xcode 26.2 and iOS 26.2:

https://github.com/XXcipherX/telegram-ios-gif-regression-test/actions/runs/33513158372

Fixes #2246

Stop reopening an FFmpeg reader that reaches EOF before producing a frame, preventing repeated synchronous decoding.

Fixes TelegramMessenger#2246
@CLAassistant

CLAassistant commented Sep 1, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

arena-ai-coding-agent Bot pushed a commit to decoder-dev/Telegram-iOS that referenced this pull request Sep 12, 2026
…egramMessenger#2124 TelegramMessenger#2308 TelegramMessenger#2235 TelegramMessenger#2241 TelegramMessenger#2329

TelegramMessenger#2244 WEBFILE_NOT_AVAILABLE poisoned web-referenced media as a complete
0-byte file: the multipart fetcher reported completeSize 0, MediaBox
persisted it and never fetched again. Now retries with exponential
backoff (1-16s, 5 attempts) then fails the fetch (retryable); both
MediaBox file contexts no longer accept a reported size of 0 as
evidence of completion.

TelegramMessenger#2246 zero-frame GIF streams spun BatchVideoRenderingContext in an
infinite reopen-decode loop at 100% CPU. Port of upstream PR TelegramMessenger#2315:
a reader that produced no frames at EOF is a decoding failure, not a
restart.

TelegramMessenger#2124 tapping one chat could open another: ListView selection resolved
through item nodes' model frames, which can disagree with the displayed
position after an interrupted layout animation. Selection and secondary
action are cross-checked against UIKit's presentation-based hit test
and cancelled on mismatch; index bounds-checked against live items.

TelegramMessenger#2308 Siri extension trapped inside Postbox: the shared .tempkey file
was written non-atomically, so a concurrent reader could see it
half-written, generate a diverging random key and poison every later
open. Atomic write now; Siri no longer force-unwraps key/salt
constructors.

TelegramMessenger#2235 Mini App web view collapsed to 1px after the keyboard opened:
degenerate intermediate geometry was clamped to max(1.0,...) and
published as a STABLE viewport. Insets are bounded to keep a minimum
usable height; intermediate geometry is not reported as stable.

TelegramMessenger#2241 web_app_request_fullscreen could be silently ignored, leaving
bots hanging on the fullscreenChanged/fullscreenFailed contract. The
unhandleable path now answers fullscreen_failed/UNSUPPORTED.

TelegramMessenger#2329 story publishing settings were unreachable on iPhone SE:
scrolling is disabled for stories in favor of the dismiss pan gesture,
so overflowing content was cut off. The screen becomes scrollable
whenever content actually overflows.

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
arena-ai-coding-agent Bot pushed a commit to decoder-dev/Telegram-iOS that referenced this pull request Sep 16, 2026
…er#2304), sharp fullscreen/peek stickers (TelegramMessenger#2297), DrawingContext null-buffer guard (TelegramMessenger#2217); TelegramMessenger#2315 already present

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
decoder-dev added a commit to decoder-dev/Telegram-iOS that referenced this pull request Sep 18, 2026
…er#2304), sharp fullscreen/peek stickers (TelegramMessenger#2297), DrawingContext null-buffer guard (TelegramMessenger#2217); TelegramMessenger#2315 already present

Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
decoder-dev added a commit to decoder-dev/Telegram-iOS that referenced this pull request Sep 18, 2026
…egramMessenger#2124 TelegramMessenger#2308 TelegramMessenger#2235 TelegramMessenger#2241 TelegramMessenger#2329

TelegramMessenger#2244 WEBFILE_NOT_AVAILABLE poisoned web-referenced media as a complete
0-byte file: the multipart fetcher reported completeSize 0, MediaBox
persisted it and never fetched again. Now retries with exponential
backoff (1-16s, 5 attempts) then fails the fetch (retryable); both
MediaBox file contexts no longer accept a reported size of 0 as
evidence of completion.

TelegramMessenger#2246 zero-frame GIF streams spun BatchVideoRenderingContext in an
infinite reopen-decode loop at 100% CPU. Port of upstream PR TelegramMessenger#2315:
a reader that produced no frames at EOF is a decoding failure, not a
restart.

TelegramMessenger#2124 tapping one chat could open another: ListView selection resolved
through item nodes' model frames, which can disagree with the displayed
position after an interrupted layout animation. Selection and secondary
action are cross-checked against UIKit's presentation-based hit test
and cancelled on mismatch; index bounds-checked against live items.

TelegramMessenger#2308 Siri extension trapped inside Postbox: the shared .tempkey file
was written non-atomically, so a concurrent reader could see it
half-written, generate a diverging random key and poison every later
open. Atomic write now; Siri no longer force-unwraps key/salt
constructors.

TelegramMessenger#2235 Mini App web view collapsed to 1px after the keyboard opened:
degenerate intermediate geometry was clamped to max(1.0,...) and
published as a STABLE viewport. Insets are bounded to keep a minimum
usable height; intermediate geometry is not reported as stable.

TelegramMessenger#2241 web_app_request_fullscreen could be silently ignored, leaving
bots hanging on the fullscreenChanged/fullscreenFailed contract. The
unhandleable path now answers fullscreen_failed/UNSUPPORTED.

TelegramMessenger#2329 story publishing settings were unreachable on iPhone SE:
scrolling is disabled for stories in favor of the dismiss pan gesture,
so overflowing content was cut off. The screen becomes scrollable
whenever content actually overflows.
decoder-dev added a commit to decoder-dev/Telegram-iOS that referenced this pull request Sep 18, 2026
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.

Saved GIFs panel: infinite decode loop + permanent 100% CPU hang on unsupported pixel format (e.g. H.264 4:4:4)

2 participants