Fix undefined behavior in FrameBuffer

Bug: none
Change-Id: I7ce6298a27dc9e79e5f5a85103b3f1dd7b4be71e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/131953
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27527}
diff --git a/modules/video_coding/frame_buffer2.cc b/modules/video_coding/frame_buffer2.cc
index 0c2a624..5d427b0 100644
--- a/modules/video_coding/frame_buffer2.cc
+++ b/modules/video_coding/frame_buffer2.cc
@@ -352,10 +352,11 @@
     if (prev_frame == frames_.end())
       return false;
     while (prev_frame->second.frame->inter_layer_predicted) {
+      if (prev_frame == frames_.begin())
+        return false;
       --prev_frame;
       --id.spatial_layer;
-      if (prev_frame == frames_.end() ||
-          prev_frame->first.picture_id != id.picture_id ||
+      if (prev_frame->first.picture_id != id.picture_id ||
           prev_frame->first.spatial_layer != id.spatial_layer) {
         return false;
       }