Skip to content

Commit 6e7fab4

Browse files
Guard against OOB moves in media send flow.
1 parent 8a7cac7 commit 6e7fab4

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/org/thoughtcrime/securesms/mediasend/MediaSendViewModel.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.annimon.stream.Stream;
1414

1515
import org.thoughtcrime.securesms.TransportOption;
16+
import org.thoughtcrime.securesms.logging.Log;
1617
import org.thoughtcrime.securesms.mms.MediaConstraints;
1718
import org.thoughtcrime.securesms.providers.BlobProvider;
1819
import org.thoughtcrime.securesms.util.MediaUtil;
@@ -31,6 +32,8 @@
3132
*/
3233
class MediaSendViewModel extends ViewModel {
3334

35+
private static final String TAG = MediaSendViewModel.class.getSimpleName();
36+
3437
private static final int MAX_PUSH = 32;
3538
private static final int MAX_SMS = 1;
3639

@@ -176,10 +179,20 @@ void onFolderSelected(@NonNull String bucketId) {
176179
}
177180

178181
void onPageChanged(int position) {
182+
if (position < 0 || position >= getSelectedMediaOrDefault().size()) {
183+
Log.w(TAG, "Tried to move to an out-of-bounds item. Size: " + getSelectedMediaOrDefault().size() + ", position: " + position);
184+
return;
185+
}
186+
179187
this.position.setValue(position);
180188
}
181189

182190
void onMediaItemRemoved(@NonNull Context context, int position) {
191+
if (position < 0 || position >= getSelectedMediaOrDefault().size()) {
192+
Log.w(TAG, "Tried to remove an out-of-bounds item. Size: " + getSelectedMediaOrDefault().size() + ", position: " + position);
193+
return;
194+
}
195+
183196
Media removed = getSelectedMediaOrDefault().remove(position);
184197

185198
if (removed != null && BlobProvider.isAuthority(removed.getUri())) {

0 commit comments

Comments
 (0)