From f0fa43e33f758e290c7bc456cb31ee6b07ad1bca Mon Sep 17 00:00:00 2001
From: Maria Santamaria <maria.santamaria_gomez@nokia.com>
Date: Fri, 29 Sep 2023 18:40:29 +0000
Subject: [PATCH] Fix #1616: NNPFC SEI nnpfc_chroma_sample_loc_type_frame value
 is checked even when not signalled

---
 source/App/EncoderApp/EncAppCfg.cpp | 5 +++++
 source/Lib/DecoderLib/SEIread.cpp   | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index 6a311cebc..c5b39dd74 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -5147,6 +5147,11 @@ bool EncAppCfg::xCheckParameter()
       xConfirmPara(m_nnPostFilterSEICharacteristicsMatrixCoeffs[i] > 255, "m_nnPostFilterSEICharacteristicsMatrixCoeffs must in the range 0 to 255");
       xConfirmPara(m_nnPostFilterSEICharacteristicsOutFormatIdc[i] > 255, "SEINNPFCOutFormatIdc must be in the range of 0 to 255");
       xConfirmPara(m_nnPostFilterSEICharacteristicsOutOrderIdc[i] > 255, "SEINNPFCOutOrderIdc must be in the range of 0 to 255");
+      if (m_nnPostFilterSEICharacteristicsChromaLocInfoPresentFlag[i])
+      {
+        xConfirmPara(m_nnPostFilterSEICharacteristicsChromaSampleLocTypeFrame[i] > (uint32_t) Chroma420LocType::UNSPECIFIED,
+                     "The value of nnpfc_chroma_sample_loc_type_frame shall be in the range of 0 to 6, inclusive");
+      }
       xConfirmPara(m_nnPostFilterSEICharacteristicsPatchWidthMinus1[i] > 32766, "SEINNPFCPatchWidthMinus1 must be in the range of 0 to 32766");
       xConfirmPara(m_nnPostFilterSEICharacteristicsPatchHeightMinus1[i] > 32766, "SEINNPFCPatchHeightMinus1 must be in the range of 0 to 32766");
       xConfirmPara(m_nnPostFilterSEICharacteristicsOverlap[i] > 16383, "SEINNPFCOverlap must be in the range of 0 to 16383");
diff --git a/source/Lib/DecoderLib/SEIread.cpp b/source/Lib/DecoderLib/SEIread.cpp
index 6955ebc63..134429fea 100644
--- a/source/Lib/DecoderLib/SEIread.cpp
+++ b/source/Lib/DecoderLib/SEIread.cpp
@@ -3125,8 +3125,8 @@ void SEIReader::xParseSEINNPostFilterCharacteristics(SEINeuralNetworkPostFilterC
     {
       sei_read_uvlc(pDecodedMessageOutputStream, val, "nnpfc_chroma_sample_loc_type_frame");
       sei.m_chromaSampleLocTypeFrame = static_cast<Chroma420LocType>(val);
+      CHECK(sei.m_chromaSampleLocTypeFrame > Chroma420LocType::UNSPECIFIED, "The value of nnpfc_chroma_sample_loc_type_frame shall be in the range of 0 to 6, inclusive");
     }
-    CHECK(sei.m_chromaSampleLocTypeFrame > Chroma420LocType::UNSPECIFIED, "The value of nnpfc_chroma_sample_loc_type_frame shall be in the range of 0 to 6, inclusive");
 
     sei_read_uvlc(pDecodedMessageOutputStream, val, "nnpfc_overlap");
     sei.m_overlap = val;
-- 
GitLab