Skip to content
Permalink
Browse files

Add Inflator::BadDistanceErr exception (Issue 414)

The improved validation and excpetion clears the Address Sanitizer and Undefined Behavior Sanitizer findings
  • Loading branch information...
noloader committed May 10, 2017
1 parent e456cd2 commit 07dbcc3d9644b18e05c1776db2a57fe04d780965
Showing with 14 additions and 4 deletions.
  1. +3 −3 validat1.cpp
  2. +7 −1 zinflate.cpp
  3. +4 −0 zinflate.h
@@ -623,7 +623,7 @@ bool TestRandomPool()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " GenerateWord32 and Crop\n";
std::cout << " GenerateWord32 and Crop\n";
}

#if !defined(NO_OS_DEPENDENCE)
@@ -711,7 +711,7 @@ bool TestRandomPool()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " GenerateWord32 and Crop\n";
std::cout << " GenerateWord32 and Crop\n";
}
#endif

@@ -808,7 +808,7 @@ bool TestAutoSeededX917()
std::cout << "FAILED:";
else
std::cout << "passed:";
std::cout << " GenerateWord32 and Crop\n";
std::cout << " GenerateWord32 and Crop\n";

std::cout.flush();
return pass;
@@ -552,12 +552,18 @@ bool Inflator::DecodeBody()
case DISTANCE_BITS:
// TODO: this surfaced during fuzzing. What do we do???
CRYPTOPP_ASSERT(m_distance < COUNTOF(distanceExtraBits));
bits = (m_distance >= COUNTOF(distanceExtraBits)) ? distanceExtraBits[29] : distanceExtraBits[m_distance];
if (m_distance >= COUNTOF(distanceExtraBits))
throw BadDistanceErr();
bits = distanceExtraBits[m_distance];
if (!m_reader.FillBuffer(bits))
{
m_nextDecode = DISTANCE_BITS;
break;
}
// TODO: this surfaced during fuzzing. What do we do???
CRYPTOPP_ASSERT(m_distance < COUNTOF(distanceStarts));
if (m_distance >= COUNTOF(distanceStarts))
throw BadDistanceErr();
m_distance = m_reader.GetBits(bits) + distanceStarts[m_distance];
OutputPast(m_literal, m_distance);
}
@@ -98,8 +98,12 @@ class Inflator : public AutoSignaling<Filter>
Err(ErrorType e, const std::string &s)
: Exception(e, s) {}
};
//! \brief Exception thrown when a truncated stream is encountered
class UnexpectedEndErr : public Err {public: UnexpectedEndErr() : Err(INVALID_DATA_FORMAT, "Inflator: unexpected end of compressed block") {}};
//! \brief Exception thrown when a bad block is encountered
class BadBlockErr : public Err {public: BadBlockErr() : Err(INVALID_DATA_FORMAT, "Inflator: error in compressed block") {}};
//! \brief Exception thrown when an invalid distance is encountered
class BadDistanceErr : public Err {public: BadDistanceErr() : Err(INVALID_DATA_FORMAT, "Inflator: error in bit distance") {}};

//! \brief RFC 1951 Decompressor
//! \param attachment the filter's attached transformation

1 comment on commit 07dbcc3

@noloader

This comment has been minimized.

Copy link
Collaborator Author

commented on 07dbcc3 May 10, 2017

Also see Issue 414 and RFC 1950/Inflator feedback needed on the mailing list.

Please sign in to comment.
You can’t perform that action at this time.