summaryrefslogtreecommitdiff
path: root/tests/extmod/ure_limit.py
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2021-03-27 19:19:51 -0500
committerDamien George <damien@micropython.org>2021-04-06 13:36:42 +1000
commit172fb5230a3943eeb6fbbb4de1dc56b16e2a7637 (patch)
tree1a5021f7ec290da5ae9b593a8e69b346cf54813a /tests/extmod/ure_limit.py
parentd35f12f5caf2f6eef08670b61dbe2a3a1b387042 (diff)
extmod/re1.5: Check and report byte overflow errors in _compilecode.
The generated regex code is limited in the range of jumps and counts, and this commit checks all cases which can overflow given the right kind of input regex, and returns an error in such a case. This change assumes that the results that overflow an int8_t do not overflow a platform int. Closes: #7078 Signed-off-by: Jeff Epler <jepler@gmail.com>
Diffstat (limited to 'tests/extmod/ure_limit.py')
-rw-r--r--tests/extmod/ure_limit.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/extmod/ure_limit.py b/tests/extmod/ure_limit.py
new file mode 100644
index 000000000..99c6a818e
--- /dev/null
+++ b/tests/extmod/ure_limit.py
@@ -0,0 +1,34 @@
+# Test overflow in ure.compile output code.
+
+try:
+ import ure as re
+except ImportError:
+ print("SKIP")
+ raise SystemExit
+
+
+def test_re(r):
+ try:
+ re.compile(r)
+ except:
+ print("Error")
+
+
+# too many chars in []
+test_re("[" + "a" * 256 + "]")
+
+# too many groups
+test_re("(a)" * 256)
+
+# jump too big for ?
+test_re("(" + "a" * 62 + ")?")
+
+# jump too big for *
+test_re("(" + "a" * 60 + ".)*")
+test_re("(" + "a" * 60 + "..)*")
+
+# jump too big for +
+test_re("(" + "a" * 62 + ")+")
+
+# jump too big for |
+test_re("b" * 63 + "|a")