Skip to content
/ pcre Public
forked from rurban/pcre

Commit 05aafb2

Browse files
committed
Implement pcre2_set_max_pattern_compiled_length() and set this limit in the fuzzer
1 parent 22cb0a6 commit 05aafb2

25 files changed

+929
-533
lines changed

ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ example pattern is: /(((?<=123?456456|ABC)))(?<=\2)/
2929

3030
(e) General code tidies.
3131

32+
(f) Limit the size of compiled patterns to 10MB (see 6 below).
33+
3234
3. Increase the maximum length of a name for a group from 32 to 128 because
3335
there is a user for whom 32 is too small.
3436

@@ -38,6 +40,9 @@ return if either jitverify or info is specified/
3840
5. Some auxiliary files for building under OpenVMS that were contributed by
3941
Alexey Chupahin have been installed.
4042

43+
6. Added pcre2_set_max_pattern_compiled_length() to limit the size of compiled
44+
patterns.
45+
4146

4247
Version 10.43 16-February-2024
4348
------------------------------

Makefile.am

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ dist_html_DATA = \
8282
doc/html/pcre2_set_glob_separator.html \
8383
doc/html/pcre2_set_heap_limit.html \
8484
doc/html/pcre2_set_match_limit.html \
85+
doc/html/pcre2_set_max_pattern_compiled_length.html \
8586
doc/html/pcre2_set_max_pattern_length.html \
8687
doc/html/pcre2_set_max_varlookbehind.html \
8788
doc/html/pcre2_set_offset_limit.html \
@@ -180,6 +181,7 @@ dist_man_MANS = \
180181
doc/pcre2_set_glob_separator.3 \
181182
doc/pcre2_set_heap_limit.3 \
182183
doc/pcre2_set_match_limit.3 \
184+
doc/pcre2_set_max_pattern_compiled_length.3 \
183185
doc/pcre2_set_max_pattern_length.3 \
184186
doc/pcre2_set_max_varlookbehind.3 \
185187
doc/pcre2_set_offset_limit.3 \

doc/html/index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,11 @@ <h1>Perl-compatible Regular Expressions (revised API: PCRE2)</h1>
252252
<tr><td><a href="pcre2_set_match_limit.html">pcre2_set_match_limit</a></td>
253253
<td>&nbsp;&nbsp;Set the match limit</td></tr>
254254

255+
<tr><td><a href="pcre2_set_max_pattern_compiled_length.html">pcre2_set_max_pattern_compiled_length</a></td>
256+
<td>&nbsp;&nbsp;Set the maximum length of a compiled pattern</td></tr>
257+
255258
<tr><td><a href="pcre2_set_max_pattern_length.html">pcre2_set_max_pattern_length</a></td>
256-
<td>&nbsp;&nbsp;Set the maximum length of pattern</td></tr>
259+
<td>&nbsp;&nbsp;Set the maximum length of a pattern</td></tr>
257260

258261
<tr><td><a href="pcre2_set_max_varlookbehind.html">pcre2_set_max_varlookbehind</a></td>
259262
<td>&nbsp;&nbsp;Set the maximum match length for a variable-length lookbehind</td></tr>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<html>
2+
<head>
3+
<title>pcre2_set_max_pattern_compiled_length specification</title>
4+
</head>
5+
<body bgcolor="#FFFFFF" text="#00005A" link="#0066FF" alink="#3399FF" vlink="#2222BB">
6+
<h1>pcre2_set_max_pattern_compiled_length man page</h1>
7+
<p>
8+
Return to the <a href="index.html">PCRE2 index page</a>.
9+
</p>
10+
<p>
11+
This page is part of the PCRE2 HTML documentation. It was generated
12+
automatically from the original man page. If there is any nonsense in it,
13+
please consult the man page, in case the conversion went wrong.
14+
<br>
15+
<br><b>
16+
SYNOPSIS
17+
</b><br>
18+
<P>
19+
<b>#include &#60;pcre2.h&#62;</b>
20+
</P>
21+
<P>
22+
<b>int pcre2_set_max_pattern_compiled_length(</b>
23+
<b> pcre2_compile_context *<i>ccontext</i>, PCRE2_SIZE <i>value</i>);</b>
24+
</P>
25+
<br><b>
26+
DESCRIPTION
27+
</b><br>
28+
<P>
29+
This function sets, in a compile context, the maximum size (in bytes) for the
30+
memory needed to hold the compiled version of a pattern that is compiled with
31+
this context. The result is always zero. If a pattern that is passed to
32+
<b>pcre2_compile()</b> with this context needs more memory, an error is
33+
generated. The default is the largest number that a PCRE2_SIZE variable can
34+
hold, which is effectively unlimited.
35+
</P>
36+
<P>
37+
There is a complete description of the PCRE2 native API in the
38+
<a href="pcre2api.html"><b>pcre2api</b></a>
39+
page and a description of the POSIX API in the
40+
<a href="pcre2posix.html"><b>pcre2posix</b></a>
41+
page.
42+
<p>
43+
Return to the <a href="index.html">PCRE2 index page</a>.
44+
</p>

