]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Check for (and throw on) large min repeat
authorJustin Viiret <justin.viiret@intel.com>
Wed, 28 Oct 2015 22:08:40 +0000 (09:08 +1100)
committerMatthew Barr <matthew.barr@intel.com>
Fri, 30 Oct 2015 00:28:37 +0000 (11:28 +1100)
We were only checking for large maximum bounds, which meant that we
would attempt to compile A{N,} where N is huge.

src/parser/ComponentRepeat.cpp
unit/hyperscan/bad_patterns.txt

index 325114d8543a156a39c6a3a0fae90fc483c5d1a4..8cd8837243b5e42876d1a591332b41c370c674f1 100644 (file)
@@ -51,11 +51,11 @@ using namespace std;
 namespace ue2 {
 
 /** \brief Hard limit on the maximum repeat for bounded repeats. */
-static const u32 MAX_MAX_BOUND = 32767;
+static constexpr u32 MAX_REPEAT = 32767;
 
 /** \brief If expanding a repeat would lead to this many positions being
  * generated, we fail the pattern. */
-static const u32 MAX_POSITIONS_EXPANDED = 500000; // arbitrarily huge
+static constexpr u32 MAX_POSITIONS_EXPANDED = 500000; // arbitrarily huge
 
 /* no edge priorities means that if our subcomponent can be empty, our min
  * extent is effectively zero. */
@@ -67,7 +67,11 @@ ComponentRepeat::ComponentRepeat(unique_ptr<Component> sub_comp_in, u32 min,
     assert(sub_comp);
     assert(max > 0);
     assert(m_min <= m_max);
-    if (m_max < NoLimit && m_max > MAX_MAX_BOUND) {
+
+    if (m_min > MAX_REPEAT) {
+        throw ParseError("Bounded repeat is too large.");
+    }
+    if (m_max != NoLimit && m_max > MAX_REPEAT) {
         throw ParseError("Bounded repeat is too large.");
     }
 }
@@ -119,7 +123,7 @@ void checkPositions(vector<PositionInfo> &v, const GlushkovBuildState &bs) {
 
 void ComponentRepeat::notePositions(GlushkovBuildState &bs) {
     assert(m_max > 0);
-    assert(m_max == NoLimit || m_max < MAX_MAX_BOUND);
+    assert(m_max == NoLimit || m_max < MAX_REPEAT);
 
     /* Note: We can construct smaller subgraphs if we're not maintaining edge
      * priorities. */
index 53a4dcc01955e2ba9a6df6c8717ba1f18f386528..1ad445b363ec1da73b93c559f826735aaef58f93 100644 (file)
 127:/^fo?ob{ro|nax_off\Qt=10omnax+8Wnah/ñññññññññññññññññññññññññññ0}l.{1,60}Car*k|npanomnax+8Wnah/8 #Expression is not valid UTF-8.
 128:/(*UTF8)^fo?ob{ro|nax_off\Qt=10omnax+8Wnah/ñññññññññññññññññññññññññññ0}l.{1,60}Car*k|npanomnax+8Wnah/ #Expression is not valid UTF-8.
 129:/bignum \1111111111111111111/ #Number is too big at index 7.
+130:/foo|&{5555555,}/ #Bounded repeat is too large.