From 59493d1edc57ebbc04c27597f2401b95aef15ae7 Mon Sep 17 00:00:00 2001 From: Luis Diaz Mas Date: Thu, 24 May 2018 23:51:05 +0200 Subject: [PATCH] Fix bug in Cr2Header::read --- src/cr2header_int.cpp | 4 +++- unitTests/test_cr2header_int.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cr2header_int.cpp b/src/cr2header_int.cpp index 23f3a2d6..5cc01bd1 100644 --- a/src/cr2header_int.cpp +++ b/src/cr2header_int.cpp @@ -17,7 +17,9 @@ namespace Exiv2 { bool Cr2Header::read(const byte* pData, uint32_t size) { - if (size < 16) return false; + if (!pData || size < 16) { + return false; + } if (pData[0] == 'I' && pData[0] == pData[1]) { setByteOrder(littleEndian); diff --git a/unitTests/test_cr2header_int.cpp b/unitTests/test_cr2header_int.cpp index e225cefb..4fd879c9 100644 --- a/unitTests/test_cr2header_int.cpp +++ b/unitTests/test_cr2header_int.cpp @@ -39,8 +39,8 @@ TEST(ACr2Header, failToReadDataFromBufferWithCorrectSizeButNull) TEST(ACr2Header, failToReadDataFromBufferWithSizeDifferentThan16) { Internal::Cr2Header header; - ASSERT_FALSE(header.read(NULL, 15)); - ASSERT_FALSE(header.read(NULL, 17)); + ASSERT_FALSE(header.read(cr2LittleEndian, 15)); + ASSERT_FALSE(header.read(cr2LittleEndian, 0)); } TEST(ACr2Header, failToReadDataFromBufferWithInvalidByteOrder)