Skip to content

Commit

Permalink
Defensive coding to avoid 0x80000000/0xFFFFFFFF FPE.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse authored and hassec committed Jun 30, 2021
1 parent a789ca3 commit cdec9dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions include/exiv2/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ namespace Exiv2 {
{
value_.clear();
long ts = TypeInfo::typeSize(typeId());
if (ts != 0)
if (ts > 0)
if (len % ts != 0) len = (len / ts) * ts;
for (long i = 0; i < len; i += ts) {
value_.push_back(getValue<T>(buf + i, byteOrder));
Expand Down Expand Up @@ -1644,15 +1644,15 @@ namespace Exiv2 {
template<>
inline long ValueType<Rational>::toLong(long n) const
{
ok_ = (value_.at(n).second != 0 && INT_MIN < value_.at(n).first && value_.at(n).first < INT_MAX );
ok_ = (value_.at(n).second > 0 && INT_MIN < value_.at(n).first && value_.at(n).first < INT_MAX );
if (!ok_) return 0;
return value_.at(n).first / value_.at(n).second;
}
// Specialization for unsigned rational
template<>
inline long ValueType<URational>::toLong(long n) const
{
ok_ = (value_.at(n).second != 0 && value_.at(n).first < LARGE_INT);
ok_ = (value_.at(n).second > 0 && value_.at(n).first < LARGE_INT);
if (!ok_) return 0;
return value_.at(n).first / value_.at(n).second;
}
Expand Down
2 changes: 1 addition & 1 deletion src/tags_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,7 @@ namespace Exiv2 {
std::ostream& printLong(std::ostream& os, const Value& value, const ExifData*)
{
Rational r = value.toRational();
if (r.second != 0) return os << static_cast<long>(r.first) / r.second;
if (r.second > 0) return os << static_cast<long>(r.first) / r.second;
return os << "(" << value << ")";
} // printLong

Expand Down

0 comments on commit cdec9dd

Please sign in to comment.