Blame SOURCES/pcre2-10.23-Fix-32-bit-non-UTF-property-test-crash.patch

5a0827
From be14c2f3f01dc2b6b574b3a86536ee8194945f7f Mon Sep 17 00:00:00 2001
5a0827
From: ph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>
5a0827
Date: Fri, 24 Feb 2017 18:25:32 +0000
5a0827
Subject: [PATCH] Fix 32-bit non-UTF property test crash.
5a0827
MIME-Version: 1.0
5a0827
Content-Type: text/plain; charset=UTF-8
5a0827
Content-Transfer-Encoding: 8bit
5a0827
5a0827
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@670 6239d852-aaf2-0410-a92c-79f79f948069
5a0827
5a0827
Petr Písař: Ported to 10.23.
5a0827
5a0827
diff --git a/src/pcre2_internal.h b/src/pcre2_internal.h
5a0827
index 6a8774c..720bbc9 100644
5a0827
--- a/src/pcre2_internal.h
5a0827
+++ b/src/pcre2_internal.h
5a0827
@@ -1774,10 +1774,17 @@ typedef struct {
5a0827
 /* UCD access macros */
5a0827
 
5a0827
 #define UCD_BLOCK_SIZE 128
5a0827
-#define GET_UCD(ch) (PRIV(ucd_records) + \
5a0827
+#define REAL_GET_UCD(ch) (PRIV(ucd_records) + \
5a0827
         PRIV(ucd_stage2)[PRIV(ucd_stage1)[(int)(ch) / UCD_BLOCK_SIZE] * \
5a0827
         UCD_BLOCK_SIZE + (int)(ch) % UCD_BLOCK_SIZE])
5a0827
 
5a0827
+#if PCRE2_CODE_UNIT_WIDTH == 32
5a0827
+#define GET_UCD(ch) ((ch > MAX_UTF_CODE_POINT)? \
5a0827
+  PRIV(dummy_ucd_record) : REAL_GET_UCD(ch))
5a0827
+#else
5a0827
+#define GET_UCD(ch) REAL_GET_UCD(ch)
5a0827
+#endif
5a0827
+
5a0827
 #define UCD_CHARTYPE(ch)    GET_UCD(ch)->chartype
5a0827
 #define UCD_SCRIPT(ch)      GET_UCD(ch)->script
5a0827
 #define UCD_CATEGORY(ch)    PRIV(ucp_gentype)[UCD_CHARTYPE(ch)]
5a0827
@@ -1834,6 +1841,9 @@ extern const uint8_t          PRIV(utf8_table4)[];
5a0827
 #define _pcre2_default_compile_context PCRE2_SUFFIX(_pcre2_default_compile_context_)
5a0827
 #define _pcre2_default_match_context   PCRE2_SUFFIX(_pcre2_default_match_context_)
5a0827
 #define _pcre2_default_tables          PCRE2_SUFFIX(_pcre2_default_tables_)
5a0827
+#if PCRE2_CODE_UNIT_WIDTH == 32
5a0827
+#define _pcre2_dummy_ucd_record        PCRE2_SUFFIX(_pcre2_dummy_ucd_record_)
5a0827
+#endif
5a0827
 #define _pcre2_hspace_list             PCRE2_SUFFIX(_pcre2_hspace_list_)
5a0827
 #define _pcre2_vspace_list             PCRE2_SUFFIX(_pcre2_vspace_list_)
5a0827
 #define _pcre2_ucd_caseless_sets       PCRE2_SUFFIX(_pcre2_ucd_caseless_sets_)
5a0827
@@ -1858,6 +1868,9 @@ extern const uint32_t                  PRIV(hspace_list)[];
5a0827
 extern const uint32_t                  PRIV(vspace_list)[];
5a0827
 extern const uint32_t                  PRIV(ucd_caseless_sets)[];
5a0827
 extern const ucd_record                PRIV(ucd_records)[];
5a0827
+#if PCRE2_CODE_UNIT_WIDTH == 32
5a0827
+extern const ucd_record                PRIV(dummy_ucd_record)[];
5a0827
+#endif
5a0827
 extern const uint8_t                   PRIV(ucd_stage1)[];
5a0827
 extern const uint16_t                  PRIV(ucd_stage2)[];
5a0827
 extern const uint32_t                  PRIV(ucp_gbtable)[];
5a0827
diff --git a/src/pcre2_ucd.c b/src/pcre2_ucd.c
5a0827
index 116f537..56aa29d 100644
5a0827
--- a/src/pcre2_ucd.c
5a0827
+++ b/src/pcre2_ucd.c
5a0827
@@ -41,6 +41,20 @@ const uint32_t PRIV(ucd_caseless_sets)[] = {0};
5a0827
 
5a0827
 const char *PRIV(unicode_version) = "8.0.0";
5a0827
 
5a0827
+/* If the 32-bit library is run in non-32-bit mode, character values
5a0827
+greater than 0x10ffff may be encountered. For these we set up a
5a0827
+special record. */
5a0827
+
5a0827
+#if PCRE2_CODE_UNIT_WIDTH == 32
5a0827
+const ucd_record PRIV(dummy_ucd_record)[] = {{
5a0827
+  ucp_Common,    /* script */
5a0827
+  ucp_Cn,        /* type unassigned */
5a0827
+  ucp_gbOther,   /* grapheme break property */
5a0827
+  0,             /* case set */
5a0827
+  0,             /* other case */
5a0827
+  }};
5a0827
+#endif
5a0827
+
5a0827
 /* When recompiling tables with a new Unicode version, please check the
5a0827
 types in this structure definition from pcre2_internal.h (the actual
5a0827
 field names will be different):
5a0827
diff --git a/testdata/testinput12 b/testdata/testinput12
5a0827
index c3b2bfc..decfe82 100644
5a0827
--- a/testdata/testinput12
5a0827
+++ b/testdata/testinput12
5a0827
@@ -360,4 +360,7 @@
5a0827
 
5a0827
 /[\s[:^ascii:]]/B,ucp
5a0827
 
5a0827
+/\pP/ucp
5a0827
+    \x{7fffffff}\=no_jit
5a0827
+
5a0827
 # End of testinput12
5a0827
diff --git a/testdata/testoutput12-16 b/testdata/testoutput12-16
5a0827
index 3b5a0cd..41e0a48 100644
5a0827
--- a/testdata/testoutput12-16
5a0827
+++ b/testdata/testoutput12-16
5a0827
@@ -1415,4 +1415,10 @@ No match
5a0827
         End
5a0827
 ------------------------------------------------------------------
5a0827
 
5a0827
+/\pP/ucp
5a0827
+    \x{7fffffff}\=no_jit
5a0827
+** Character \x{7fffffff} is greater than 0xffff and UTF-16 mode is not enabled.
5a0827
+** Truncation will probably give the wrong result.
5a0827
+No match
5a0827
+
5a0827
 # End of testinput12
5a0827
diff --git a/testdata/testoutput12-32 b/testdata/testoutput12-32
5a0827
index 1496159..e9130b9 100644
5a0827
--- a/testdata/testoutput12-32
5a0827
+++ b/testdata/testoutput12-32
5a0827
@@ -1409,4 +1409,8 @@ No match
5a0827
         End
5a0827
 ------------------------------------------------------------------
5a0827
 
5a0827
+/\pP/ucp
5a0827
+    \x{7fffffff}\=no_jit
5a0827
+No match
5a0827
+
5a0827
 # End of testinput12
5a0827
-- 
5a0827
2.7.4
5a0827