From 172fb5230a3943eeb6fbbb4de1dc56b16e2a7637 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 27 Mar 2021 19:19:51 -0500 Subject: 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 --- tests/extmod/ure_limit.py | 34 ++++++++++++++++++++++++++++++++++ tests/extmod/ure_limit.py.exp | 7 +++++++ 2 files changed, 41 insertions(+) create mode 100644 tests/extmod/ure_limit.py create mode 100644 tests/extmod/ure_limit.py.exp (limited to 'tests') 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") diff --git a/tests/extmod/ure_limit.py.exp b/tests/extmod/ure_limit.py.exp new file mode 100644 index 000000000..8353be536 --- /dev/null +++ b/tests/extmod/ure_limit.py.exp @@ -0,0 +1,7 @@ +Error +Error +Error +Error +Error +Error +Error -- cgit v1.2.3