From 5dd4ddf635109b5b4d7541deb7569023539ef761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Mon, 19 Dec 2022 22:37:57 +0100 Subject: [PATCH] Ensure depth limit in large string spec --- spec/std/regex_spec.cr | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/std/regex_spec.cr b/spec/std/regex_spec.cr index d3830124aa79..72f62a3463cd 100644 --- a/spec/std/regex_spec.cr +++ b/spec/std/regex_spec.cr @@ -201,17 +201,18 @@ describe "Regex" do end it "doesn't crash with a large single line string" do + str = File.read(datapath("large_single_line_string.txt")) + {% if Regex::Engine.resolve.name == "Regex::PCRE" %} LibPCRE.config LibPCRE::CONFIG_JIT, out jit_enabled pending! "PCRE JIT mode not available." unless 1 == jit_enabled + + str.matches?(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/) {% else %} - # This spec requires a fairly large depth limit. Some package builds - # have a more restrictive value which would make this test fail. - pending! "PCRE2 depth limit too low" unless Regex::PCRE2.config(LibPCRE2::CONFIG_DEPTHLIMIT, UInt32) > 8192 + # Can't use regex literal because the *LIMIT_DEPTH verb is not supported in libpcre (only libpcre2) + # and thus the compiler doesn't recognize it. + str.matches?(Regex.new("(*LIMIT_DEPTH=8192)^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$")) {% end %} - - str = File.read(datapath("large_single_line_string.txt")) - str.matches?(/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/) # We don't care whether this actually matches or not, it's just to make # sure the engine does not stack overflow with a large string. end