diff --git a/source/Lib/CommonLib/Slice.cpp b/source/Lib/CommonLib/Slice.cpp
index f7fa29e11a9481791a174ea688f141b0e3b1d390..b06bedd02ec9f93f119925c6644ae525aca95138 100644
--- a/source/Lib/CommonLib/Slice.cpp
+++ b/source/Lib/CommonLib/Slice.cpp
@@ -2349,6 +2349,11 @@ void Slice::scaleRefPicList( Picture *scaledRefPic[], APS** apss, APS& lmcsAps,
 
           CHECK( j >= MAX_NUM_REF, "scaledRefPic can not hold all reference pictures!" );
 
+          if( j >= MAX_NUM_REF )
+          {
+            j = 0;
+          }
+
           if( scaledRefPic[j] == nullptr )
           {
             scaledRefPic[j] = new Picture;