From 4ca89db22dea962690f31c1781bce5937ee91837 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 1 Jan 2018 13:12:21 +0000 Subject: [PATCH] imgproc(hdr): fix bounds check in HdrDecoder::checkSignature() --- modules/imgcodecs/src/grfmt_hdr.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_hdr.cpp b/modules/imgcodecs/src/grfmt_hdr.cpp index f795120547..9801106506 100644 --- a/modules/imgcodecs/src/grfmt_hdr.cpp +++ b/modules/imgcodecs/src/grfmt_hdr.cpp @@ -101,10 +101,14 @@ bool HdrDecoder::readData(Mat& _img) bool HdrDecoder::checkSignature( const String& signature ) const { - if(signature.size() >= m_signature.size() && - (!memcmp(signature.c_str(), m_signature.c_str(), m_signature.size()) || - !memcmp(signature.c_str(), m_signature_alt.c_str(), m_signature_alt.size()))) - return true; + if (signature.size() >= m_signature.size() && + 0 == memcmp(signature.c_str(), m_signature.c_str(), m_signature.size()) + ) + return true; + if (signature.size() >= m_signature_alt.size() && + 0 == memcmp(signature.c_str(), m_signature_alt.c_str(), m_signature_alt.size()) + ) + return true; return false; }