Add Inflator::BadDistanceErr exception
authorJeffrey Walton <noloader@gmail.com>
Tue, 27 Jun 2017 19:04:20 +0000 (20:04 +0100)
committerLaszlo Boszormenyi (GCS) <gcs@debian.org>
Tue, 27 Jun 2017 19:04:20 +0000 (20:04 +0100)
Origin: upstream, https://github.com/weidai11/cryptopp/commit/07dbcc3d9644b18e05c1776db2a57fe04d780965
Bug: https://github.com/weidai11/cryptopp/issues/414
Last-Update: 2017-06-05

The improved validation and excpetion clears the Address Sanitizer and
Undefined Behavior Sanitizer findings

Gbp-Pq: Name zinflate-564.diff

zinflate.cpp
zinflate.h

index adffca017d0f0c3060bd0c9555bec3e5486abc9a..1a12460f02c8f0d80a0d69d4a2580570df58a3a0 100644 (file)
@@ -550,12 +550,16 @@ bool Inflator::DecodeBody()
                                                break;\r
                                        }\r
                case DISTANCE_BITS:\r
+                                       if (m_distance >= sizeof(distanceExtraBits)/sizeof(distanceExtraBits[0]))\r
+                                               throw BadDistanceErr();\r
                                        bits = distanceExtraBits[m_distance];\r
                                        if (!m_reader.FillBuffer(bits))\r
                                        {\r
                                                m_nextDecode = DISTANCE_BITS;\r
                                                break;\r
                                        }\r
+                                       if (m_distance >= sizeof(distanceStarts)/sizeof(distanceStarts[0]))\r
+                                               throw BadDistanceErr();\r
                                        m_distance = m_reader.GetBits(bits) + distanceStarts[m_distance];\r
                                        OutputPast(m_literal, m_distance);\r
                                }\r
index 8c08ed08dc4ed8a6a7eaf1c5d543c6182f8e8242..6442969ddce5a85e3c3ef8cc4fa5b219e6730ec7 100644 (file)
@@ -96,6 +96,7 @@ public:
        };\r
        class UnexpectedEndErr : public Err {public: UnexpectedEndErr() : Err(INVALID_DATA_FORMAT, "Inflator: unexpected end of compressed block") {}};\r
        class BadBlockErr : public Err {public: BadBlockErr() : Err(INVALID_DATA_FORMAT, "Inflator: error in compressed block") {}};\r
+       class BadDistanceErr : public Err {public: BadDistanceErr() : Err(INVALID_DATA_FORMAT, "Inflator: error in bit distance") {}};\r
 \r
        //! \brief RFC 1951 Decompressor\r
        //! \param attachment the filter's attached transformation\r