diff --git a/src/bmffimage.cpp b/src/bmffimage.cpp index b6f6a90f5f..bd7cd3cf7b 100644 --- a/src/bmffimage.cpp +++ b/src/bmffimage.cpp @@ -363,8 +363,8 @@ uint64_t BmffImage::boxHandler(std::ostream& out /* = std::cout*/, Exiv2::PrintS // Check that the string has a '\0' terminator. const char* str = data.c_str(skip); const size_t maxlen = data.size() - skip; - Internal::enforce(maxlen > 0 && strnlen(str, maxlen) < maxlen, Exiv2::ErrorCode::kerCorruptedMetadata); std::string name(str); + Internal::enforce(maxlen > 0 && name.size() < maxlen, Exiv2::ErrorCode::kerCorruptedMetadata); if (Internal::contains(name, "Exif")) { // "Exif" or "ExifExif" exifID_ = ID; id = " *** Exif ***"; diff --git a/src/helper_functions.cpp b/src/helper_functions.cpp index 736d2a4b14..351de439e0 100644 --- a/src/helper_functions.cpp +++ b/src/helper_functions.cpp @@ -13,7 +13,10 @@ std::string string_from_unterminated(const char* data, size_t data_length) { if (data_length == 0) { return {}; } - const size_t StringLength = strnlen(data, data_length); + size_t StringLength = 0; + while (StringLength < data_length && data[StringLength] != '\0') { + StringLength++; + } return {data, StringLength}; }