Description: Apply upstream revision 1631 (Closes: #815921)
 This is an upstream patch to fix workspace overflow for (*ACCEPT) with
 deeply nested parentheses
Author: Matthew Vernon <matthew@debian.org>
X-Dgit-Generated: 2:8.38-2 50aa7778a6bb8b81a9e03e8744f797362183772e

---

Index: pcre3-8.31/pcreposix.c
===================================================================
--- pcre3-8.31.orig/pcreposix.c	2016-03-24 13:13:40.286993129 -0400
+++ pcre3-8.31/pcreposix.c	2016-03-24 13:14:25.491561003 -0400
@@ -161,7 +161,8 @@
   REG_BADPAT,  /* invalid UTF-16 string (should not occur) */
   /* 75 */
   REG_BADPAT,  /* overlong MARK name */
-  REG_BADPAT   /* character value in \u.... sequence is too large */
+  REG_BADPAT,  /* character value in \u.... sequence is too large */
+  REG_BADPAT   /* pattern too complicated */
 };
 
 /* Table of texts corresponding to POSIX error codes */
Index: pcre3-8.31/pcre_compile.c
===================================================================
--- pcre3-8.31.orig/pcre_compile.c	2016-03-24 13:13:40.286993129 -0400
+++ pcre3-8.31/pcre_compile.c	2016-03-24 13:15:00.135996257 -0400
@@ -492,6 +492,7 @@
   /* 75 */
   "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"
   "character value in \\u.... sequence is too large\0"
+  "regular expression is too complicated\0"
   ;
 
 /* Table to identify digits and hex digits. This is used when compiling
@@ -3551,7 +3552,8 @@
     if (code > cd->start_workspace + cd->workspace_size -
         WORK_SIZE_SAFETY_MARGIN)                       /* Check for overrun */
       {
-      *errorcodeptr = ERR52;
+      *errorcodeptr = (code >= cd->start_workspace + cd->workspace_size)?
+        ERR52 : ERR77;
       goto FAILED;
       }
 
@@ -5644,8 +5646,21 @@
             cd->had_accept = TRUE;
             for (oc = cd->open_caps; oc != NULL; oc = oc->next)
               {
-              *code++ = OP_CLOSE;
-              PUT2INC(code, 0, oc->number);
+              if (lengthptr != NULL)
+                {
+#ifdef COMPILE_PCRE8
+                *lengthptr += 1 + IMM2_SIZE;
+#elif defined COMPILE_PCRE16
+                *lengthptr += 2 + IMM2_SIZE;
+#elif defined COMPILE_PCRE32
+                *lengthptr += 4 + IMM2_SIZE;
+#endif
+                }
+              else
+                {
+                *code++ = OP_CLOSE;
+                PUT2INC(code, 0, oc->number);
+                }
               }
             *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
 
Index: pcre3-8.31/pcre_internal.h
===================================================================
--- pcre3-8.31.orig/pcre_internal.h	2016-03-24 13:13:40.286993129 -0400
+++ pcre3-8.31/pcre_internal.h	2016-03-24 13:15:20.660254126 -0400
@@ -1945,7 +1945,7 @@
        ERR40, ERR41, ERR42, ERR43, ERR44, ERR45, ERR46, ERR47, ERR48, ERR49,
        ERR50, ERR51, ERR52, ERR53, ERR54, ERR55, ERR56, ERR57, ERR58, ERR59,
        ERR60, ERR61, ERR62, ERR63, ERR64, ERR65, ERR66, ERR67, ERR68, ERR69,
-       ERR70, ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERRCOUNT };
+       ERR70, ERR71, ERR72, ERR73, ERR74, ERR75, ERR76, ERR77, ERRCOUNT };
 
 /* JIT compiling modes. The function list is indexed by them. */
 enum { JIT_COMPILE, JIT_PARTIAL_SOFT_COMPILE, JIT_PARTIAL_HARD_COMPILE,
Index: pcre3-8.31/testdata/testoutput11-8
===================================================================
--- pcre3-8.31.orig/testdata/testoutput11-8	2016-03-24 13:13:40.286993129 -0400
+++ pcre3-8.31/testdata/testoutput11-8	2016-03-24 13:13:40.282993080 -0400
@@ -749,4 +749,7 @@
  34     End
 ------------------------------------------------------------------
 
+/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/
+Failed: missing ) at offset 509
+
 /-- End of testinput11 --/
Index: pcre3-8.31/testdata/testoutput11-16
===================================================================
--- pcre3-8.31.orig/testdata/testoutput11-16	2016-03-24 13:13:40.286993129 -0400
+++ pcre3-8.31/testdata/testoutput11-16	2016-03-24 13:13:40.282993080 -0400
@@ -749,4 +749,7 @@
  22     End
 ------------------------------------------------------------------
 
+/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/
+Failed: regular expression is too complicated at offset 490
+
 /-- End of testinput11 --/
Index: pcre3-8.31/testdata/testinput11
===================================================================
--- pcre3-8.31.orig/testdata/testinput11	2016-03-24 13:13:40.286993129 -0400
+++ pcre3-8.31/testdata/testinput11	2016-03-24 13:13:40.282993080 -0400
@@ -136,4 +136,6 @@
 
 /((?+1)(\1))/B
 
+/([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00]([00](*ACCEPT)/
+
 /-- End of testinput11 --/
