Repository navigation
Conversation
oviron
marked this pull request as ready for review
November 19, 2026 12:07
Author
|
Our fork ships these two commits in AyuGram 7.4.4-3, universal macOS and Windows x64, built by CI. The macOS build starts and runs. No code change since the pull request was opened. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A handler of
Streaming::Player::updates()can destroy the player that is sending the update, and the player then goes on reading and writing its own fields.The automatic quality switch does it.
Player::trackReceivedTill()sendsPreloadedVideothroughtrackSendReceivedTill().Streaming::Document::handleUpdate()answers withcheckSwitchToHigherQuality(), which firesswitchQualityRequests, and the owner replaces its stream right there:Gif::createStreamedPlayer(),OverlayWidget::applyVideoQuality()orPip::applyVideoQuality(). If that owner held the lastshared_ptr<Document>, theDocumentand itsPlayerare destroyed before_updates.fire()returns. Back intrackReceivedTill()the player reads_pauseReading,_information,_audio,_videoand_options, may set_pauseReading, andvideoReceivedTill()then callscheckResumeFromWaitingForData().How bad it is depends on the owner.
GifandPipcreate the new stream before they drop the old one, so theweak_ptrinData::Streamingstill holds the old allocation: the object is destroyed, the memory is not freed yet.OverlayWidget::applyVideoQuality()callsclearStreaming()first andinitStreaming()after it, andsharedDocument()erases the expired entry (PruneDestroyedAndSet) while it registers the new stream. The memory is freed, and the reads that follow are a use after free. It takes the media viewer as the only owner of the stream and the quality on Auto.The same happens after
Information:Gif::streamingReady()callsstopAnimation()when the real frame is over the inline limit, andprovideStartInformation()reads_stageand_pausedafter the update.The first commit checks
_sessionGuardafter these updates, the waytrackPlayedTill(),start()andupdatePausedState()already do:trackReceivedTill()aftertrackSendReceivedTill();audioReceivedTill()andvideoReceivedTill()beforecheckResumeFromWaitingForData();trackPlayedTill();provideStartInformation()after the update.stop()clears the guard too. The code skipped in that case has no effect that outlives the stop: the only field it could change is_pauseReading, and the nextplay()resets it.Audio track.
AudioTrack::playPosition()has the same problem one level down. Its handler fires_waitingForData, the player sendsWaitingForData{ true }, andDocument::waitingChange()checks for a lower quality at once if the waiting indicator is still animating. When the owner replaces the stream there,Player::stop()destroys the track, and the handler then reads_stream.durationand assigns_playPosition. The track is its own allocation, so its memory is freed whichever owner did it. The second commit givesAudioTrackabase::has_weak_ptrbase and returns from the handler when the track is gone.Found by reading the code while working on #31657; I have not seen a crash from it. Our fork of AyuGram, which tracks Telegram Desktop 7.4.4, ships these commits in AyuGram 7.4.4-3 (universal macOS and Windows x64, built by CI). The macOS build starts and runs; the behaviour itself has not been checked by observation yet.
This pull request was prepared with the help of an AI assistant (Claude Code).
🤖 Generated with Claude Code