#568: Check for empty value when creating thumbnail and preventively also in a number of other places.

v0.27.3
Andreas Huggel 17 years ago
parent c5ebed2d9b
commit ec1ea1fe80

@ -494,14 +494,14 @@ namespace Action {
if (md == exifData.end()) {
md = exifData.findKey(Exiv2::ExifKey("Exif.Photo.PixelXDimension"));
}
if (md != exifData.end()) {
if (md != exifData.end() && md->count() > 0) {
xdim = md->toLong();
}
md = exifData.findKey(Exiv2::ExifKey("Exif.Image.ImageLength"));
if (md == exifData.end()) {
md = exifData.findKey(Exiv2::ExifKey("Exif.Photo.PixelYDimension"));
}
if (md != exifData.end()) {
if (md != exifData.end() && md->count() > 0) {
ydim = md->toLong();
}
if (xdim != 0 && ydim != 0) {

@ -475,7 +475,7 @@ namespace Exiv2 {
{
Exiv2::ExifData::iterator pos = exifData_->findKey(ExifKey(from));
if (pos == exifData_->end()) return;
std::string value = pos->value().toString();
std::string value = pos->toString();
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -509,8 +509,8 @@ namespace Exiv2 {
Exiv2::ExifData::iterator pos = exifData_->findKey(ExifKey(from));
if (pos == exifData_->end()) return;
if (!prepareXmpTarget(to)) return;
for (int i = 0; i < pos->value().count(); ++i) {
std::string value = pos->value().toString(i);
for (int i = 0; i < pos->count(); ++i) {
std::string value = pos->toString(i);
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -532,7 +532,7 @@ namespace Exiv2 {
char buf[30];
if (std::string(from) != "Exif.GPSInfo.GPSTimeStamp") {
std::string value = pos->value().toString();
std::string value = pos->toString();
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -550,10 +550,10 @@ namespace Exiv2 {
else { // "Exif.GPSInfo.GPSTimeStamp"
bool ok = true;
if (pos->value().count() != 3) ok = false;
if (pos->count() != 3) ok = false;
if (ok) {
for (int i = 0; i < 3; ++i) {
if (pos->value().toRational(i).second == 0) {
if (pos->toRational(i).second == 0) {
ok = false;
break;
}
@ -566,10 +566,10 @@ namespace Exiv2 {
return;
}
double dhour = pos->value().toFloat(0);
double dmin = pos->value().toFloat(1);
double dhour = pos->toFloat(0);
double dmin = pos->toFloat(1);
// Hack: Need Value::toDouble
URational r = pos->value().toRational(2);
URational r = pos->toRational(2);
double dsec = static_cast<double>(r.first)/r.second;
if (!pos->value().ok()) {
@ -605,7 +605,7 @@ namespace Exiv2 {
#endif
return;
}
std::string value = datePos->value().toString();
std::string value = datePos->toString();
if (sscanf(value.c_str(), "%d:%d:%d", &year, &month, &day) != 3) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to
@ -629,8 +629,8 @@ namespace Exiv2 {
if (subsecTag) {
Exiv2::ExifData::iterator subsec_pos = exifData_->findKey(ExifKey(subsecTag));
if ( subsec_pos != exifData_->end()
&& !subsec_pos->value().toString().empty()) {
subsec = std::string(".") + subsec_pos->value().toString();
&& !subsec_pos->toString().empty()) {
subsec = std::string(".") + subsec_pos->toString();
}
if (erase_) exifData_->erase(subsec_pos);
}
@ -650,8 +650,8 @@ namespace Exiv2 {
if (pos == exifData_->end()) return;
if (!prepareXmpTarget(to)) return;
std::ostringstream value;
for (int i = 0; i < pos->value().count(); ++i) {
value << static_cast<char>(pos->value().toLong(i));
for (int i = 0; i < pos->count(); ++i) {
value << static_cast<char>(pos->toLong(i));
}
(*xmpData_)[to] = value.str();
if (erase_) exifData_->erase(pos);
@ -663,9 +663,9 @@ namespace Exiv2 {
if (pos == exifData_->end()) return;
if (!prepareXmpTarget(to)) return;
std::ostringstream value;
for (int i = 0; i < pos->value().count(); ++i) {
for (int i = 0; i < pos->count(); ++i) {
if (i > 0) value << '.';
value << pos->value().toLong(i);
value << pos->toLong(i);
}
(*xmpData_)[to] = value.str();
if (erase_) exifData_->erase(pos);
@ -674,9 +674,9 @@ namespace Exiv2 {
void Converter::cnvExifFlash(const char* from, const char* to)
{
Exiv2::ExifData::iterator pos = exifData_->findKey(ExifKey(from));
if (pos == exifData_->end()) return;
if (pos == exifData_->end() || pos->count() == 0) return;
if (!prepareXmpTarget(to)) return;
int value = pos->value().toLong();
int value = pos->toLong();
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -698,7 +698,7 @@ namespace Exiv2 {
Exiv2::ExifData::iterator pos = exifData_->findKey(ExifKey(from));
if (pos == exifData_->end()) return;
if (!prepareXmpTarget(to)) return;
if (pos->value().count() != 3) {
if (pos->count() != 3) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
#endif
@ -713,8 +713,8 @@ namespace Exiv2 {
}
double deg[3];
for (int i = 0; i < 3; ++i) {
const int32_t z = pos->value().toRational(i).first;
const int32_t d = pos->value().toRational(i).second;
const int32_t z = pos->toRational(i).first;
const int32_t d = pos->toRational(i).second;
if (d == 0) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -730,7 +730,7 @@ namespace Exiv2 {
std::ostringstream oss;
oss << ideg << ","
<< std::fixed << std::setprecision(7) << min
<< refPos->value().toString().c_str()[0];
<< refPos->toString().c_str()[0];
(*xmpData_)[to] = oss.str();
if (erase_) exifData_->erase(pos);
@ -777,8 +777,8 @@ namespace Exiv2 {
Exiv2::XmpData::iterator pos = xmpData_->findKey(XmpKey(from));
if (pos == xmpData_->end()) return;
std::ostringstream array;
for (int i = 0; i < pos->value().count(); ++i) {
std::string value = pos->value().toString(i);
for (int i = 0; i < pos->count(); ++i) {
std::string value = pos->toString(i);
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -797,7 +797,7 @@ namespace Exiv2 {
Exiv2::XmpData::iterator pos = xmpData_->findKey(XmpKey(from));
if (pos == xmpData_->end()) return;
if (!prepareExifTarget(to)) return;
std::string value = pos->value().toString();
std::string value = pos->toString();
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -882,7 +882,7 @@ namespace Exiv2 {
Exiv2::XmpData::iterator pos = xmpData_->findKey(XmpKey(from));
if (pos == xmpData_->end()) return;
if (!prepareExifTarget(to)) return;
std::string value = pos->value().toString();
std::string value = pos->toString();
if (!pos->value().ok() || value.length() < 4) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -905,7 +905,7 @@ namespace Exiv2 {
Exiv2::XmpData::iterator pos = xmpData_->findKey(XmpKey(from));
if (pos == xmpData_->end()) return;
if (!prepareExifTarget(to)) return;
std::string value = pos->value().toString();
std::string value = pos->toString();
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -928,8 +928,8 @@ namespace Exiv2 {
if (!prepareExifTarget(to)) return;
unsigned short value = 0;
if (pos != xmpData_->end()) {
int fired = pos->value().toLong();
if (pos != xmpData_->end() && pos->count() > 0) {
int fired = pos->toLong();
if (pos->value().ok())
value |= fired & 1;
#ifndef SUPPRESS_WARNINGS
@ -938,8 +938,8 @@ namespace Exiv2 {
#endif
}
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Return"));
if (pos != xmpData_->end()) {
int ret = pos->value().toLong();
if (pos != xmpData_->end() && pos->count() > 0) {
int ret = pos->toLong();
if (pos->value().ok())
value |= (ret & 3) << 1;
#ifndef SUPPRESS_WARNINGS
@ -948,8 +948,8 @@ namespace Exiv2 {
#endif
}
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Mode"));
if (pos != xmpData_->end()) {
int mode = pos->value().toLong();
if (pos != xmpData_->end() && pos->count() > 0) {
int mode = pos->toLong();
if (pos->value().ok())
value |= (mode & 3) << 3;
#ifndef SUPPRESS_WARNINGS
@ -958,8 +958,8 @@ namespace Exiv2 {
#endif
}
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:Function"));
if (pos != xmpData_->end()) {
int function = pos->value().toLong();
if (pos != xmpData_->end() && pos->count() > 0) {
int function = pos->toLong();
if (pos->value().ok())
value |= (function & 1) << 5;
#ifndef SUPPRESS_WARNINGS
@ -968,8 +968,8 @@ namespace Exiv2 {
#endif
}
pos = xmpData_->findKey(XmpKey(std::string(from) + "/exif:RedEyeMode"));
if (pos != xmpData_->end()) {
int red = pos->value().toLong();
if (pos != xmpData_->end() && pos->count() > 0) {
int red = pos->toLong();
if (pos->value().ok())
value |= (red & 1) << 6;
#ifndef SUPPRESS_WARNINGS
@ -987,7 +987,7 @@ namespace Exiv2 {
Exiv2::XmpData::iterator pos = xmpData_->findKey(XmpKey(from));
if (pos == xmpData_->end()) return;
if (!prepareExifTarget(to)) return;
std::string value = pos->value().toString();
std::string value = pos->toString();
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -1044,7 +1044,7 @@ namespace Exiv2 {
if (!prepareXmpTarget(to)) return;
while (pos != iptcData_->end()) {
if (pos->key() == from) {
std::string value = pos->value().toString();
std::string value = pos->toString();
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -1082,9 +1082,9 @@ namespace Exiv2 {
return;
}
int count = pos->value().count();
int count = pos->count();
for (int i = 0; i < count; ++i) {
std::string value = pos->value().toString(i);
std::string value = pos->toString(i);
if (!pos->value().ok()) {
#ifndef SUPPRESS_WARNINGS
std::cerr << "Warning: Failed to convert " << from << " to " << to << "\n";
@ -1119,8 +1119,8 @@ namespace Exiv2 {
res << key.tag();
Exiv2::ExifData::iterator pos = exifData_->findKey(key);
if (pos == exifData_->end()) continue;
DataBuf data(pos->value().size());
pos->value().copy(data.pData_, littleEndian /* FIXME ? */);
DataBuf data(pos->size());
pos->copy(data.pData_, littleEndian /* FIXME ? */);
MD5Update ( &context, data.pData_, data.size_);
}
}
@ -1274,11 +1274,11 @@ namespace {
{
if (pos->typeId() == Exiv2::langAlt) {
// get the default language entry without x-default qualifier
value = pos->value().toString(0);
value = pos->toString(0);
if (!pos->value().ok() && pos->count() == 1) {
// If there is no default but exactly one entry, take that
// without the qualifier
value = pos->value().toString();
value = pos->toString();
if ( pos->value().ok()
&& value.length() > 5 && value.substr(0, 5) == "lang=") {
std::string::size_type pos = value.find_first_of(' ');
@ -1292,7 +1292,7 @@ namespace {
}
}
else {
value = pos->value().toString();
value = pos->toString();
}
return pos->value().ok();
}

@ -66,14 +66,20 @@ namespace Exiv2 {
int Cr2Image::pixelWidth() const
{
Exiv2::ExifData::const_iterator widthIter = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelXDimension"));
return (widthIter == exifData_.end()) ? 0 : widthIter->toLong();
ExifData::const_iterator imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelXDimension"));
if (imageWidth != exifData_.end() && imageWidth->count() > 0) {
return imageWidth->toLong();
}
return 0;
}
int Cr2Image::pixelHeight() const
{
Exiv2::ExifData::const_iterator heightIter = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelYDimension"));
return (heightIter == exifData_.end()) ? 0 : heightIter->toLong();
ExifData::const_iterator imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelYDimension"));
if (imageHeight != exifData_.end() && imageHeight->count() > 0) {
return imageHeight->toLong();
}
return 0;
}
void Cr2Image::setExifData(const ExifData& /*exifData*/)

@ -98,13 +98,19 @@ namespace Exiv2 {
int CrwImage::pixelWidth() const
{
Exiv2::ExifData::const_iterator widthIter = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelXDimension"));
return (widthIter == exifData_.end()) ? 0 : widthIter->toLong();
if (widthIter != exifData_.end() && widthIter->count() > 0) {
return widthIter->toLong();
}
return 0;
}
int CrwImage::pixelHeight() const
{
Exiv2::ExifData::const_iterator heightIter = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelYDimension"));
return (heightIter == exifData_.end()) ? 0 : heightIter->toLong();
if (heightIter != exifData_.end() && heightIter->count() > 0) {
return heightIter->toLong();
}
return 0;
}
void CrwImage::setIptcData(const IptcData& /*iptcData*/)
@ -1310,7 +1316,7 @@ namespace Exiv2 {
edY->copy(buf.pData_ + 4, pHead->byteOrder());
}
int32_t d = 0;
if (edO != edEnd && edO->typeId() == unsignedShort) {
if (edO != edEnd && edO->count() > 0 && edO->typeId() == unsignedShort) {
d = RotationMap::degrees(static_cast<uint16_t>(edO->toLong()));
}
l2Data(buf.pData_ + 12, d, pHead->byteOrder());

@ -481,6 +481,7 @@ namespace {
const Exiv2::ExifKey k1("Exif.Thumbnail.Compression");
Exiv2::ExifData::const_iterator pos = exifData.findKey(k1);
if (pos != exifData.end()) {
if (pos->count() == 0) return thumbnail;
long compression = pos->toLong();
if (compression == 6) {
thumbnail = Thumbnail::AutoPtr(new JpegThumbnail);

@ -61,9 +61,8 @@ namespace Exiv2 {
int MrwImage::pixelWidth() const
{
ExifData::const_iterator imageWidth;
if ((imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageWidth"))) != exifData_.end())
{
ExifData::const_iterator imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageWidth"));
if (imageWidth != exifData_.end() && imageWidth->count() > 0) {
return imageWidth->toLong();
}
return 0;
@ -71,9 +70,8 @@ namespace Exiv2 {
int MrwImage::pixelHeight() const
{
ExifData::const_iterator imageHeight;
if ((imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageLength"))) != exifData_.end())
{
ExifData::const_iterator imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageLength"));
if (imageHeight != exifData_.end() && imageHeight->count() > 0) {
return imageHeight->toLong();
}
return 0;

@ -64,9 +64,8 @@ namespace Exiv2 {
int OrfImage::pixelWidth() const
{
ExifData::const_iterator imageWidth;
if ((imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageWidth"))) != exifData_.end())
{
ExifData::const_iterator imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageWidth"));
if (imageWidth != exifData_.end() && imageWidth->count() > 0) {
return imageWidth->toLong();
}
return 0;
@ -74,9 +73,8 @@ namespace Exiv2 {
int OrfImage::pixelHeight() const
{
ExifData::const_iterator imageHeight;
if ((imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageLength"))) != exifData_.end())
{
ExifData::const_iterator imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageLength"));
if (imageHeight != exifData_.end() && imageHeight->count() > 0) {
return imageHeight->toLong();
}
return 0;

@ -62,13 +62,19 @@ namespace Exiv2 {
int RafImage::pixelWidth() const
{
Exiv2::ExifData::const_iterator widthIter = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelXDimension"));
return (widthIter == exifData_.end()) ? 0 : widthIter->toLong();
if (widthIter != exifData_.end() && widthIter->count() > 0) {
return widthIter->toLong();
}
return 0;
}
int RafImage::pixelHeight() const
{
Exiv2::ExifData::const_iterator heightIter = exifData_.findKey(Exiv2::ExifKey("Exif.Photo.PixelYDimension"));
return (heightIter == exifData_.end()) ? 0 : heightIter->toLong();
if (heightIter != exifData_.end() && heightIter->count() > 0) {
return heightIter->toLong();
}
return 0;
}
void RafImage::setExifData(const ExifData& /*exifData*/)

@ -99,9 +99,8 @@ namespace Exiv2 {
int TiffImage::pixelWidth() const
{
ExifData::const_iterator imageWidth;
if ((imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageWidth"))) != exifData_.end())
{
ExifData::const_iterator imageWidth = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageWidth"));
if (imageWidth != exifData_.end() && imageWidth->count() > 0) {
return imageWidth->toLong();
}
return 0;
@ -109,9 +108,8 @@ namespace Exiv2 {
int TiffImage::pixelHeight() const
{
ExifData::const_iterator imageHeight;
if ((imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageLength"))) != exifData_.end())
{
ExifData::const_iterator imageHeight = exifData_.findKey(Exiv2::ExifKey("Exif.Image.ImageLength"));
if (imageHeight != exifData_.end() && imageHeight->count() > 0) {
return imageHeight->toLong();
}
return 0;

@ -332,11 +332,6 @@ namespace Exiv2 {
// Don't decode the entry if value is not set
if (!object->pValue()) return;
// Remember NewSubfileType
if (object->tag() == 0x00fe) {
groupType_[object->group()] = object->pValue()->toLong();
}
const DecoderFct decoderFct = findDecoderFct_(make_,
object->tag(),
object->group());

@ -295,11 +295,6 @@ namespace Exiv2 {
TiffComponent* const pRoot_; //!< Root element of the composite
const FindDecoderFct findDecoderFct_; //!< Ptr to the function to find special decoding functions
std::string make_; //!< Camera make, determined from the tags to decode
//! Type used to remember tag 0x00fe (NewSubfileType) for each group
typedef std::map<uint16_t, uint32_t> GroupType;
GroupType groupType_; //!< NewSubfileType for each group
bool decodedIptc_; //!< Indicates if IPTC has been decoded yet
}; // class TiffDecoder

Loading…
Cancel
Save