From 10d190c7a6b030c9a51e9c662e63f283242d3fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Komar=C4=8Devi=C4=87?= Date: Thu, 15 Sep 2022 10:48:47 +0200 Subject: [PATCH] Initialize a non-empty PNG ICC profile name --- src/pngimage.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pngimage.cpp b/src/pngimage.cpp index f9a6bbd8ab..293e29e98e 100644 --- a/src/pngimage.cpp +++ b/src/pngimage.cpp @@ -52,7 +52,7 @@ namespace Exiv2 { using namespace Internal; PngImage::PngImage(BasicIo::UniquePtr io, bool create) : - Image(ImageType::png, mdExif | mdIptc | mdXmp | mdComment, std::move(io)) { + Image(ImageType::png, mdExif | mdIptc | mdXmp | mdComment, std::move(io)), profileName_("ICC Profile") { if (create && io_->open() == 0) { #ifdef EXIV2_DEBUG_MESSAGES std::cerr << "Exiv2::PngImage:: Creating PNG image to memory\n"; @@ -447,13 +447,16 @@ void PngImage::readMetadata() { enforce(iccOffset < 80 && iccOffset < chunkLength, Exiv2::ErrorCode::kerCorruptedMetadata); } while (chunkData.read_uint8(iccOffset++) != 0x00); - profileName_ = std::string(chunkData.c_str(), iccOffset - 1); + // Don't fail on empty ICC profile name, but also don't overwrite the default + std::string profileName = std::string(chunkData.c_str(), iccOffset - 1); + if (profileName.size() > 0) + profileName_ = profileName; ++iccOffset; // +1 = 'compressed' flag enforce(iccOffset <= chunkLength, Exiv2::ErrorCode::kerCorruptedMetadata); zlibToDataBuf(chunkData.c_data(iccOffset), static_cast(chunkLength - iccOffset), iccProfile_); #ifdef EXIV2_DEBUG_MESSAGES - std::cout << "Exiv2::PngImage::readMetadata: profile name: " << profileName_ << std::endl; + std::cout << "Exiv2::PngImage::readMetadata: profile name: " << profileName << std::endl; std::cout << "Exiv2::PngImage::readMetadata: iccProfile.size_ (uncompressed) : " << iccProfile_.size() << std::endl; #endif