doc/html/pcre2api.html

+17-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ <h1>pcre2api man page</h1>
161161
<b> PCRE2_SIZE <i>value</i>);</b>
162162
<br>
163163
<br>
164+
<b>int pcre2_set_max_pattern_compiled_length(</b>
165+
<b> pcre2_compile_context *<i>ccontext</i>, PCRE2_SIZE <i>value</i>);</b>
166+
<br>
167+
<br>
164168
<b>int pcre2_set_max_varlookbehind(pcre2_compile_contest *<i>ccontext</i>,</b>
165169
<b>" uint32_t <i>value</i>);</b>
166170
<br>
@@ -874,6 +878,18 @@ <h1>pcre2api man page</h1>
874878
PCRE2_SIZE variable can hold, which is effectively unlimited.
875879
<br>
876880
<br>
881+
<b>int pcre2_set_max_pattern_compiled_length(</b>
882+
<b> pcre2_compile_context *<i>ccontext</i>, PCRE2_SIZE <i>value</i>);</b>
883+
<br>
884+
<br>
885+
This sets a maximum size, in bytes, for the memory needed to hold the compiled
886+
version of a pattern that is compiled with this context. If the pattern needs
887+
more memory, an error is generated. This facility is provided so that
888+
applications that accept patterns from external sources can limit the amount of
889+
memory they use. The default is the largest number that a PCRE2_SIZE variable
890+
can hold, which is effectively unlimited.
891+
<br>
892+
<br>
877893
<b>int pcre2_set_max_varlookbehind(pcre2_compile_contest *<i>ccontext</i>,</b>
878894
<b>" uint32_t <i>value</i>);</b>
879895
<br>
@@ -4161,7 +4177,7 @@ <h1>pcre2api man page</h1>
41614177
</P>
41624178
<br><a name="SEC43" href="#TOC1">REVISION</a><br>
41634179
<P>
4164-
Last updated: 27 January 2024
4180+
Last updated: 24 April 2024
41654181
<br>
41664182
Copyright &copy; 1997-2024 University of Cambridge.
41674183
<br>

doc/html/pcre2test.html

+13-2
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,9 @@ <h1>pcre2test man page</h1>
696696
jitfast use JIT fast path
697697
jitverify verify JIT use
698698
locale=&#60;name&#62; use this locale
699-
max_pattern_length=&#60;n&#62; set maximum pattern length
699+
max_pattern_compiled ) set maximum compiled pattern
700+
_length=&#60;n&#62; ) length (bytes)
701+
max_pattern_length=&#60;n&#62; set maximum pattern length (code units)
700702
max_varlookbehind=&#60;n&#62; set maximum variable lookbehind length
701703
memory show memory used
702704
newline=&#60;type&#62; set newline type
@@ -1019,6 +1021,15 @@ <h1>pcre2test man page</h1>
10191021
length of pattern that <b>pcre2_compile()</b> will accept. Breaching the limit
10201022
causes a compilation error. The default is the largest number a PCRE2_SIZE
10211023
variable can hold (essentially unlimited).
1024+
</P>
1025+
<br><b>
1026+
Limiting the size of a compiled pattern
1027+
</b><br>
1028+
<P>
1029+
The <b>max_pattern_compiled_length</b> modifier sets a limit, in bytes, to the
1030+
amount of memory used by a compiled pattern. Breaching the limit causes a
1031+
compilation error. The default is the largest number a PCRE2_SIZE variable can
1032+
hold (essentially unlimited).
10221033
<a name="posixwrapper"></a></P>
10231034
<br><b>
10241035
Using the POSIX wrapper API
@@ -2193,7 +2204,7 @@ <h1>pcre2test man page</h1>
21932204
</P>
21942205
<br><a name="SEC21" href="#TOC1">REVISION</a><br>
21952206
<P>
2196-
Last updated: 27 January 2024
2207+
Last updated: 24 April 2024
21972208
<br>
21982209
Copyright &copy; 1997-2024 University of Cambridge.
21992210
<br>

doc/index.html.src

+4-1
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,11 @@ in the library.
252252
<tr><td><a href="pcre2_set_match_limit.html">pcre2_set_match_limit</a></td>
253253
<td>&nbsp;&nbsp;Set the match limit</td></tr>
254254

255+
<tr><td><a href="pcre2_set_max_pattern_compiled_length.html">pcre2_set_max_pattern_compiled_length</a></td>
256+
<td>&nbsp;&nbsp;Set the maximum length of a compiled pattern</td></tr>
257+
255258
<tr><td><a href="pcre2_set_max_pattern_length.html">pcre2_set_max_pattern_length</a></td>
256-
<td>&nbsp;&nbsp;Set the maximum length of pattern</td></tr>
259+
<td>&nbsp;&nbsp;Set the maximum length of a pattern</td></tr>
257260

258261
<tr><td><a href="pcre2_set_max_varlookbehind.html">pcre2_set_max_varlookbehind</a></td>
259262
<td>&nbsp;&nbsp;Set the maximum match length for a variable-length lookbehind</td></tr>

doc/pcre2.txt

+16-2
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ PCRE2 NATIVE API COMPILE CONTEXT FUNCTIONS
283283
int pcre2_set_max_pattern_length(pcre2_compile_context *ccontext,
284284
PCRE2_SIZE value);
285285

286+
int pcre2_set_max_pattern_compiled_length(
287+
pcre2_compile_context *ccontext, PCRE2_SIZE value);
288+
286289
int pcre2_set_max_varlookbehind(pcre2_compile_contest *ccontext,
287290
uint32_t value);
288291

@@ -912,6 +915,17 @@ PCRE2 CONTEXTS
912915
largest number that a PCRE2_SIZE variable can hold, which is effec-
913916
tively unlimited.
914917

918+
int pcre2_set_max_pattern_compiled_length(
919+
pcre2_compile_context *ccontext, PCRE2_SIZE value);
920+
921+
This sets a maximum size, in bytes, for the memory needed to hold the
922+
compiled version of a pattern that is compiled with this context. If
923+
the pattern needs more memory, an error is generated. This facility is
924+
provided so that applications that accept patterns from external
925+
sources can limit the amount of memory they use. The default is the
926+
largest number that a PCRE2_SIZE variable can hold, which is effec-
927+
tively unlimited.
928+
915929
int pcre2_set_max_varlookbehind(pcre2_compile_contest *ccontext,
916930
uint32_t value);
917931

@@ -3998,11 +4012,11 @@ AUTHOR
39984012

39994013
REVISION
40004014

4001-
Last updated: 27 January 2024
4015+
Last updated: 24 April 2024
40024016
Copyright (c) 1997-2024 University of Cambridge.
40034017

40044018

4005-
PCRE2 10.43 27 January 2024 PCRE2API(3)
4019+
PCRE2 10.44 24 April 2024 PCRE2API(3)
40064020
------------------------------------------------------------------------------
40074021

40084022

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.TH PCRE2_SET_MAX_PATTERN_COMPILED_LENGTH 3 "24 April 2024" "PCRE2 10.44"
2+
.SH NAME
3+
PCRE2 - Perl-compatible regular expressions (revised API)
4+
.SH SYNOPSIS
5+
.rs
6+
.sp
7+
.B #include <pcre2.h>
8+
.PP
9+
.nf
10+
.B int pcre2_set_max_pattern_compiled_length(
11+
.B " pcre2_compile_context *\fIccontext\fP, PCRE2_SIZE \fIvalue\fP);"
12+
.fi
13+
.
14+
.SH DESCRIPTION
15+
.rs
16+
.sp
17+
This function sets, in a compile context, the maximum size (in bytes) for the
18+
memory needed to hold the compiled version of a pattern that is compiled with
19+
this context. The result is always zero. If a pattern that is passed to
20+
\fBpcre2_compile()\fP with this context needs more memory, an error is
21+
generated. The default is the largest number that a PCRE2_SIZE variable can
22+
hold, which is effectively unlimited.
23+
.P
24+
There is a complete description of the PCRE2 native API in the
25+
.\" HREF
26+
\fBpcre2api\fP
27+
.\"
28+
page and a description of the POSIX API in the
29+
.\" HREF
30+
\fBpcre2posix\fP
31+
.\"
32+
page.

doc/pcre2api.3

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH PCRE2API 3 "27 January 2024" "PCRE2 10.43"
1+
.TH PCRE2API 3 "24 April 2024" "PCRE2 10.44"
22
.SH NAME
33
PCRE2 - Perl-compatible regular expressions (revised API)
44
.sp
@@ -101,6 +101,9 @@ document for an overview of all the PCRE2 documentation.
101101
.B int pcre2_set_max_pattern_length(pcre2_compile_context *\fIccontext\fP,
102102
.B " PCRE2_SIZE \fIvalue\fP);"
103103
.sp
104+
.B int pcre2_set_max_pattern_compiled_length(
105+
.B " pcre2_compile_context *\fIccontext\fP, PCRE2_SIZE \fIvalue\fP);"
106+
.sp
104107
.B int pcre2_set_max_varlookbehind(pcre2_compile_contest *\fIccontext\fP,
105108
.B " uint32_t \fIvalue\fP);
106109
.sp
@@ -805,6 +808,18 @@ external sources can limit their size. The default is the largest number that a
805808
PCRE2_SIZE variable can hold, which is effectively unlimited.
806809
.sp
807810
.nf
811+
.B int pcre2_set_max_pattern_compiled_length(
812+
.B " pcre2_compile_context *\fIccontext\fP, PCRE2_SIZE \fIvalue\fP);"
813+
.fi
814+
.sp
815+
This sets a maximum size, in bytes, for the memory needed to hold the compiled
816+
version of a pattern that is compiled with this context. If the pattern needs
817+
more memory, an error is generated. This facility is provided so that
818+
applications that accept patterns from external sources can limit the amount of
819+
memory they use. The default is the largest number that a PCRE2_SIZE variable
820+
can hold, which is effectively unlimited.
821+
.sp
822+
.nf
808823
.B int pcre2_set_max_varlookbehind(pcre2_compile_contest *\fIccontext\fP,
809824
.B " uint32_t \fIvalue\fP);
810825
.fi
@@ -4167,6 +4182,6 @@ Cambridge, England.
41674182
.rs
41684183
.sp
41694184
.nf
4170-
Last updated: 27 January 2024
4185+
Last updated: 24 April 2024
41714186
Copyright (c) 1997-2024 University of Cambridge.
41724187
.fi

doc/pcre2demo.3

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH PCRE2DEMO 3 "16 April 2024" "PCRE2 10.43"
1+
.TH PCRE2DEMO 3 "24 April 2024" "PCRE2 10.43"
22
.\"AUTOMATICALLY GENERATED BY PrepareRelease - do not EDIT!
33
.SH NAME
44
PCRE2DEMO - A demonstration C program for PCRE2

doc/pcre2test.1

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH PCRE2TEST 1 "27 January 2024" "PCRE 10.43"
1+
.TH PCRE2TEST 1 "24 April 2024" "PCRE 10.44"
22
.SH NAME
33
pcre2test - a program for testing Perl-compatible regular expressions.
44
.SH SYNOPSIS
@@ -652,7 +652,9 @@ heavily used in the test files.
652652
jitfast use JIT fast path
653653
jitverify verify JIT use
654654
locale=<name> use this locale
655-
max_pattern_length=<n> set maximum pattern length
655+
max_pattern_compiled ) set maximum compiled pattern
656+
_length=<n> ) length (bytes)
657+
max_pattern_length=<n> set maximum pattern length (code units)
656658
max_varlookbehind=<n> set maximum variable lookbehind length
657659
memory show memory used
658660
newline=<type> set newline type
@@ -976,6 +978,15 @@ causes a compilation error. The default is the largest number a PCRE2_SIZE
976978
variable can hold (essentially unlimited).
977979
.
978980
.
981+
.SS "Limiting the size of a compiled pattern"
982+
.rs
983+
.sp
984+
The \fBmax_pattern_compiled_length\fP modifier sets a limit, in bytes, to the
985+
amount of memory used by a compiled pattern. Breaching the limit causes a
986+
compilation error. The default is the largest number a PCRE2_SIZE variable can
987+
hold (essentially unlimited).
988+
.
989+
.
979990
.\" HTML <a name="posixwrapper"></a>
980991
.SS "Using the POSIX wrapper API"
981992
.rs
@@ -2170,6 +2181,6 @@ Cambridge, England.
21702181
.rs
21712182
.sp
21722183
.nf
2173-
Last updated: 27 January 2024
2184+
Last updated: 24 April 2024
21742185
Copyright (c) 1997-2024 University of Cambridge.
21752186
.fi

0 commit comments

Comments
 (0)