Skip to content

Fix IndexOutOfBounds crash when sending media with an undecodable preview#7050

Open
Narasimha-sc wants to merge 2 commits into
masterfrom
nd/fix-corrupted-video-upload-error
Open

Fix IndexOutOfBounds crash when sending media with an undecodable preview#7050
Narasimha-sc wants to merge 2 commits into
masterfrom
nd/fix-corrupted-video-upload-error

Conversation

@Narasimha-sc

@Narasimha-sc Narasimha-sc commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Problem. Sending a batch of picked media crashes with IndexOutOfBoundsException (ComposeView.sendMessageAsync) when one of the items — typically a corrupted video — produces no preview frame.

Cause. processPickedMedia appended to MediaPreview.content unconditionally for videos (and size-ok animated images) but only appended to images when a preview bitmap existed; getBitmapFromVideo returns a null preview for undecodable videos without throwing, desyncing the two index-aligned lists so sendMessageAsync indexes images[index] past its end.

Fix. Pair both appends behind a single non-null-bitmap check so content and images always stay equal-length and index-aligned; only the undecodable item is skipped while the rest of the batch still sends. A skipped video shows showVideoDecodingException() (guarded by hasAlertsShown() so the alert neither stacks across multiple bad items nor duplicates the one already shown on the exception path) instead of being dropped silently. Shared commonMain change, so Android and Desktop are both covered.

@Narasimha-sc Narasimha-sc requested a review from epoberezkin as a code owner June 4, 2026 21:04
@Narasimha-sc Narasimha-sc changed the base branch from stable to master June 4, 2026 21:05
@Narasimha-sc Narasimha-sc force-pushed the nd/fix-corrupted-video-upload-error branch 2 times, most recently from 2d12dcb to 0f3c78f Compare June 8, 2026 10:38
…tOfBounds on send

processPickedMedia appended to MediaPreview.content unconditionally for videos
(and size-ok animated images) but only appended to images when a preview bitmap
existed. getBitmapFromVideo returns a null preview for undecodable/corrupted
videos without throwing, desyncing the two lists; sendMessageAsync then indexes
images[index] past its end and crashes. Pair both appends behind a non-null
bitmap so the lists stay equal-length and index-aligned, and skip only the bad
item so the rest of the picked batch still sends.

A video skipped this way shows showVideoDecodingException(), guarded by
hasAlertsShown() so it neither stacks across multiple bad items nor duplicates
the alert already shown on getBitmapFromVideo's exception path. Image decode
failures are already surfaced earlier by getBitmapFromUri.
@Narasimha-sc Narasimha-sc force-pushed the nd/fix-corrupted-video-upload-error branch from 0f3c78f to ad26b70 Compare June 8, 2026 13:04
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.

2 participants