/src/pcre2/src/pcre2_match.c
Line | Count | Source |
1 | | /************************************************* |
2 | | * Perl-Compatible Regular Expressions * |
3 | | *************************************************/ |
4 | | |
5 | | /* PCRE is a library of functions to support regular expressions whose syntax |
6 | | and semantics are as close as possible to those of the Perl 5 language. |
7 | | |
8 | | Written by Philip Hazel |
9 | | Original API code Copyright (c) 1997-2012 University of Cambridge |
10 | | New API code Copyright (c) 2015-2024 University of Cambridge |
11 | | |
12 | | ----------------------------------------------------------------------------- |
13 | | Redistribution and use in source and binary forms, with or without |
14 | | modification, are permitted provided that the following conditions are met: |
15 | | |
16 | | * Redistributions of source code must retain the above copyright notice, |
17 | | this list of conditions and the following disclaimer. |
18 | | |
19 | | * Redistributions in binary form must reproduce the above copyright |
20 | | notice, this list of conditions and the following disclaimer in the |
21 | | documentation and/or other materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the University of Cambridge nor the names of its |
24 | | contributors may be used to endorse or promote products derived from |
25 | | this software without specific prior written permission. |
26 | | |
27 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
28 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
29 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
30 | | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
31 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
32 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
33 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
34 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
35 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
36 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
37 | | POSSIBILITY OF SUCH DAMAGE. |
38 | | ----------------------------------------------------------------------------- |
39 | | */ |
40 | | |
41 | | |
42 | | #include "pcre2_internal.h" |
43 | | |
44 | | |
45 | | |
46 | | /* These defines enable debugging code */ |
47 | | |
48 | | /* #define DEBUG_FRAMES_DISPLAY */ |
49 | | /* #define DEBUG_SHOW_OPS */ |
50 | | /* #define DEBUG_SHOW_RMATCH */ |
51 | | |
52 | | #ifdef DEBUG_FRAMES_DISPLAY |
53 | | #include <stdarg.h> |
54 | | #endif |
55 | | |
56 | | #ifdef DEBUG_SHOW_OPS |
57 | | static const char *OP_names[] = { OP_NAME_LIST }; |
58 | | #endif |
59 | | |
60 | | /* These defines identify the name of the block containing "static" |
61 | | information, and fields within it. */ |
62 | | |
63 | 92.0M | #define NLBLOCK mb /* Block containing newline information */ |
64 | 452k | #define PSSTART start_subject /* Field containing processed string start */ |
65 | 22.4M | #define PSEND end_subject /* Field containing processed string end */ |
66 | | |
67 | 3.16M | #define RECURSE_UNSET 0xffffffffu /* Bigger than max group number */ |
68 | | |
69 | | /* Masks for identifying the public options that are permitted at match time. */ |
70 | | |
71 | | #define PUBLIC_MATCH_OPTIONS \ |
72 | 257k | (PCRE2_ANCHORED | PCRE2_ENDANCHORED | PCRE2_NOTBOL | PCRE2_NOTEOL | PCRE2_NOTEMPTY | \ |
73 | 257k | PCRE2_NOTEMPTY_ATSTART | PCRE2_NO_UTF_CHECK | PCRE2_PARTIAL_HARD | PCRE2_PARTIAL_SOFT | \ |
74 | 257k | PCRE2_NO_JIT | PCRE2_COPY_MATCHED_SUBJECT | PCRE2_DISABLE_RECURSELOOP_CHECK) |
75 | | |
76 | | #define PUBLIC_JIT_MATCH_OPTIONS \ |
77 | 247k | (PCRE2_NO_UTF_CHECK | PCRE2_NOTBOL | PCRE2_NOTEOL | PCRE2_NOTEMPTY | PCRE2_NOTEMPTY_ATSTART | \ |
78 | 247k | PCRE2_PARTIAL_SOFT | PCRE2_PARTIAL_HARD | PCRE2_COPY_MATCHED_SUBJECT) |
79 | | |
80 | | /* Non-error returns from and within the match() function. Error returns are |
81 | | externally defined PCRE2_ERROR_xxx codes, which are all negative. */ |
82 | | |
83 | 392k | #define MATCH_MATCH 1 |
84 | 23.8M | #define MATCH_NOMATCH 0 |
85 | | |
86 | | /* Special internal returns used in the match() function. Make them |
87 | | sufficiently negative to avoid the external error codes. */ |
88 | | |
89 | 684k | #define MATCH_ACCEPT (-999) |
90 | 407k | #define MATCH_KETRPOS (-998) |
91 | | /* The next 5 must be kept together and in sequence so that a test that checks |
92 | | for any one of them can use a range. */ |
93 | 583k | #define MATCH_COMMIT (-997) |
94 | 2.30M | #define MATCH_PRUNE (-996) |
95 | 9.36k | #define MATCH_SKIP (-995) |
96 | 137k | #define MATCH_SKIP_ARG (-994) |
97 | 13.5M | #define MATCH_THEN (-993) |
98 | 290k | #define MATCH_BACKTRACK_MAX MATCH_THEN |
99 | 290k | #define MATCH_BACKTRACK_MIN MATCH_COMMIT |
100 | | |
101 | | /* Group frame type values. Zero means the frame is not a group frame. The |
102 | | lower 16 bits are used for data (e.g. the capture number). Group frames are |
103 | | used for most groups so that information about the start is easily available at |
104 | | the end without having to scan back through intermediate frames (backtrack |
105 | | points). */ |
106 | | |
107 | 1.45M | #define GF_CAPTURE 0x00010000u |
108 | 2.14M | #define GF_NOCAPTURE 0x00020000u |
109 | 1.91M | #define GF_CONDASSERT 0x00030000u |
110 | 6.28M | #define GF_RECURSE 0x00040000u |
111 | | |
112 | | /* Masks for the identity and data parts of the group frame type. */ |
113 | | |
114 | 5.02M | #define GF_IDMASK(a) ((a) & 0xffff0000u) |
115 | 730k | #define GF_DATAMASK(a) ((a) & 0x0000ffffu) |
116 | | |
117 | | /* Repetition types */ |
118 | | |
119 | | enum { REPTYPE_MIN, REPTYPE_MAX, REPTYPE_POS }; |
120 | | |
121 | | /* Min and max values for the common repeats; a maximum of UINT32_MAX => |
122 | | infinity. */ |
123 | | |
124 | | static const uint32_t rep_min[] = { |
125 | | // clang-format off |
126 | | 0, 0, /* * and *? */ |
127 | | 1, 1, /* + and +? */ |
128 | | 0, 0, /* ? and ?? */ |
129 | | 0, 0, /* dummy placefillers for OP_CR[MIN]RANGE */ |
130 | | 0, 1, 0, /* OP_CRPOS{STAR, PLUS, QUERY} */ |
131 | | // clang-format on |
132 | | }; |
133 | | |
134 | | static const uint32_t rep_max[] = { |
135 | | // clang-format off |
136 | | UINT32_MAX, UINT32_MAX, /* * and *? */ |
137 | | UINT32_MAX, UINT32_MAX, /* + and +? */ |
138 | | 1, 1, /* ? and ?? */ |
139 | | 0, 0, /* dummy placefillers for OP_CR[MIN]RANGE */ |
140 | | UINT32_MAX, UINT32_MAX, 1, /* OP_CRPOS{STAR, PLUS, QUERY} */ |
141 | | // clang-format on |
142 | | }; |
143 | | |
144 | | /* Repetition types - must include OP_CRPOSRANGE (not needed above) */ |
145 | | |
146 | | static const uint32_t rep_typ[] = { |
147 | | // clang-format off |
148 | | REPTYPE_MAX, REPTYPE_MIN, /* * and *? */ |
149 | | REPTYPE_MAX, REPTYPE_MIN, /* + and +? */ |
150 | | REPTYPE_MAX, REPTYPE_MIN, /* ? and ?? */ |
151 | | REPTYPE_MAX, REPTYPE_MIN, /* OP_CRRANGE and OP_CRMINRANGE */ |
152 | | REPTYPE_POS, REPTYPE_POS, /* OP_CRPOSSTAR, OP_CRPOSPLUS */ |
153 | | REPTYPE_POS, REPTYPE_POS, /* OP_CRPOSQUERY, OP_CRPOSRANGE */ |
154 | | // clang-format on |
155 | | }; |
156 | | |
157 | | /* Numbers for RMATCH calls at backtracking points. When these lists are |
158 | | changed, the code at RETURN_SWITCH below must be updated in sync. */ |
159 | | |
160 | | enum { |
161 | | // clang-format off |
162 | | RM1=1, RM2, RM3, RM4, RM5, RM6, RM7, RM8, RM9, RM10, |
163 | | RM11, RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20, |
164 | | RM21, RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30, |
165 | | RM31, RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, |
166 | | // clang-format on |
167 | | }; |
168 | | |
169 | | #ifdef SUPPORT_WIDE_CHARS |
170 | | enum { |
171 | | // clang-format off |
172 | | RM100=100, RM101, RM102, RM103, |
173 | | // clang-format on |
174 | | }; |
175 | | #endif |
176 | | |
177 | | #ifdef SUPPORT_UNICODE |
178 | | enum { |
179 | | // clang-format off |
180 | | RM200=200, RM201, RM202, RM203, RM204, RM205, RM206, RM207, |
181 | | RM208, RM209, RM210, RM211, RM212, RM213, RM214, RM215, |
182 | | RM216, RM217, RM218, RM219, RM220, RM221, RM222, RM223, |
183 | | RM224, |
184 | | // clang-format on |
185 | | }; |
186 | | #endif |
187 | | |
188 | | /* Define short names for general fields in the current backtrack frame, which |
189 | | is always pointed to by the F variable. Occasional references to fields in |
190 | | other frames are written out explicitly. There are also some fields in the |
191 | | current frame that are used for short-term, localised backtracking memory. |
192 | | These are members of the fields union and #defined with Lxxx names at the |
193 | | point of use and undefined afterwards. */ |
194 | | |
195 | 40.4M | #define Fback_frame F->back_frame |
196 | 4.96M | #define Fcapture_last F->capture_last |
197 | 6.52M | #define Fcurrent_recurse F->current_recurse |
198 | 165M | #define Fecode F->ecode |
199 | 125M | #define Feptr F->eptr |
200 | 22.0M | #define Fgroup_frame_type F->group_frame_type |
201 | 11.4M | #define Flast_group_offset F->last_group_offset |
202 | 2.63M | #define Fmark F->mark |
203 | 67.7M | #define Frdepth F->rdepth |
204 | 4.00M | #define Fstart_match F->start_match |
205 | 7.06M | #define Foffset_top F->offset_top |
206 | 90.9M | #define Fop F->op |
207 | 4.91M | #define Fovector F->ovector |
208 | 37.7M | #define Freturn_id F->return_id |
209 | | |
210 | | |
211 | | #ifdef DEBUG_FRAMES_DISPLAY |
212 | | /************************************************* |
213 | | * Display current frames and contents * |
214 | | *************************************************/ |
215 | | |
216 | | /* This debugging function displays the current set of frames and their |
217 | | contents. It is not called automatically from anywhere, the intention being |
218 | | that calls can be inserted where necessary when debugging frame-related |
219 | | problems. |
220 | | |
221 | | Arguments: |
222 | | f the file to write to |
223 | | F the current top frame |
224 | | P a previous frame of interest |
225 | | frame_size the frame size |
226 | | mb points to the match block |
227 | | match_data points to the match data block |
228 | | s identification text |
229 | | |
230 | | Returns: nothing |
231 | | */ |
232 | | |
233 | | static void |
234 | | display_frames(FILE *f, heapframe *F, heapframe *P, PCRE2_SIZE frame_size, match_block *mb, |
235 | | pcre2_match_data *match_data, const char *s, ...) |
236 | | { |
237 | | uint32_t i; |
238 | | heapframe *Q; |
239 | | va_list ap; |
240 | | va_start(ap, s); |
241 | | |
242 | | fprintf(f, "FRAMES "); |
243 | | vfprintf(f, s, ap); |
244 | | va_end(ap); |
245 | | |
246 | | if (P != NULL) |
247 | | fprintf(f, " P=%lu", ((char *)P - (char *)(match_data->heapframes)) / frame_size); |
248 | | fprintf(f, "\n"); |
249 | | |
250 | | for (i = 0, Q = match_data->heapframes; Q <= F; i++, Q = (heapframe *)((char *)Q + frame_size)) |
251 | | { |
252 | | fprintf(f, "Frame %d type=%x subj=%lu code=%d back=%lu id=%d", i, Q->group_frame_type, |
253 | | Q->eptr - mb->start_subject, *(Q->ecode), Q->back_frame, Q->return_id); |
254 | | |
255 | | if (Q->last_group_offset == PCRE2_UNSET) |
256 | | fprintf(f, " lgoffset=unset\n"); |
257 | | else |
258 | | fprintf(f, " lgoffset=%lu\n", Q->last_group_offset / frame_size); |
259 | | } |
260 | | } |
261 | | |
262 | | #endif |
263 | | |
264 | | |
265 | | |
266 | | /************************************************* |
267 | | * Process a callout * |
268 | | *************************************************/ |
269 | | |
270 | | /* This function is called for all callouts, whether "standalone" or at the |
271 | | start of a conditional group. Feptr will be pointing to either OP_CALLOUT or |
272 | | OP_CALLOUT_STR. A callout block is allocated in pcre2_match() and initialized |
273 | | with fixed values. |
274 | | |
275 | | Arguments: |
276 | | F points to the current backtracking frame |
277 | | mb points to the match block |
278 | | lengthptr where to return the length of the callout item |
279 | | |
280 | | Returns: the return from the callout |
281 | | or 0 if no callout function exists |
282 | | */ |
283 | | |
284 | | static int |
285 | | do_callout(heapframe *F, match_block *mb, PCRE2_SIZE *lengthptr) |
286 | 1.34M | { |
287 | 1.34M | int rc; |
288 | 1.34M | PCRE2_SIZE save0, save1; |
289 | 1.34M | PCRE2_SIZE *callout_ovector; |
290 | 1.34M | pcre2_callout_block *cb; |
291 | | |
292 | 1.34M | *lengthptr = |
293 | 1.34M | (*Fecode == OP_CALLOUT) ? PRIV(OP_lengths)[OP_CALLOUT] : GET(Fecode, 1 + 2 * LINK_SIZE); |
294 | | |
295 | 1.34M | if (mb->callout == NULL) |
296 | 0 | return 0; // No callout function provided |
297 | | |
298 | | /* The original matching code (pre 10.30) worked directly with the ovector |
299 | | passed by the user, and this was passed to callouts. Now that the working |
300 | | ovector is in the backtracking frame, it no longer needs to reserve space for |
301 | | the overall match offsets (which would waste space in the frame). For backward |
302 | | compatibility, however, we pass capture_top and offset_vector to the callout as |
303 | | if for the extended ovector, and we ensure that the first two slots are unset |
304 | | by preserving and restoring their current contents. Picky compilers complain if |
305 | | references such as Fovector[-2] are use directly, so we set up a separate |
306 | | pointer. */ |
307 | | |
308 | 1.34M | callout_ovector = (PCRE2_SIZE *)(Fovector)-2; |
309 | | |
310 | | /* The cb->version, cb->subject, cb->subject_length, and cb->start_match fields |
311 | | are set externally. The first 3 never change; the last is updated for each |
312 | | bumpalong. */ |
313 | | |
314 | 1.34M | cb = mb->cb; |
315 | 1.34M | cb->capture_top = (uint32_t)Foffset_top / 2 + 1; |
316 | 1.34M | cb->capture_last = Fcapture_last; |
317 | 1.34M | cb->offset_vector = callout_ovector; |
318 | 1.34M | cb->mark = mb->nomatch_mark; |
319 | 1.34M | cb->current_position = (PCRE2_SIZE)(Feptr - mb->start_subject); |
320 | 1.34M | cb->pattern_position = GET(Fecode, 1); |
321 | 1.34M | cb->next_item_length = GET(Fecode, 1 + LINK_SIZE); |
322 | | |
323 | 1.34M | if (*Fecode == OP_CALLOUT) // Numerical callout |
324 | 1.32M | { |
325 | 1.32M | cb->callout_number = Fecode[1 + 2 * LINK_SIZE]; |
326 | 1.32M | cb->callout_string_offset = 0; |
327 | 1.32M | cb->callout_string = NULL; |
328 | 1.32M | cb->callout_string_length = 0; |
329 | 1.32M | } |
330 | 11.3k | else // String callout |
331 | 11.3k | { |
332 | 11.3k | cb->callout_number = 0; |
333 | 11.3k | cb->callout_string_offset = GET(Fecode, 1 + 3 * LINK_SIZE); |
334 | 11.3k | cb->callout_string = Fecode + (1 + 4 * LINK_SIZE) + 1; |
335 | 11.3k | cb->callout_string_length = *lengthptr - (1 + 4 * LINK_SIZE) - 2; |
336 | 11.3k | } |
337 | | |
338 | 1.34M | save0 = callout_ovector[0]; |
339 | 1.34M | save1 = callout_ovector[1]; |
340 | 1.34M | callout_ovector[0] = callout_ovector[1] = PCRE2_UNSET; |
341 | 1.34M | rc = mb->callout(cb, mb->callout_data); |
342 | 1.34M | callout_ovector[0] = save0; |
343 | 1.34M | callout_ovector[1] = save1; |
344 | 1.34M | cb->callout_flags = 0; |
345 | 1.34M | return rc; |
346 | 1.34M | } |
347 | | |
348 | | |
349 | | |
350 | | /************************************************* |
351 | | * Match a back-reference * |
352 | | *************************************************/ |
353 | | |
354 | | /* This function is called only when it is known that the offset lies within |
355 | | the offsets that have so far been used in the match. Note that in caseless |
356 | | UTF-8 mode, the number of subject bytes matched may be different to the number |
357 | | of reference bytes. (In theory this could also happen in UTF-16 mode, but it |
358 | | seems unlikely.) |
359 | | |
360 | | Arguments: |
361 | | offset index into the offset vector |
362 | | caseless TRUE if caseless |
363 | | caseopts bitmask of REFI_FLAG_XYZ values |
364 | | F the current backtracking frame pointer |
365 | | mb points to match block |
366 | | lengthptr pointer for returning the length matched |
367 | | |
368 | | Returns: = 0 sucessful match; number of code units matched is set |
369 | | < 0 no match |
370 | | > 0 partial match |
371 | | */ |
372 | | |
373 | | static int |
374 | | match_ref(PCRE2_SIZE offset, BOOL caseless, int caseopts, heapframe *F, match_block *mb, |
375 | | PCRE2_SIZE *lengthptr) |
376 | 295k | { |
377 | 295k | PCRE2_SPTR p; |
378 | 295k | PCRE2_SIZE length; |
379 | 295k | PCRE2_SPTR eptr; |
380 | 295k | PCRE2_SPTR eptr_start; |
381 | | |
382 | | #ifndef SUPPORT_UNICODE |
383 | | (void)caseopts; // Avoid compiler warning. |
384 | | #endif |
385 | | |
386 | | /* Deal with an unset group. The default is no match, but there is an option to |
387 | | match an empty string. */ |
388 | | |
389 | 295k | if (offset >= Foffset_top || Fovector[offset] == PCRE2_UNSET) |
390 | 49.1k | { |
391 | 49.1k | if ((mb->poptions & PCRE2_MATCH_UNSET_BACKREF) != 0) |
392 | 1.92k | { |
393 | 1.92k | *lengthptr = 0; |
394 | 1.92k | return 0; // Match |
395 | 1.92k | } |
396 | 47.2k | else |
397 | 47.2k | { |
398 | 47.2k | return -1; // No match |
399 | 47.2k | } |
400 | 49.1k | } |
401 | | |
402 | | /* Separate the caseless and UTF cases for speed. */ |
403 | | |
404 | 246k | eptr = eptr_start = Feptr; |
405 | 246k | p = mb->start_subject + Fovector[offset]; |
406 | 246k | length = Fovector[offset + 1] - Fovector[offset]; |
407 | 246k | PCRE2_ASSERT(eptr <= mb->end_subject); |
408 | | |
409 | 246k | if (caseless) |
410 | 77.6k | { |
411 | 77.6k | #if defined SUPPORT_UNICODE |
412 | 77.6k | BOOL utf = (mb->poptions & PCRE2_UTF) != 0; |
413 | 77.6k | BOOL caseless_restrict = (caseopts & REFI_FLAG_CASELESS_RESTRICT) != 0; |
414 | 77.6k | BOOL turkish_casing = !caseless_restrict && (caseopts & REFI_FLAG_TURKISH_CASING) != 0; |
415 | | |
416 | 77.6k | if (utf || (mb->poptions & PCRE2_UCP) != 0) |
417 | 49.4k | { |
418 | 49.4k | PCRE2_SPTR endptr = p + length; |
419 | | |
420 | | /* Match characters up to the end of the reference. NOTE: the number of |
421 | | code units matched may differ, because in UTF-8 there are some characters |
422 | | whose upper and lower case codes have different numbers of bytes. For |
423 | | example, U+023A (2 bytes in UTF-8) is the upper case version of U+2C65 (3 |
424 | | bytes in UTF-8); a sequence of 3 of the former uses 6 bytes, as does a |
425 | | sequence of two of the latter. It is important, therefore, to check the |
426 | | length along the reference, not along the subject (earlier code did this |
427 | | wrong). UCP uses Unicode properties but without UTF encoding. */ |
428 | | |
429 | 51.4k | while (p < endptr) |
430 | 47.9k | { |
431 | 47.9k | uint32_t c, d; |
432 | 47.9k | const ucd_record *ur; |
433 | 47.9k | if (eptr >= mb->end_subject) |
434 | 4.79k | return 1; // Partial match |
435 | | |
436 | 43.2k | if (utf) |
437 | 36.4k | { |
438 | 36.4k | GETCHARINC(c, eptr); |
439 | 36.4k | GETCHARINC(d, p); |
440 | 36.4k | } |
441 | 6.76k | else |
442 | 6.76k | { |
443 | 6.76k | c = *eptr++; |
444 | 6.76k | d = *p++; |
445 | 6.76k | } |
446 | | |
447 | 43.2k | if (turkish_casing && UCD_ANY_I(d)) |
448 | 0 | { |
449 | 0 | c = UCD_FOLD_I_TURKISH(c); |
450 | 0 | d = UCD_FOLD_I_TURKISH(d); |
451 | 0 | if (c != d) |
452 | 0 | return -1; // No match |
453 | 0 | } |
454 | 43.2k | else if (c != d && c != (uint32_t)((int)d + (ur = GET_UCD(d))->other_case)) |
455 | 41.3k | { |
456 | 41.3k | const uint32_t *pp = PRIV(ucd_caseless_sets) + ur->caseset; |
457 | | |
458 | | /* When PCRE2_EXTRA_CASELESS_RESTRICT is set, ignore any caseless sets |
459 | | that start with an ASCII character. */ |
460 | 41.3k | if (caseless_restrict && *pp < 128) |
461 | 475 | return -1; // No match |
462 | | |
463 | 40.8k | for (;;) |
464 | 44.3k | { |
465 | 44.3k | if (c < *pp) |
466 | 40.6k | return -1; // No match |
467 | 3.70k | if (c == *pp++) |
468 | 194 | break; |
469 | 3.70k | } |
470 | 40.8k | } |
471 | 43.2k | } |
472 | 49.4k | } |
473 | 28.2k | else |
474 | 28.2k | #endif |
475 | | |
476 | | /* Not in UTF or UCP mode */ |
477 | 28.2k | { |
478 | 34.0k | for (; length > 0; length--) |
479 | 30.5k | { |
480 | 30.5k | uint32_t cc, cp; |
481 | 30.5k | if (eptr >= mb->end_subject) |
482 | 1.81k | return 1; // Partial match |
483 | 28.7k | cc = *eptr; |
484 | 28.7k | cp = *p; |
485 | 28.7k | if (TABLE_GET(cp, mb->lcc, cp) != TABLE_GET(cc, mb->lcc, cc)) |
486 | 22.9k | return -1; // No match |
487 | 5.76k | p++; |
488 | 5.76k | eptr++; |
489 | 5.76k | } |
490 | 28.2k | } |
491 | 77.6k | } |
492 | | |
493 | | /* In the caseful case, we can just compare the code units, whether or not we |
494 | | are in UTF and/or UCP mode. When partial matching, we have to do this unit by |
495 | | unit. */ |
496 | | |
497 | 168k | else |
498 | 168k | { |
499 | 168k | if (mb->partial != 0) |
500 | 75.6k | { |
501 | 137k | for (; length > 0; length--) |
502 | 125k | { |
503 | 125k | if (eptr >= mb->end_subject) |
504 | 5.17k | return 1; // Partial match |
505 | 119k | if (*p++ != *eptr++) |
506 | 57.7k | return -1; // No match |
507 | 119k | } |
508 | 75.6k | } |
509 | | |
510 | | /* Not partial matching */ |
511 | | |
512 | 93.0k | else |
513 | 93.0k | { |
514 | 93.0k | if ((PCRE2_SIZE)(mb->end_subject - eptr) < length || memcmp(p, eptr, CU2BYTES(length)) != 0) |
515 | 76.4k | return -1; // No match |
516 | 16.6k | eptr += length; |
517 | 16.6k | } |
518 | 168k | } |
519 | | |
520 | 36.3k | *lengthptr = eptr - eptr_start; |
521 | 36.3k | return 0; // Match |
522 | 246k | } |
523 | | |
524 | | |
525 | | |
526 | | /************************************************* |
527 | | * Restore offsets after a recurse * |
528 | | *************************************************/ |
529 | | |
530 | | /* This function restores the ovector values when |
531 | | a recursive block reaches its end, and the triggering |
532 | | recurse has and argument list. |
533 | | |
534 | | Arguments: |
535 | | F the current backtracking frame pointer |
536 | | P the previous backtracking frame pointer |
537 | | */ |
538 | | |
539 | | static void |
540 | | recurse_update_offsets(heapframe *F, heapframe *P) |
541 | 14.1k | { |
542 | 14.1k | PCRE2_SIZE *dst = F->ovector; |
543 | 14.1k | PCRE2_SIZE *src = P->ovector; |
544 | | /* The first bracket has offset 2, because |
545 | | offset 0 is reserved for the full match. */ |
546 | 14.1k | PCRE2_SIZE offset = 2; |
547 | 14.1k | PCRE2_SIZE offset_top = Foffset_top + 2; |
548 | 14.1k | PCRE2_SIZE diff; |
549 | 14.1k | PCRE2_SPTR ecode = Fecode; |
550 | | |
551 | 14.1k | do |
552 | 14.9k | { |
553 | 14.9k | diff = (GET2(ecode, 1) << 1) - offset; |
554 | 14.9k | ecode += 1 + IMM2_SIZE; |
555 | | |
556 | 14.9k | if (offset + diff >= offset_top) |
557 | 2.26k | { |
558 | | /* Some OP_CREF opcodes are not |
559 | | processed, they must be skipped. */ |
560 | 3.58k | while (*ecode == OP_CREF) |
561 | 1.31k | ecode += 1 + IMM2_SIZE; |
562 | 2.26k | break; |
563 | 2.26k | } |
564 | | |
565 | 12.6k | if (diff == 2) |
566 | 1.34k | { |
567 | 1.34k | dst[0] = src[0]; |
568 | 1.34k | dst[1] = src[1]; |
569 | 1.34k | } |
570 | 11.3k | else if (diff >= 4) |
571 | 277 | { |
572 | 277 | memcpy(dst, src, diff * sizeof(PCRE2_SIZE)); |
573 | 277 | } |
574 | | |
575 | | /* Skip the unmodified entry. */ |
576 | 12.6k | diff += 2; |
577 | 12.6k | offset += diff; |
578 | 12.6k | dst += diff; |
579 | 12.6k | src += diff; |
580 | 12.6k | } while (*ecode == OP_CREF); |
581 | | |
582 | 14.1k | diff = offset_top - offset; |
583 | 14.1k | if (diff == 2) |
584 | 2.56k | { |
585 | 2.56k | dst[0] = src[0]; |
586 | 2.56k | dst[1] = src[1]; |
587 | 2.56k | } |
588 | 11.5k | else if (diff >= 4) |
589 | 362 | { |
590 | 362 | memcpy(dst, src, diff * sizeof(PCRE2_SIZE)); |
591 | 362 | } |
592 | | |
593 | 14.1k | Fecode = ecode; |
594 | 14.1k | Foffset_top = (offset <= P->offset_top) ? P->offset_top : (offset - 2); |
595 | 14.1k | } |
596 | | |
597 | | |
598 | | |
599 | | /****************************************************************************** |
600 | | ******************************************************************************* |
601 | | "Recursion" in the match() function |
602 | | |
603 | | The original match() function was highly recursive, but this proved to be the |
604 | | source of a number of problems over the years, mostly because of the relatively |
605 | | small system stacks that are commonly found. As new features were added to |
606 | | patterns, various kludges were invented to reduce the amount of stack used, |
607 | | making the code hard to understand in places. |
608 | | |
609 | | A version did exist that used individual frames on the heap instead of calling |
610 | | match() recursively, but this ran substantially slower. The current version is |
611 | | a refactoring that uses a vector of frames to remember backtracking points. |
612 | | This runs no slower, and possibly even a bit faster than the original recursive |
613 | | implementation. |
614 | | |
615 | | At first, an initial vector of size START_FRAMES_SIZE (enough for maybe 50 |
616 | | frames) was allocated on the system stack. If this was not big enough, the heap |
617 | | was used for a larger vector. However, it turns out that there are environments |
618 | | where taking as little as 20KiB from the system stack is an embarrassment. |
619 | | After another refactoring, the heap is used exclusively, but a pointer the |
620 | | frames vector and its size are cached in the match_data block, so that there is |
621 | | no new memory allocation if the same match_data block is used for multiple |
622 | | matches (unless the frames vector has to be extended). |
623 | | ******************************************************************************* |
624 | | ******************************************************************************/ |
625 | | |
626 | | |
627 | | |
628 | | /************************************************* |
629 | | * Macros for the match() function * |
630 | | *************************************************/ |
631 | | |
632 | | /* These macros pack up tests that are used for partial matching several times |
633 | | in the code. The second one is used when we already know we are past the end of |
634 | | the subject. We set the "hit end" flag if the pointer is at the end of the |
635 | | subject and either (a) the pointer is past the earliest inspected character |
636 | | (i.e. something has been matched, even if not part of the actual matched |
637 | | string), or (b) the pattern contains a lookbehind. These are the conditions for |
638 | | which adding more characters may allow the current match to continue. |
639 | | |
640 | | For hard partial matching, we immediately return a partial match. Otherwise, |
641 | | carrying on means that a complete match on the current subject will be sought. |
642 | | A partial match is returned only if no complete match can be found. */ |
643 | | |
644 | | #define CHECK_PARTIAL() \ |
645 | 1.08M | do \ |
646 | 1.08M | { \ |
647 | 1.08M | if (Feptr >= mb->end_subject) \ |
648 | 1.08M | { \ |
649 | 155k | SCHECK_PARTIAL(); \ |
650 | 155k | } \ |
651 | 1.08M | } while (0) |
652 | | |
653 | | #define SCHECK_PARTIAL() \ |
654 | 1.65M | do \ |
655 | 1.65M | { \ |
656 | 1.65M | if (mb->partial != 0 && (Feptr > mb->start_used_ptr || mb->allowemptypartial)) \ |
657 | 1.65M | { \ |
658 | 480k | mb->hitend = TRUE; \ |
659 | 480k | if (mb->partial > 1) \ |
660 | 480k | return PCRE2_ERROR_PARTIAL; \ |
661 | 480k | } \ |
662 | 1.65M | } while (0) |
663 | | |
664 | | |
665 | | /* These macros are used to implement backtracking. They simulate a recursive |
666 | | call to the match() function by means of a local vector of frames which |
667 | | remember the backtracking points. */ |
668 | | |
669 | | #define RMATCH(ra, rb) \ |
670 | 19.5M | do \ |
671 | 19.5M | { \ |
672 | 19.5M | start_ecode = ra; \ |
673 | 19.5M | Freturn_id = rb; \ |
674 | 19.5M | goto MATCH_RECURSE; \ |
675 | 19.5M | L_##rb :; \ |
676 | 18.2M | } while (0) |
677 | | |
678 | | #define RRETURN(ra) \ |
679 | 20.6M | do \ |
680 | 20.6M | { \ |
681 | 20.6M | rrc = ra; \ |
682 | 20.6M | goto RETURN_SWITCH; \ |
683 | 20.6M | } while (0) |
684 | | |
685 | | |
686 | | |
687 | | /************************************************* |
688 | | * Match from current position * |
689 | | *************************************************/ |
690 | | |
691 | | /* This function is called to run one match attempt at a single starting point |
692 | | in the subject. |
693 | | |
694 | | Performance note: It might be tempting to extract commonly used fields from the |
695 | | mb structure (e.g. end_subject) into individual variables to improve |
696 | | performance. Tests using gcc on a SPARC disproved this; in the first case, it |
697 | | made performance worse. |
698 | | |
699 | | Arguments: |
700 | | start_eptr starting character in subject |
701 | | start_ecode starting position in compiled code |
702 | | top_bracket number of capturing parentheses in the pattern |
703 | | frame_size size of each backtracking frame |
704 | | match_data pointer to the match_data block |
705 | | mb pointer to "static" variables block |
706 | | |
707 | | Returns: MATCH_MATCH if matched ) these values are >= 0 |
708 | | MATCH_NOMATCH if failed to match ) |
709 | | negative MATCH_xxx value for PRUNE, SKIP, etc |
710 | | negative PCRE2_ERROR_xxx value if aborted by an error condition |
711 | | (e.g. stopped by repeated call or depth limit) |
712 | | */ |
713 | | |
714 | | static int |
715 | | match(PCRE2_SPTR start_eptr, PCRE2_SPTR start_ecode, uint16_t top_bracket, PCRE2_SIZE frame_size, |
716 | | pcre2_match_data *match_data, match_block *mb) |
717 | 2.47M | { |
718 | | /* Frame-handling variables */ |
719 | | |
720 | 2.47M | heapframe *F; // Current frame pointer |
721 | 2.47M | heapframe *N = NULL; // Temporary frame pointers |
722 | 2.47M | heapframe *P = NULL; |
723 | | |
724 | 2.47M | heapframe *frames_top; // End of frames vector |
725 | 2.47M | heapframe *assert_accept_frame = NULL; // For passing back a frame with captures |
726 | 2.47M | PCRE2_SIZE frame_copy_size; // Amount to copy when creating a new frame |
727 | | |
728 | | /* Local variables that do not need to be preserved over calls to RMATCH(). */ |
729 | | |
730 | 2.47M | PCRE2_SPTR branch_end = NULL; |
731 | 2.47M | PCRE2_SPTR branch_start; |
732 | 2.47M | PCRE2_SPTR bracode; // Temp pointer to start of group |
733 | 2.47M | PCRE2_SIZE offset; // Used for group offsets |
734 | 2.47M | PCRE2_SIZE length; // Used for various length calculations |
735 | | |
736 | 2.47M | int rrc; // Return from functions & backtracking "recursions" |
737 | 2.47M | #ifdef SUPPORT_UNICODE |
738 | 2.47M | int proptype; // Type of character property |
739 | 2.47M | #endif |
740 | | |
741 | 2.47M | uint32_t i; // Used for local loops |
742 | 2.47M | uint32_t fc; // Character values |
743 | 2.47M | uint32_t number; // Used for group and other numbers |
744 | 2.47M | uint32_t reptype = 0; // Type of repetition (0 to avoid compiler warning) |
745 | 2.47M | uint32_t group_frame_type; // Specifies type for new group frames |
746 | | |
747 | 2.47M | BOOL condition; // Used in conditional groups |
748 | 2.47M | BOOL cur_is_word; // Used in "word" tests |
749 | 2.47M | BOOL prev_is_word; // Used in "word" tests |
750 | | |
751 | | /* UTF and UCP flags */ |
752 | | |
753 | 2.47M | #ifdef SUPPORT_UNICODE |
754 | 2.47M | BOOL utf = (mb->poptions & PCRE2_UTF) != 0; |
755 | 2.47M | BOOL ucp = (mb->poptions & PCRE2_UCP) != 0; |
756 | | #else |
757 | | BOOL utf = FALSE; // Required for convenience even when no Unicode support |
758 | | #endif |
759 | | |
760 | | /* This is the length of the last part of a backtracking frame that must be |
761 | | copied when a new frame is created. */ |
762 | | |
763 | 2.47M | frame_copy_size = frame_size - offsetof(heapframe, eptr); |
764 | | |
765 | | /* Set up the first frame and the end of the frames vector. */ |
766 | | |
767 | 2.47M | F = match_data->heapframes; |
768 | 2.47M | frames_top = (heapframe *)((char *)F + match_data->heapframes_size); |
769 | | |
770 | 2.47M | Frdepth = 0; // "Recursion" depth |
771 | 2.47M | Fcapture_last = 0; // Number of most recent capture |
772 | 2.47M | Fcurrent_recurse = RECURSE_UNSET; // Not pattern recursing. |
773 | 2.47M | Fstart_match = Feptr = start_eptr; // Current data pointer and start match |
774 | 2.47M | Fmark = NULL; // Most recent mark |
775 | 2.47M | Foffset_top = 0; // End of captures within the frame |
776 | 2.47M | Flast_group_offset = PCRE2_UNSET; // Saved frame of most recent group |
777 | 2.47M | group_frame_type = 0; // Not a start of group frame |
778 | 2.47M | goto NEW_FRAME; // Start processing with this frame |
779 | | |
780 | | /* Come back here when we want to create a new frame for remembering a |
781 | | backtracking point. */ |
782 | | |
783 | 19.5M | MATCH_RECURSE: |
784 | | |
785 | | /* Set up a new backtracking frame. If the vector is full, get a new one, |
786 | | doubling the size, but constrained by the heap limit (which is in KiB). */ |
787 | | |
788 | 19.5M | N = (heapframe *)((char *)F + frame_size); |
789 | 19.5M | if ((heapframe *)((char *)N + frame_size) >= frames_top) |
790 | 251 | { |
791 | 251 | heapframe *new; |
792 | 251 | PCRE2_SIZE newsize; |
793 | 251 | PCRE2_SIZE usedsize = (char *)N - (char *)(match_data->heapframes); |
794 | | |
795 | 251 | if (match_data->heapframes_size >= PCRE2_SIZE_MAX / 2) |
796 | 0 | { |
797 | 0 | if (match_data->heapframes_size == PCRE2_SIZE_MAX - 1) |
798 | 0 | return PCRE2_ERROR_NOMEMORY; |
799 | 0 | newsize = PCRE2_SIZE_MAX - 1; |
800 | 0 | } |
801 | 251 | else |
802 | 251 | { |
803 | 251 | newsize = match_data->heapframes_size * 2; |
804 | 251 | } |
805 | | |
806 | 251 | if (newsize / 1024 >= mb->heap_limit) |
807 | 0 | { |
808 | 0 | PCRE2_SIZE old_size = match_data->heapframes_size / 1024; |
809 | 0 | if (mb->heap_limit <= old_size) |
810 | 0 | { |
811 | 0 | return PCRE2_ERROR_HEAPLIMIT; |
812 | 0 | } |
813 | 0 | else |
814 | 0 | { |
815 | 0 | PCRE2_SIZE max_delta = 1024 * (mb->heap_limit - old_size); |
816 | 0 | int over_bytes = match_data->heapframes_size % 1024; |
817 | 0 | if (over_bytes) |
818 | 0 | max_delta -= (1024 - over_bytes); |
819 | 0 | newsize = match_data->heapframes_size + max_delta; |
820 | 0 | } |
821 | 0 | } |
822 | | |
823 | | /* With a heap limit set, the permitted additional size may not be enough for |
824 | | another frame, so do a final check. */ |
825 | | |
826 | 251 | if (newsize - usedsize < frame_size) |
827 | 0 | return PCRE2_ERROR_HEAPLIMIT; |
828 | 251 | new = match_data->memctl.malloc(newsize, match_data->memctl.memory_data); |
829 | 251 | if (new == NULL) |
830 | 0 | return PCRE2_ERROR_NOMEMORY; |
831 | 251 | memcpy(new, match_data->heapframes, usedsize); |
832 | | |
833 | 251 | N = (heapframe *)((char *)new + usedsize); |
834 | 251 | F = (heapframe *)((char *)N - frame_size); |
835 | | |
836 | 251 | match_data->memctl.free(match_data->heapframes, match_data->memctl.memory_data); |
837 | 251 | match_data->heapframes = new; |
838 | 251 | match_data->heapframes_size = newsize; |
839 | 251 | frames_top = (heapframe *)((char *)new + newsize); |
840 | 251 | } |
841 | | |
842 | | #ifdef DEBUG_SHOW_RMATCH |
843 | | fprintf(stderr, "++ RMATCH %d frame=%d", Freturn_id, Frdepth + 1); |
844 | | if (group_frame_type != 0) |
845 | | { |
846 | | fprintf(stderr, " type=%x ", group_frame_type); |
847 | | switch (GF_IDMASK(group_frame_type)) |
848 | | { |
849 | | case GF_CAPTURE: |
850 | | fprintf(stderr, "capture=%d", GF_DATAMASK(group_frame_type)); |
851 | | break; |
852 | | |
853 | | case GF_NOCAPTURE: |
854 | | fprintf(stderr, "nocapture op=%d", Fop); |
855 | | break; |
856 | | |
857 | | case GF_CONDASSERT: |
858 | | fprintf(stderr, "condassert op=%d", Fop); |
859 | | break; |
860 | | |
861 | | case GF_RECURSE: |
862 | | fprintf(stderr, "recurse=%d", GF_DATAMASK(group_frame_type)); |
863 | | break; |
864 | | |
865 | | default: |
866 | | fprintf(stderr, "*** unknown ***"); |
867 | | break; |
868 | | } |
869 | | } |
870 | | |
871 | | fprintf(stderr, "\n"); |
872 | | #endif |
873 | | |
874 | | /* Copy those fields that must be copied into the new frame, increase the |
875 | | "recursion" depth (i.e. the new frame's index) and then make the new frame |
876 | | current. */ |
877 | | |
878 | 19.5M | memcpy((char *)N + offsetof(heapframe, eptr), (char *)F + offsetof(heapframe, eptr), |
879 | 19.5M | frame_copy_size); |
880 | | |
881 | 19.5M | N->rdepth = Frdepth + 1; |
882 | 19.5M | F = N; |
883 | | |
884 | | /* Carry on processing with a new frame. */ |
885 | | |
886 | 22.0M | NEW_FRAME: |
887 | 22.0M | Fgroup_frame_type = group_frame_type; |
888 | 22.0M | Fecode = start_ecode; // Starting code pointer |
889 | 22.0M | Fback_frame = frame_size; // Default is go back one frame |
890 | | |
891 | | /* If this is a special type of group frame, remember its offset for quick |
892 | | access at the end of the group. If this is a recursion, set a new current |
893 | | recursion value. */ |
894 | | |
895 | 22.0M | if (group_frame_type != 0) |
896 | 5.01M | { |
897 | 5.01M | Flast_group_offset = (char *)F - (char *)match_data->heapframes; |
898 | 5.01M | if (GF_IDMASK(group_frame_type) == GF_RECURSE) |
899 | 730k | Fcurrent_recurse = GF_DATAMASK(group_frame_type); |
900 | 5.01M | group_frame_type = 0; |
901 | 5.01M | } |
902 | | |
903 | | |
904 | | /* ========================================================================= */ |
905 | | /* This is the main processing loop. First check that we haven't recorded too |
906 | | many backtracks (search tree is too large), or that we haven't exceeded the |
907 | | recursive depth limit (used too many backtracking frames). If not, process the |
908 | | opcodes. */ |
909 | | |
910 | 22.0M | if (mb->match_call_count++ >= mb->match_limit) |
911 | 21.0k | return PCRE2_ERROR_MATCHLIMIT; |
912 | 21.9M | if (Frdepth >= mb->match_limit_depth) |
913 | 0 | return PCRE2_ERROR_DEPTHLIMIT; |
914 | | |
915 | | #ifdef DEBUG_SHOW_OPS |
916 | | fprintf(stderr, "\n++ New frame: type=0x%x subject offset %ld\n", GF_IDMASK(Fgroup_frame_type), |
917 | | Feptr - mb->start_subject); |
918 | | #endif |
919 | | |
920 | 21.9M | for (;;) |
921 | 40.3M | { |
922 | | #ifdef DEBUG_SHOW_OPS |
923 | | fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, OP_names[*Fecode]); |
924 | | #endif |
925 | | |
926 | 40.3M | Fop = (uint8_t)(*Fecode); // Cast needed for 16-bit and 32-bit modes |
927 | 40.3M | switch (Fop) |
928 | 40.3M | { |
929 | | /* ===================================================================== */ |
930 | | /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes, to close |
931 | | any currently open capturing brackets. Unlike reaching the end of a group, |
932 | | where we know the starting frame is at the top of the chained frames, in |
933 | | this case we have to search back for the relevant frame in case other types |
934 | | of group that use chained frames have intervened. Multiple OP_CLOSEs always |
935 | | come innermost first, which matches the chain order. We can ignore this in |
936 | | a recursion, because captures are not passed out of recursions. */ |
937 | | |
938 | 2.36k | case OP_CLOSE: |
939 | 2.36k | if (Fcurrent_recurse == RECURSE_UNSET) |
940 | 2.03k | { |
941 | 2.03k | number = GET2(Fecode, 1); |
942 | 2.03k | offset = Flast_group_offset; |
943 | 2.03k | for (;;) |
944 | 2.59k | { |
945 | | /* Corrupted heapframes?. Trigger an assert and return an error */ |
946 | 2.59k | PCRE2_ASSERT(offset != PCRE2_UNSET); |
947 | 2.59k | if (offset == PCRE2_UNSET) |
948 | 0 | return PCRE2_ERROR_INTERNAL; |
949 | | |
950 | 2.59k | N = (heapframe *)((char *)match_data->heapframes + offset); |
951 | 2.59k | P = (heapframe *)((char *)N - frame_size); |
952 | 2.59k | if (N->group_frame_type == (GF_CAPTURE | number)) |
953 | 2.03k | break; |
954 | 557 | offset = P->last_group_offset; |
955 | 557 | } |
956 | | |
957 | 2.03k | offset = (number << 1) - 2; |
958 | 2.03k | Fcapture_last = number; |
959 | 2.03k | Fovector[offset] = P->eptr - mb->start_subject; |
960 | 2.03k | Fovector[offset + 1] = Feptr - mb->start_subject; |
961 | 2.03k | if (offset >= Foffset_top) |
962 | 1.24k | Foffset_top = offset + 2; |
963 | 2.03k | } |
964 | | |
965 | 2.36k | Fecode += PRIV(OP_lengths)[*Fecode]; |
966 | 2.36k | break; |
967 | | |
968 | | |
969 | | /* ===================================================================== */ |
970 | | /* Real or forced end of the pattern, assertion, or recursion. In an |
971 | | assertion ACCEPT, update the last used pointer and remember the current |
972 | | frame so that the captures and mark can be fished out of it. */ |
973 | | |
974 | 9.64k | case OP_ASSERT_ACCEPT: |
975 | 9.64k | if (Feptr > mb->last_used_ptr) |
976 | 1.63k | mb->last_used_ptr = Feptr; |
977 | 9.64k | assert_accept_frame = F; |
978 | 9.64k | RRETURN(MATCH_ACCEPT); |
979 | | |
980 | | /* For ACCEPT within a recursion, we have to find the most recent |
981 | | recursion. If not in a recursion, fall through to code that is common with |
982 | | OP_END. */ |
983 | | |
984 | 7.11k | case OP_ACCEPT: |
985 | 7.11k | if (Fcurrent_recurse != RECURSE_UNSET) |
986 | 631 | { |
987 | | #ifdef DEBUG_SHOW_OPS |
988 | | fprintf(stderr, "++ Accept within recursion\n"); |
989 | | #endif |
990 | 631 | offset = Flast_group_offset; |
991 | 631 | for (;;) |
992 | 1.24k | { |
993 | | /* Corrupted heapframes?. Trigger an assert and return an error */ |
994 | 1.24k | PCRE2_ASSERT(offset != PCRE2_UNSET); |
995 | 1.24k | if (offset == PCRE2_UNSET) |
996 | 0 | return PCRE2_ERROR_INTERNAL; |
997 | | |
998 | 1.24k | N = (heapframe *)((char *)match_data->heapframes + offset); |
999 | 1.24k | P = (heapframe *)((char *)N - frame_size); |
1000 | 1.24k | if (GF_IDMASK(N->group_frame_type) == GF_RECURSE) |
1001 | 631 | break; |
1002 | 612 | offset = P->last_group_offset; |
1003 | 612 | } |
1004 | | |
1005 | | /* N is now the frame of the recursion; the previous frame is at the |
1006 | | OP_RECURSE position. Go back there, copying the current subject position |
1007 | | and mark, and the start_match position (\K might have changed it), and |
1008 | | then move on past the OP_RECURSE. */ |
1009 | | |
1010 | 631 | P->eptr = Feptr; |
1011 | 631 | P->mark = Fmark; |
1012 | 631 | P->start_match = Fstart_match; |
1013 | 631 | F = P; |
1014 | 631 | Fecode += 1 + LINK_SIZE; |
1015 | 631 | continue; |
1016 | 631 | } |
1017 | | |
1018 | 6.48k | PCRE2_FALLTHROUGH /* Fall through */ |
1019 | 6.48k | |
1020 | 6.48k | /* OP_END itself can never be reached within a recursion because that is |
1021 | 6.48k | picked up when the OP_KET that always precedes OP_END is reached. */ |
1022 | 6.48k | |
1023 | 637k | case OP_END: |
1024 | | |
1025 | | /* Fail for an empty string match if either PCRE2_NOTEMPTY is set, or if |
1026 | | PCRE2_NOTEMPTY_ATSTART is set and we have matched at the start of the |
1027 | | subject. In both cases, backtracking will then try other alternatives, if |
1028 | | any. */ |
1029 | | |
1030 | 637k | if (Feptr == Fstart_match && ((mb->moptions & PCRE2_NOTEMPTY) != 0 || |
1031 | 147k | ((mb->moptions & PCRE2_NOTEMPTY_ATSTART) != 0 && |
1032 | 31.8k | Fstart_match == mb->start_subject + mb->start_offset))) |
1033 | 211k | { |
1034 | | #ifdef DEBUG_SHOW_OPS |
1035 | | fprintf(stderr, "++ Backtrack because empty string\n"); |
1036 | | #endif |
1037 | 211k | RRETURN(MATCH_NOMATCH); |
1038 | 211k | } |
1039 | | |
1040 | | /* Fail if PCRE2_ENDANCHORED is set and the end of the match is not |
1041 | | the end of the subject. After (*ACCEPT) we fail the entire match (at this |
1042 | | position) but backtrack if we've reached the end of the pattern. This |
1043 | | applies whether or not we are in a recursion. */ |
1044 | | |
1045 | 425k | if (Feptr < mb->end_subject && ((mb->moptions | mb->poptions) & PCRE2_ENDANCHORED) != 0) |
1046 | 353k | { |
1047 | 353k | if (Fop == OP_END) |
1048 | 351k | { |
1049 | | #ifdef DEBUG_SHOW_OPS |
1050 | | fprintf(stderr, "++ Backtrack because not at end (endanchored set)\n"); |
1051 | | #endif |
1052 | 351k | RRETURN(MATCH_NOMATCH); |
1053 | 351k | } |
1054 | | |
1055 | | #ifdef DEBUG_SHOW_OPS |
1056 | | fprintf(stderr, "++ Failed ACCEPT not at end (endanchored set)\n"); |
1057 | | #endif |
1058 | 2.18k | return MATCH_NOMATCH; // (*ACCEPT) |
1059 | 353k | } |
1060 | | |
1061 | | /* Fail if we detect that the start position was moved to be either after |
1062 | | the end position (\K in lookahead) or before the start offset (\K in |
1063 | | lookbehind). If this occurs, the pattern must have used \K in a somewhat |
1064 | | sneaky way (e.g. by pattern recursion), because if the \K is actually |
1065 | | syntactically inside the lookaround, it's blocked at compile-time. */ |
1066 | | |
1067 | 72.2k | if (Fstart_match < mb->start_subject + mb->start_offset || Fstart_match > Feptr) |
1068 | 7 | { |
1069 | | /* The \K expression is fairly rare. We assert it was used so that we |
1070 | | catch any unexpected invalid data in start_match. */ |
1071 | 7 | PCRE2_ASSERT(mb->hasbsk); |
1072 | | |
1073 | 7 | if (!mb->allowlookaroundbsk) |
1074 | 7 | return PCRE2_ERROR_BAD_BACKSLASH_K; |
1075 | 7 | } |
1076 | | |
1077 | | /* We have a successful match of the whole pattern. Record the result and |
1078 | | then do a direct return from the function. If there is space in the offset |
1079 | | vector, set any pairs that follow the highest-numbered captured string but |
1080 | | are less than the number of capturing groups in the pattern to PCRE2_UNSET. |
1081 | | It is documented that this happens. "Gaps" are set to PCRE2_UNSET |
1082 | | dynamically. It is only those at the end that need setting here. */ |
1083 | | |
1084 | 72.2k | mb->end_match_ptr = Feptr; // Record where we ended |
1085 | 72.2k | mb->end_offset_top = Foffset_top; // and how many extracts were taken |
1086 | 72.2k | mb->mark = Fmark; // and the last success mark |
1087 | 72.2k | if (Feptr > mb->last_used_ptr) |
1088 | 39.2k | mb->last_used_ptr = Feptr; |
1089 | | |
1090 | 72.2k | match_data->ovector[0] = Fstart_match - mb->start_subject; |
1091 | 72.2k | match_data->ovector[1] = Feptr - mb->start_subject; |
1092 | | |
1093 | | /* Set i to the smaller of the sizes of the external and frame ovectors. */ |
1094 | | |
1095 | 72.2k | i = 2 * ((top_bracket + 1 > match_data->oveccount) ? match_data->oveccount : top_bracket + 1); |
1096 | 72.2k | memcpy(match_data->ovector + 2, Fovector, (i - 2) * sizeof(PCRE2_SIZE)); |
1097 | 93.5k | while (--i >= Foffset_top + 2) |
1098 | 21.2k | match_data->ovector[i] = PCRE2_UNSET; |
1099 | 72.2k | return MATCH_MATCH; // Note: NOT RRETURN |
1100 | | |
1101 | | |
1102 | | /*===================================================================== */ |
1103 | | /* Match any single character type except newline; have to take care with |
1104 | | CRLF newlines and partial matching. */ |
1105 | | |
1106 | 116k | case OP_ANY: |
1107 | 116k | if (IS_NEWLINE(Feptr)) |
1108 | 935 | RRETURN(MATCH_NOMATCH); |
1109 | 115k | if (mb->partial != 0 && Feptr == mb->end_subject - 1 && NLBLOCK->nltype == NLTYPE_FIXED && |
1110 | 2.09k | NLBLOCK->nllen == 2 && *Feptr == NLBLOCK->nl[0]) |
1111 | 0 | { |
1112 | 0 | mb->hitend = TRUE; |
1113 | 0 | if (mb->partial > 1) |
1114 | 0 | return PCRE2_ERROR_PARTIAL; |
1115 | 0 | } |
1116 | | |
1117 | 115k | PCRE2_FALLTHROUGH /* Fall through */ |
1118 | 115k | |
1119 | 115k | /* Match any single character whatsoever. */ |
1120 | 115k | |
1121 | 156k | case OP_ALLANY: |
1122 | | /* DO NOT merge the Feptr++ here; it must not be updated before SCHECK_PARTIAL. */ |
1123 | 156k | if (Feptr >= mb->end_subject) |
1124 | 11.5k | { |
1125 | 11.5k | SCHECK_PARTIAL(); |
1126 | 11.4k | RRETURN(MATCH_NOMATCH); |
1127 | 11.4k | } |
1128 | | |
1129 | 144k | Feptr++; |
1130 | 144k | #ifdef SUPPORT_UNICODE |
1131 | 144k | if (utf) |
1132 | 32.6k | ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); |
1133 | 144k | #endif |
1134 | 144k | Fecode++; |
1135 | 144k | break; |
1136 | | |
1137 | | |
1138 | | /* ===================================================================== */ |
1139 | | /* Match a single code unit, even in UTF mode. This opcode really does |
1140 | | match any code unit, even newline. (It really should be called ANYCODEUNIT, |
1141 | | of course - the byte name is from pre-16 bit days.) */ |
1142 | | |
1143 | 0 | case OP_ANYBYTE: |
1144 | | /* DO NOT merge the Feptr++ here; it must not be updated before SCHECK_PARTIAL. */ |
1145 | 0 | if (Feptr >= mb->end_subject) |
1146 | 0 | { |
1147 | 0 | SCHECK_PARTIAL(); |
1148 | 0 | RRETURN(MATCH_NOMATCH); |
1149 | 0 | } |
1150 | | |
1151 | 0 | Feptr++; |
1152 | 0 | Fecode++; |
1153 | 0 | break; |
1154 | | |
1155 | | |
1156 | | /* ===================================================================== */ |
1157 | | /* Match a single character, casefully */ |
1158 | | |
1159 | 10.6M | case OP_CHAR: |
1160 | 10.6M | #ifdef SUPPORT_UNICODE |
1161 | 10.6M | if (utf) |
1162 | 1.60M | { |
1163 | 1.60M | length = 1; |
1164 | 1.60M | Fecode++; |
1165 | 1.60M | GETCHARLEN(fc, Fecode, length); |
1166 | 1.60M | if (length > (PCRE2_SIZE)(mb->end_subject - Feptr)) |
1167 | 73.8k | { |
1168 | 73.8k | CHECK_PARTIAL(); // Not SCHECK_PARTIAL() |
1169 | 73.6k | RRETURN(MATCH_NOMATCH); |
1170 | 73.6k | } |
1171 | | |
1172 | 1.77M | for (; length > 0; length--) |
1173 | 1.53M | { |
1174 | 1.53M | if (*Fecode++ != *Feptr++) |
1175 | 1.29M | RRETURN(MATCH_NOMATCH); |
1176 | 1.53M | } |
1177 | 1.53M | } |
1178 | 9.08M | else |
1179 | 9.08M | #endif |
1180 | | |
1181 | | /* Not UTF mode */ |
1182 | 9.08M | { |
1183 | 9.08M | if (mb->end_subject - Feptr < 1) |
1184 | 269k | { |
1185 | 269k | SCHECK_PARTIAL(); // This one can use SCHECK_PARTIAL() |
1186 | 267k | RRETURN(MATCH_NOMATCH); |
1187 | 267k | } |
1188 | | |
1189 | 8.81M | if (Fecode[1] != *Feptr++) |
1190 | 5.16M | RRETURN(MATCH_NOMATCH); |
1191 | 3.65M | Fecode += 2; |
1192 | 3.65M | } |
1193 | | |
1194 | 3.89M | break; |
1195 | | |
1196 | | |
1197 | | /* ===================================================================== */ |
1198 | | /* Match a single character, caselessly. If we are at the end of the |
1199 | | subject, give up immediately. We get here only when the pattern character |
1200 | | has at most one other case. Characters with more than two cases are coded |
1201 | | as OP_PROP with the pseudo-property PT_CLIST. */ |
1202 | | |
1203 | 3.89M | case OP_CHARI: |
1204 | 3.16M | if (Feptr >= mb->end_subject) |
1205 | 118k | { |
1206 | 118k | SCHECK_PARTIAL(); |
1207 | 117k | RRETURN(MATCH_NOMATCH); |
1208 | 117k | } |
1209 | | |
1210 | 3.05M | #ifdef SUPPORT_UNICODE |
1211 | 3.05M | if (utf) |
1212 | 1.51M | { |
1213 | 1.51M | length = 1; |
1214 | 1.51M | Fecode++; |
1215 | 1.51M | GETCHARLEN(fc, Fecode, length); |
1216 | | |
1217 | | /* If the pattern character's value is < 128, we know that its other case |
1218 | | (if any) is also < 128 (and therefore only one code unit long in all |
1219 | | code-unit widths), so we can use the fast lookup table. We checked above |
1220 | | that there is at least one character left in the subject. */ |
1221 | | |
1222 | 1.51M | if (fc < 128) |
1223 | 474k | { |
1224 | 474k | uint32_t cc = *Feptr; |
1225 | 474k | if (mb->lcc[fc] != TABLE_GET(cc, mb->lcc, cc)) |
1226 | 311k | RRETURN(MATCH_NOMATCH); |
1227 | 162k | Fecode++; |
1228 | 162k | Feptr++; |
1229 | 162k | } |
1230 | | |
1231 | | /* Otherwise we must pick up the subject character and use Unicode |
1232 | | property support to test its other case. Note that we cannot use the |
1233 | | value of "length" to check for sufficient bytes left, because the other |
1234 | | case of the character may have more or fewer code units. */ |
1235 | | |
1236 | 1.03M | else |
1237 | 1.03M | { |
1238 | 1.03M | uint32_t dc; |
1239 | 1.03M | GETCHARINC(dc, Feptr); |
1240 | 1.03M | Fecode += length; |
1241 | 1.03M | if (dc != fc && dc != UCD_OTHERCASE(fc)) |
1242 | 918k | RRETURN(MATCH_NOMATCH); |
1243 | 1.03M | } |
1244 | 1.51M | } |
1245 | | |
1246 | | /* If UCP is set without UTF we must do the same as above, but with one |
1247 | | character per code unit. */ |
1248 | | |
1249 | 1.53M | else if (ucp) |
1250 | 520k | { |
1251 | 520k | uint32_t cc = *Feptr; |
1252 | 520k | fc = Fecode[1]; |
1253 | 520k | if (fc < 128) |
1254 | 198k | { |
1255 | 198k | if (mb->lcc[fc] != TABLE_GET(cc, mb->lcc, cc)) |
1256 | 174k | RRETURN(MATCH_NOMATCH); |
1257 | 198k | } |
1258 | 321k | else |
1259 | 321k | { |
1260 | 321k | if (cc != fc && cc != UCD_OTHERCASE(fc)) |
1261 | 286k | RRETURN(MATCH_NOMATCH); |
1262 | 321k | } |
1263 | | |
1264 | 59.5k | Feptr++; |
1265 | 59.5k | Fecode += 2; |
1266 | 59.5k | } |
1267 | | |
1268 | 1.01M | else |
1269 | 1.01M | #endif /* SUPPORT_UNICODE */ |
1270 | | |
1271 | | /* Not UTF or UCP mode; use the table for characters < 256. */ |
1272 | 1.01M | { |
1273 | 1.01M | if (TABLE_GET(Fecode[1], mb->lcc, Fecode[1]) != TABLE_GET(*Feptr, mb->lcc, *Feptr)) |
1274 | 887k | RRETURN(MATCH_NOMATCH); |
1275 | 131k | Feptr++; |
1276 | 131k | Fecode += 2; |
1277 | 131k | } |
1278 | | |
1279 | 473k | break; |
1280 | | |
1281 | | |
1282 | | /* ===================================================================== */ |
1283 | | /* Match not a single character. */ |
1284 | | |
1285 | 473k | case OP_NOT: |
1286 | 244k | case OP_NOTI: |
1287 | 244k | if (Feptr >= mb->end_subject) |
1288 | 5.74k | { |
1289 | 5.74k | SCHECK_PARTIAL(); |
1290 | 5.72k | RRETURN(MATCH_NOMATCH); |
1291 | 5.72k | } |
1292 | | |
1293 | 238k | #ifdef SUPPORT_UNICODE |
1294 | 238k | if (utf) |
1295 | 38.5k | { |
1296 | 38.5k | uint32_t ch; |
1297 | 38.5k | Fecode++; |
1298 | 38.5k | GETCHARINC(ch, Fecode); |
1299 | 38.5k | GETCHARINC(fc, Feptr); |
1300 | 38.5k | if (ch == fc) |
1301 | 3.55k | { |
1302 | 3.55k | RRETURN(MATCH_NOMATCH); // Caseful match |
1303 | 3.55k | } |
1304 | 34.9k | else if (Fop == OP_NOTI) // If caseless |
1305 | 18.7k | { |
1306 | 18.7k | if (ch > 127) |
1307 | 5.73k | ch = UCD_OTHERCASE(ch); |
1308 | 12.9k | else |
1309 | 12.9k | ch = (mb->fcc)[ch]; |
1310 | 18.7k | if (ch == fc) |
1311 | 444 | RRETURN(MATCH_NOMATCH); |
1312 | 18.7k | } |
1313 | 38.5k | } |
1314 | | |
1315 | | /* UCP without UTF is as above, but with one character per code unit. */ |
1316 | | |
1317 | 200k | else if (ucp) |
1318 | 5.92k | { |
1319 | 5.92k | uint32_t ch; |
1320 | 5.92k | fc = *Feptr++; |
1321 | 5.92k | ch = Fecode[1]; |
1322 | 5.92k | Fecode += 2; |
1323 | | |
1324 | 5.92k | if (ch == fc) |
1325 | 938 | { |
1326 | 938 | RRETURN(MATCH_NOMATCH); // Caseful match |
1327 | 938 | } |
1328 | 4.99k | else if (Fop == OP_NOTI) // If caseless |
1329 | 4.07k | { |
1330 | 4.07k | if (ch > 127) |
1331 | 681 | ch = UCD_OTHERCASE(ch); |
1332 | 3.39k | else |
1333 | 3.39k | ch = (mb->fcc)[ch]; |
1334 | 4.07k | if (ch == fc) |
1335 | 202 | RRETURN(MATCH_NOMATCH); |
1336 | 4.07k | } |
1337 | 5.92k | } |
1338 | | |
1339 | 194k | else |
1340 | 194k | #endif /* SUPPORT_UNICODE */ |
1341 | | |
1342 | | /* Neither UTF nor UCP is set */ |
1343 | | |
1344 | 194k | { |
1345 | 194k | uint32_t ch = Fecode[1]; |
1346 | 194k | fc = *Feptr++; |
1347 | 194k | if (ch == fc || (Fop == OP_NOTI && TABLE_GET(ch, mb->fcc, ch) == fc)) |
1348 | 9.60k | RRETURN(MATCH_NOMATCH); |
1349 | 184k | Fecode += 2; |
1350 | 184k | } |
1351 | | |
1352 | 223k | break; |
1353 | | |
1354 | | |
1355 | | /* ===================================================================== */ |
1356 | | /* Match a single character repeatedly. */ |
1357 | | |
1358 | 717k | #define Llength F->byte1 |
1359 | 223k | #define Loclength F->byte2 |
1360 | 2.49M | #define Lstart_eptr F->fields.char_repeat.start_eptr |
1361 | 683k | #define Lcharptr F->fields.char_repeat.charptr |
1362 | 7.77M | #define Lmin F->fields.char_repeat.min |
1363 | 5.70M | #define Lmax F->fields.char_repeat.max |
1364 | 4.49M | #define Lc F->fields.char_repeat.c |
1365 | 841k | #define Loc F->fields.char_repeat.oc.oc |
1366 | 223k | #define Loccu F->fields.char_repeat.oc.occu |
1367 | | |
1368 | 223k | case OP_EXACT: |
1369 | 34.9k | case OP_EXACTI: |
1370 | 34.9k | Lmin = Lmax = GET2(Fecode, 1); |
1371 | 34.9k | Fecode += 1 + IMM2_SIZE; |
1372 | 34.9k | goto REPEATCHAR; |
1373 | | |
1374 | 9.97k | case OP_POSUPTO: |
1375 | 12.0k | case OP_POSUPTOI: |
1376 | 12.0k | reptype = REPTYPE_POS; |
1377 | 12.0k | Lmin = 0; |
1378 | 12.0k | Lmax = GET2(Fecode, 1); |
1379 | 12.0k | Fecode += 1 + IMM2_SIZE; |
1380 | 12.0k | goto REPEATCHAR; |
1381 | | |
1382 | 26.3k | case OP_UPTO: |
1383 | 28.1k | case OP_UPTOI: |
1384 | 28.1k | reptype = REPTYPE_MAX; |
1385 | 28.1k | Lmin = 0; |
1386 | 28.1k | Lmax = GET2(Fecode, 1); |
1387 | 28.1k | Fecode += 1 + IMM2_SIZE; |
1388 | 28.1k | goto REPEATCHAR; |
1389 | | |
1390 | 3.72k | case OP_MINUPTO: |
1391 | 6.28k | case OP_MINUPTOI: |
1392 | 6.28k | reptype = REPTYPE_MIN; |
1393 | 6.28k | Lmin = 0; |
1394 | 6.28k | Lmax = GET2(Fecode, 1); |
1395 | 6.28k | Fecode += 1 + IMM2_SIZE; |
1396 | 6.28k | goto REPEATCHAR; |
1397 | | |
1398 | 166k | case OP_POSSTAR: |
1399 | 279k | case OP_POSSTARI: |
1400 | 279k | reptype = REPTYPE_POS; |
1401 | 279k | Lmin = 0; |
1402 | 279k | Lmax = UINT32_MAX; |
1403 | 279k | Fecode++; |
1404 | 279k | goto REPEATCHAR; |
1405 | | |
1406 | 247k | case OP_POSPLUS: |
1407 | 381k | case OP_POSPLUSI: |
1408 | 381k | reptype = REPTYPE_POS; |
1409 | 381k | Lmin = 1; |
1410 | 381k | Lmax = UINT32_MAX; |
1411 | 381k | Fecode++; |
1412 | 381k | goto REPEATCHAR; |
1413 | | |
1414 | 279k | case OP_POSQUERY: |
1415 | 310k | case OP_POSQUERYI: |
1416 | 310k | reptype = REPTYPE_POS; |
1417 | 310k | Lmin = 0; |
1418 | 310k | Lmax = 1; |
1419 | 310k | Fecode++; |
1420 | 310k | goto REPEATCHAR; |
1421 | | |
1422 | 97.4k | case OP_STAR: |
1423 | 123k | case OP_STARI: |
1424 | 139k | case OP_MINSTAR: |
1425 | 182k | case OP_MINSTARI: |
1426 | 221k | case OP_PLUS: |
1427 | 235k | case OP_PLUSI: |
1428 | 256k | case OP_MINPLUS: |
1429 | 291k | case OP_MINPLUSI: |
1430 | 972k | case OP_QUERY: |
1431 | 997k | case OP_QUERYI: |
1432 | 1.03M | case OP_MINQUERY: |
1433 | 1.06M | case OP_MINQUERYI: |
1434 | 1.06M | fc = *Fecode++ - ((Fop < OP_STARI) ? OP_STAR : OP_STARI); |
1435 | 1.06M | Lmin = rep_min[fc]; |
1436 | 1.06M | Lmax = rep_max[fc]; |
1437 | 1.06M | reptype = rep_typ[fc]; |
1438 | | |
1439 | | /* Common code for all repeated single-character matches. We first check |
1440 | | for the minimum number of characters. If the minimum equals the maximum, we |
1441 | | are done. Otherwise, if minimizing, check the rest of the pattern for a |
1442 | | match; if there isn't one, advance up to the maximum, one character at a |
1443 | | time. |
1444 | | |
1445 | | If maximizing, advance up to the maximum number of matching characters, |
1446 | | until Feptr is past the end of the maximum run. If possessive, we are |
1447 | | then done (no backing up). Otherwise, match at this position; anything |
1448 | | other than no match is immediately returned. For nomatch, back up one |
1449 | | character, unless we are matching \R and the last thing matched was |
1450 | | \r\n, in which case, back up two code units until we reach the first |
1451 | | optional character position. |
1452 | | |
1453 | | The various UTF/non-UTF and caseful/caseless cases are handled separately, |
1454 | | for speed. */ |
1455 | | |
1456 | 2.11M | REPEATCHAR: |
1457 | 2.11M | #ifdef SUPPORT_UNICODE |
1458 | 2.11M | if (utf) |
1459 | 642k | { |
1460 | 642k | length = 1; |
1461 | 642k | Lcharptr = Fecode; |
1462 | 642k | GETCHARLEN(fc, Fecode, length); |
1463 | 642k | Fecode += length; |
1464 | 642k | Llength = (uint8_t)length; |
1465 | | |
1466 | | /* Handle multi-code-unit character matching, caseful and caseless. */ |
1467 | | |
1468 | 642k | if (length > 1) |
1469 | 50.1k | { |
1470 | 50.1k | uint32_t othercase; |
1471 | | |
1472 | 50.1k | if (Fop >= OP_STARI && // Caseless |
1473 | 29.1k | (othercase = UCD_OTHERCASE(fc)) != fc) |
1474 | 18.9k | Loclength = (uint8_t)PRIV(ord2utf)(othercase, Loccu); |
1475 | 31.1k | else |
1476 | 31.1k | Loclength = 0; |
1477 | | |
1478 | 52.7k | for (i = 1; i <= Lmin; i++) |
1479 | 17.4k | { |
1480 | 17.4k | if (Feptr <= mb->end_subject - length && memcmp(Feptr, Lcharptr, CU2BYTES(length)) == 0) |
1481 | 2.41k | { |
1482 | 2.41k | Feptr += length; |
1483 | 2.41k | } |
1484 | 15.0k | else if (Loclength > 0 && Feptr <= mb->end_subject - Loclength && |
1485 | 2.56k | memcmp(Feptr, Loccu, CU2BYTES(Loclength)) == 0) |
1486 | 202 | { |
1487 | 202 | Feptr += Loclength; |
1488 | 202 | } |
1489 | 14.8k | else |
1490 | 14.8k | { |
1491 | 14.8k | CHECK_PARTIAL(); |
1492 | 14.8k | RRETURN(MATCH_NOMATCH); |
1493 | 14.8k | } |
1494 | 17.4k | } |
1495 | | |
1496 | 35.3k | if (Lmin == Lmax) |
1497 | 218 | continue; |
1498 | | |
1499 | 35.1k | if (reptype == REPTYPE_MIN) |
1500 | 13.4k | { |
1501 | 13.4k | for (;;) |
1502 | 14.6k | { |
1503 | 14.6k | RMATCH(Fecode, RM202); |
1504 | 14.3k | if (rrc != MATCH_NOMATCH) |
1505 | 290 | RRETURN(rrc); |
1506 | 14.0k | if (Lmin++ >= Lmax) |
1507 | 680 | RRETURN(MATCH_NOMATCH); |
1508 | 13.3k | if (Feptr <= mb->end_subject - Llength && |
1509 | 10.3k | memcmp(Feptr, Lcharptr, CU2BYTES(Llength)) == 0) |
1510 | 1.01k | { |
1511 | 1.01k | Feptr += Llength; |
1512 | 1.01k | } |
1513 | 12.3k | else if (Loclength > 0 && Feptr <= mb->end_subject - Loclength && |
1514 | 5.56k | memcmp(Feptr, Loccu, CU2BYTES(Loclength)) == 0) |
1515 | 210 | { |
1516 | 210 | Feptr += Loclength; |
1517 | 210 | } |
1518 | 12.1k | else |
1519 | 12.1k | { |
1520 | 12.1k | CHECK_PARTIAL(); |
1521 | 12.1k | RRETURN(MATCH_NOMATCH); |
1522 | 12.1k | } |
1523 | 13.3k | } |
1524 | | |
1525 | 13.4k | PCRE2_UNREACHABLE(); // Control never reaches here |
1526 | 13.4k | } |
1527 | 21.6k | else // Maximize |
1528 | 21.6k | { |
1529 | 21.6k | Lstart_eptr = Feptr; |
1530 | 24.3k | for (i = Lmin; i < Lmax; i++) |
1531 | 22.6k | { |
1532 | 22.6k | if (Feptr <= mb->end_subject - Llength && |
1533 | 17.7k | memcmp(Feptr, Lcharptr, CU2BYTES(Llength)) == 0) |
1534 | 2.44k | { |
1535 | 2.44k | Feptr += Llength; |
1536 | 2.44k | } |
1537 | 20.1k | else if (Loclength > 0 && Feptr <= mb->end_subject - Loclength && |
1538 | 7.00k | memcmp(Feptr, Loccu, CU2BYTES(Loclength)) == 0) |
1539 | 206 | { |
1540 | 206 | Feptr += Loclength; |
1541 | 206 | } |
1542 | 19.9k | else |
1543 | 19.9k | { |
1544 | 19.9k | CHECK_PARTIAL(); |
1545 | 19.9k | break; |
1546 | 19.9k | } |
1547 | 22.6k | } |
1548 | | |
1549 | | /* After \C in UTF mode, Lstart_eptr might be in the middle of a |
1550 | | Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't |
1551 | | go too far. */ |
1552 | | |
1553 | 21.6k | if (reptype != REPTYPE_POS) |
1554 | 11.1k | { |
1555 | 11.1k | for (;;) |
1556 | 11.9k | { |
1557 | 11.9k | if (Feptr <= Lstart_eptr) |
1558 | 10.7k | break; |
1559 | 1.19k | RMATCH(Fecode, RM203); |
1560 | 1.16k | if (rrc != MATCH_NOMATCH) |
1561 | 379 | RRETURN(rrc); |
1562 | 786 | Feptr--; |
1563 | 786 | BACKCHAR(Feptr); |
1564 | 786 | } |
1565 | 11.1k | } |
1566 | 21.6k | } |
1567 | | |
1568 | 21.2k | break; // End of repeated wide character handling |
1569 | 35.1k | } |
1570 | | |
1571 | | /* Length of UTF character is 1. Put it into the preserved variable and |
1572 | | fall through to the non-UTF code. */ |
1573 | | |
1574 | 592k | Lc = fc; |
1575 | 592k | } |
1576 | 1.47M | else |
1577 | 1.47M | #endif /* SUPPORT_UNICODE */ |
1578 | | |
1579 | | /* When not in UTF mode, load a single-code-unit character. Then proceed as |
1580 | | above, using Unicode casing if either UTF or UCP is set. */ |
1581 | | |
1582 | 1.47M | Lc = *Fecode++; |
1583 | | |
1584 | | /* Caseless comparison */ |
1585 | | |
1586 | 2.06M | if (Fop >= OP_STARI) |
1587 | 440k | { |
1588 | | #if PCRE2_CODE_UNIT_WIDTH == 8 |
1589 | | #ifdef SUPPORT_UNICODE |
1590 | | if (ucp && !utf && Lc > 127) |
1591 | | Loc = UCD_OTHERCASE(Lc); |
1592 | | else |
1593 | | #endif /* SUPPORT_UNICODE */ |
1594 | | /* Lc will be < 128 in UTF-8 mode. */ |
1595 | | Loc = mb->fcc[Lc]; |
1596 | | #else /* 16-bit & 32-bit */ |
1597 | 440k | #ifdef SUPPORT_UNICODE |
1598 | 440k | if ((utf || ucp) && Lc > 127) |
1599 | 134k | Loc = UCD_OTHERCASE(Lc); |
1600 | 305k | else |
1601 | 305k | #endif /* SUPPORT_UNICODE */ |
1602 | 305k | Loc = TABLE_GET(Lc, mb->fcc, Lc); |
1603 | 440k | #endif /* PCRE2_CODE_UNIT_WIDTH == 8 */ |
1604 | | |
1605 | 479k | for (i = 1; i <= Lmin; i++) |
1606 | 188k | { |
1607 | 188k | uint32_t cc; // Faster than PCRE2_UCHAR |
1608 | 188k | if (Feptr >= mb->end_subject) |
1609 | 8.30k | { |
1610 | 8.30k | SCHECK_PARTIAL(); |
1611 | 8.28k | RRETURN(MATCH_NOMATCH); |
1612 | 8.28k | } |
1613 | | |
1614 | 180k | cc = *Feptr; |
1615 | 180k | if (Lc != cc && Loc != cc) |
1616 | 140k | RRETURN(MATCH_NOMATCH); |
1617 | 39.5k | Feptr++; |
1618 | 39.5k | } |
1619 | | |
1620 | 290k | if (Lmin == Lmax) |
1621 | 266 | continue; |
1622 | | |
1623 | 290k | if (reptype == REPTYPE_MIN) |
1624 | 70.8k | { |
1625 | 70.8k | for (;;) |
1626 | 83.5k | { |
1627 | 83.5k | uint32_t cc; // Faster than PCRE2_UCHAR |
1628 | 83.5k | RMATCH(Fecode, RM25); |
1629 | 76.0k | if (rrc != MATCH_NOMATCH) |
1630 | 1.54k | RRETURN(rrc); |
1631 | 74.4k | if (Lmin++ >= Lmax) |
1632 | 2.48k | RRETURN(MATCH_NOMATCH); |
1633 | 71.9k | if (Feptr >= mb->end_subject) |
1634 | 5.06k | { |
1635 | 5.06k | SCHECK_PARTIAL(); |
1636 | 5.03k | RRETURN(MATCH_NOMATCH); |
1637 | 5.03k | } |
1638 | | |
1639 | 66.9k | cc = *Feptr; |
1640 | 66.9k | if (Lc != cc && Loc != cc) |
1641 | 54.2k | RRETURN(MATCH_NOMATCH); |
1642 | 12.6k | Feptr++; |
1643 | 12.6k | } |
1644 | | |
1645 | 70.8k | PCRE2_UNREACHABLE(); // Control never reaches here |
1646 | 70.8k | } |
1647 | | |
1648 | 219k | else // Maximize |
1649 | 219k | { |
1650 | 219k | Lstart_eptr = Feptr; |
1651 | 255k | for (i = Lmin; i < Lmax; i++) |
1652 | 249k | { |
1653 | 249k | uint32_t cc; // Faster than PCRE2_UCHAR |
1654 | 249k | if (Feptr >= mb->end_subject) |
1655 | 7.93k | { |
1656 | 7.93k | SCHECK_PARTIAL(); |
1657 | 7.89k | break; |
1658 | 7.93k | } |
1659 | | |
1660 | 241k | cc = *Feptr; |
1661 | 241k | if (Lc != cc && Loc != cc) |
1662 | 204k | break; |
1663 | 36.1k | Feptr++; |
1664 | 36.1k | } |
1665 | | |
1666 | 219k | if (reptype != REPTYPE_POS) |
1667 | 48.6k | { |
1668 | 48.6k | for (;;) |
1669 | 53.1k | { |
1670 | 53.1k | if (Feptr == Lstart_eptr) |
1671 | 47.9k | break; |
1672 | 5.21k | RMATCH(Fecode, RM26); |
1673 | 4.91k | Feptr--; |
1674 | 4.91k | if (rrc != MATCH_NOMATCH) |
1675 | 424 | RRETURN(rrc); |
1676 | 4.91k | } |
1677 | 48.6k | } |
1678 | 219k | } |
1679 | 290k | } |
1680 | | |
1681 | | /* Caseful comparisons (includes all multi-byte characters) */ |
1682 | | |
1683 | 1.62M | else |
1684 | 1.62M | { |
1685 | 1.70M | for (i = 1; i <= Lmin; i++) |
1686 | 325k | { |
1687 | 325k | if (Feptr >= mb->end_subject) |
1688 | 21.2k | { |
1689 | 21.2k | SCHECK_PARTIAL(); |
1690 | 21.1k | RRETURN(MATCH_NOMATCH); |
1691 | 21.1k | } |
1692 | | |
1693 | 303k | if (Lc != *Feptr++) |
1694 | 227k | RRETURN(MATCH_NOMATCH); |
1695 | 303k | } |
1696 | | |
1697 | 1.37M | if (Lmin == Lmax) |
1698 | 526 | continue; |
1699 | | |
1700 | 1.37M | if (reptype == REPTYPE_MIN) |
1701 | 58.3k | { |
1702 | 58.3k | for (;;) |
1703 | 70.9k | { |
1704 | 70.9k | RMATCH(Fecode, RM27); |
1705 | 61.5k | if (rrc != MATCH_NOMATCH) |
1706 | 1.89k | RRETURN(rrc); |
1707 | 59.6k | if (Lmin++ >= Lmax) |
1708 | 3.01k | RRETURN(MATCH_NOMATCH); |
1709 | 56.5k | if (Feptr >= mb->end_subject) |
1710 | 3.02k | { |
1711 | 3.02k | SCHECK_PARTIAL(); |
1712 | 3.00k | RRETURN(MATCH_NOMATCH); |
1713 | 3.00k | } |
1714 | | |
1715 | 53.5k | if (Lc != *Feptr++) |
1716 | 40.9k | RRETURN(MATCH_NOMATCH); |
1717 | 53.5k | } |
1718 | | |
1719 | 58.3k | PCRE2_UNREACHABLE(); // Control never reaches here |
1720 | 58.3k | } |
1721 | 1.32M | else // Maximize |
1722 | 1.32M | { |
1723 | 1.32M | Lstart_eptr = Feptr; |
1724 | 1.45M | for (i = Lmin; i < Lmax; i++) |
1725 | 1.38M | { |
1726 | 1.38M | if (Feptr >= mb->end_subject) |
1727 | 32.9k | { |
1728 | 32.9k | SCHECK_PARTIAL(); |
1729 | 32.7k | break; |
1730 | 32.9k | } |
1731 | | |
1732 | 1.34M | if (Lc != *Feptr) |
1733 | 1.21M | break; |
1734 | 135k | Feptr++; |
1735 | 135k | } |
1736 | | |
1737 | 1.32M | if (reptype != REPTYPE_POS) |
1738 | 808k | { |
1739 | 808k | for (;;) |
1740 | 865k | { |
1741 | 865k | if (Feptr <= Lstart_eptr) |
1742 | 805k | break; |
1743 | 60.1k | RMATCH(Fecode, RM28); |
1744 | 57.5k | Feptr--; |
1745 | 57.5k | if (rrc != MATCH_NOMATCH) |
1746 | 810 | RRETURN(rrc); |
1747 | 57.5k | } |
1748 | 808k | } |
1749 | 1.32M | } |
1750 | 1.37M | } |
1751 | | |
1752 | 1.53M | break; |
1753 | | |
1754 | 1.53M | #undef Llength |
1755 | 1.53M | #undef Loclength |
1756 | 1.53M | #undef Lstart_eptr |
1757 | 1.53M | #undef Lcharptr |
1758 | 1.53M | #undef Lmin |
1759 | 1.53M | #undef Lmax |
1760 | 1.53M | #undef Lc |
1761 | 1.53M | #undef Loc |
1762 | 1.53M | #undef Loccu |
1763 | | |
1764 | | |
1765 | | /* ===================================================================== */ |
1766 | | /* Match a negated single one-byte character repeatedly. This is almost a |
1767 | | repeat of the code for a repeated single character, but I haven't found a |
1768 | | nice way of commoning these up that doesn't require a test of the |
1769 | | positive/negative option for each character match. Maybe that wouldn't add |
1770 | | very much to the time taken, but character matching *is* what this is all |
1771 | | about... */ |
1772 | | |
1773 | 1.53M | #define Lstart_eptr F->fields.charnot_repeat.start_eptr |
1774 | 4.55M | #define Lmin F->fields.charnot_repeat.min |
1775 | 5.26M | #define Lmax F->fields.charnot_repeat.max |
1776 | 4.00M | #define Lc F->fields.charnot_repeat.c |
1777 | 1.53M | #define Loc F->fields.charnot_repeat.oc |
1778 | | |
1779 | 1.53M | case OP_NOTEXACT: |
1780 | 336k | case OP_NOTEXACTI: |
1781 | 336k | Lmin = Lmax = GET2(Fecode, 1); |
1782 | 336k | Fecode += 1 + IMM2_SIZE; |
1783 | 336k | goto REPEATNOTCHAR; |
1784 | | |
1785 | 36.2k | case OP_NOTUPTO: |
1786 | 39.7k | case OP_NOTUPTOI: |
1787 | 39.7k | Lmin = 0; |
1788 | 39.7k | Lmax = GET2(Fecode, 1); |
1789 | 39.7k | reptype = REPTYPE_MAX; |
1790 | 39.7k | Fecode += 1 + IMM2_SIZE; |
1791 | 39.7k | goto REPEATNOTCHAR; |
1792 | | |
1793 | 6.09k | case OP_NOTMINUPTO: |
1794 | 10.1k | case OP_NOTMINUPTOI: |
1795 | 10.1k | Lmin = 0; |
1796 | 10.1k | Lmax = GET2(Fecode, 1); |
1797 | 10.1k | reptype = REPTYPE_MIN; |
1798 | 10.1k | Fecode += 1 + IMM2_SIZE; |
1799 | 10.1k | goto REPEATNOTCHAR; |
1800 | | |
1801 | 37.7k | case OP_NOTPOSSTAR: |
1802 | 43.0k | case OP_NOTPOSSTARI: |
1803 | 43.0k | reptype = REPTYPE_POS; |
1804 | 43.0k | Lmin = 0; |
1805 | 43.0k | Lmax = UINT32_MAX; |
1806 | 43.0k | Fecode++; |
1807 | 43.0k | goto REPEATNOTCHAR; |
1808 | | |
1809 | 13.2k | case OP_NOTPOSPLUS: |
1810 | 19.8k | case OP_NOTPOSPLUSI: |
1811 | 19.8k | reptype = REPTYPE_POS; |
1812 | 19.8k | Lmin = 1; |
1813 | 19.8k | Lmax = UINT32_MAX; |
1814 | 19.8k | Fecode++; |
1815 | 19.8k | goto REPEATNOTCHAR; |
1816 | | |
1817 | 21.0k | case OP_NOTPOSQUERY: |
1818 | 25.3k | case OP_NOTPOSQUERYI: |
1819 | 25.3k | reptype = REPTYPE_POS; |
1820 | 25.3k | Lmin = 0; |
1821 | 25.3k | Lmax = 1; |
1822 | 25.3k | Fecode++; |
1823 | 25.3k | goto REPEATNOTCHAR; |
1824 | | |
1825 | 308k | case OP_NOTPOSUPTO: |
1826 | 343k | case OP_NOTPOSUPTOI: |
1827 | 343k | reptype = REPTYPE_POS; |
1828 | 343k | Lmin = 0; |
1829 | 343k | Lmax = GET2(Fecode, 1); |
1830 | 343k | Fecode += 1 + IMM2_SIZE; |
1831 | 343k | goto REPEATNOTCHAR; |
1832 | | |
1833 | 19.5k | case OP_NOTSTAR: |
1834 | 23.9k | case OP_NOTSTARI: |
1835 | 28.4k | case OP_NOTMINSTAR: |
1836 | 34.4k | case OP_NOTMINSTARI: |
1837 | 59.9k | case OP_NOTPLUS: |
1838 | 65.8k | case OP_NOTPLUSI: |
1839 | 72.8k | case OP_NOTMINPLUS: |
1840 | 79.0k | case OP_NOTMINPLUSI: |
1841 | 101k | case OP_NOTQUERY: |
1842 | 126k | case OP_NOTQUERYI: |
1843 | 132k | case OP_NOTMINQUERY: |
1844 | 138k | case OP_NOTMINQUERYI: |
1845 | 138k | fc = *Fecode++ - ((Fop >= OP_NOTSTARI) ? OP_NOTSTARI : OP_NOTSTAR); |
1846 | 138k | Lmin = rep_min[fc]; |
1847 | 138k | Lmax = rep_max[fc]; |
1848 | 138k | reptype = rep_typ[fc]; |
1849 | | |
1850 | | /* Common code for all repeated single-character non-matches. */ |
1851 | | |
1852 | 956k | REPEATNOTCHAR: |
1853 | 956k | GETCHARINCTEST(Lc, Fecode); |
1854 | | |
1855 | | /* The code is duplicated for the caseless and caseful cases, for speed, |
1856 | | since matching characters is likely to be quite common. First, ensure the |
1857 | | minimum number of matches are present. If Lmin = Lmax, we are done. |
1858 | | Otherwise, if minimizing, keep trying the rest of the expression and |
1859 | | advancing one matching character if failing, up to the maximum. |
1860 | | Alternatively, if maximizing, find the maximum number of characters and |
1861 | | work backwards. */ |
1862 | | |
1863 | 956k | if (Fop >= OP_NOTSTARI) // Caseless |
1864 | 151k | { |
1865 | 151k | #ifdef SUPPORT_UNICODE |
1866 | 151k | if ((utf || ucp) && Lc > 127) |
1867 | 19.8k | Loc = UCD_OTHERCASE(Lc); |
1868 | 131k | else |
1869 | 131k | #endif /* SUPPORT_UNICODE */ |
1870 | | |
1871 | 131k | Loc = TABLE_GET(Lc, mb->fcc, Lc); // Other case from table |
1872 | | |
1873 | 151k | #ifdef SUPPORT_UNICODE |
1874 | 151k | if (utf) |
1875 | 30.8k | { |
1876 | 30.8k | uint32_t d; |
1877 | 52.1k | for (i = 1; i <= Lmin; i++) |
1878 | 25.7k | { |
1879 | 25.7k | if (Feptr >= mb->end_subject) |
1880 | 2.46k | { |
1881 | 2.46k | SCHECK_PARTIAL(); |
1882 | 2.45k | RRETURN(MATCH_NOMATCH); |
1883 | 2.45k | } |
1884 | | |
1885 | 23.3k | GETCHARINC(d, Feptr); |
1886 | 23.3k | if (Lc == d || Loc == d) |
1887 | 2.03k | RRETURN(MATCH_NOMATCH); |
1888 | 23.3k | } |
1889 | 30.8k | } |
1890 | 120k | else |
1891 | 120k | #endif /* SUPPORT_UNICODE */ |
1892 | | |
1893 | | /* Not UTF mode */ |
1894 | 120k | { |
1895 | 227k | for (i = 1; i <= Lmin; i++) |
1896 | 112k | { |
1897 | 112k | if (Feptr >= mb->end_subject) |
1898 | 2.51k | { |
1899 | 2.51k | SCHECK_PARTIAL(); |
1900 | 2.50k | RRETURN(MATCH_NOMATCH); |
1901 | 2.50k | } |
1902 | | |
1903 | 109k | if (Lc == *Feptr || Loc == *Feptr) |
1904 | 3.11k | RRETURN(MATCH_NOMATCH); |
1905 | 106k | Feptr++; |
1906 | 106k | } |
1907 | 120k | } |
1908 | | |
1909 | 141k | if (Lmin == Lmax) |
1910 | 35.0k | continue; // Finished for exact count |
1911 | | |
1912 | 106k | if (reptype == REPTYPE_MIN) |
1913 | 19.9k | { |
1914 | 19.9k | #ifdef SUPPORT_UNICODE |
1915 | 19.9k | if (utf) |
1916 | 10.2k | { |
1917 | 10.2k | uint32_t d; |
1918 | 10.2k | for (;;) |
1919 | 36.1k | { |
1920 | 36.1k | RMATCH(Fecode, RM204); |
1921 | 34.8k | if (rrc != MATCH_NOMATCH) |
1922 | 308 | RRETURN(rrc); |
1923 | 34.5k | if (Lmin++ >= Lmax) |
1924 | 2.69k | RRETURN(MATCH_NOMATCH); |
1925 | 31.8k | if (Feptr >= mb->end_subject) |
1926 | 3.12k | { |
1927 | 3.12k | SCHECK_PARTIAL(); |
1928 | 3.11k | RRETURN(MATCH_NOMATCH); |
1929 | 3.11k | } |
1930 | | |
1931 | 28.7k | GETCHARINC(d, Feptr); |
1932 | 28.7k | if (Lc == d || Loc == d) |
1933 | 2.81k | RRETURN(MATCH_NOMATCH); |
1934 | 28.7k | } |
1935 | 10.2k | } |
1936 | 9.77k | else |
1937 | 9.77k | #endif /*SUPPORT_UNICODE */ |
1938 | | |
1939 | | /* Not UTF mode */ |
1940 | 9.77k | { |
1941 | 9.77k | for (;;) |
1942 | 87.8k | { |
1943 | 87.8k | RMATCH(Fecode, RM29); |
1944 | 87.3k | if (rrc != MATCH_NOMATCH) |
1945 | 417 | RRETURN(rrc); |
1946 | 86.9k | if (Lmin++ >= Lmax) |
1947 | 3.60k | RRETURN(MATCH_NOMATCH); |
1948 | 83.3k | if (Feptr >= mb->end_subject) |
1949 | 2.49k | { |
1950 | 2.49k | SCHECK_PARTIAL(); |
1951 | 2.48k | RRETURN(MATCH_NOMATCH); |
1952 | 2.48k | } |
1953 | | |
1954 | 80.8k | if (Lc == *Feptr || Loc == *Feptr) |
1955 | 2.77k | RRETURN(MATCH_NOMATCH); |
1956 | 78.0k | Feptr++; |
1957 | 78.0k | } |
1958 | 9.77k | } |
1959 | | |
1960 | 19.9k | PCRE2_UNREACHABLE(); // Control never reaches here |
1961 | 19.9k | } |
1962 | | |
1963 | | /* Maximize case */ |
1964 | | |
1965 | 86.0k | else |
1966 | 86.0k | { |
1967 | 86.0k | Lstart_eptr = Feptr; |
1968 | | |
1969 | 86.0k | #ifdef SUPPORT_UNICODE |
1970 | 86.0k | if (utf) |
1971 | 13.1k | { |
1972 | 13.1k | uint32_t d; |
1973 | 54.0k | for (i = Lmin; i < Lmax; i++) |
1974 | 50.2k | { |
1975 | 50.2k | int len = 1; |
1976 | 50.2k | if (Feptr >= mb->end_subject) |
1977 | 3.60k | { |
1978 | 3.60k | SCHECK_PARTIAL(); |
1979 | 3.59k | break; |
1980 | 3.60k | } |
1981 | | |
1982 | 46.6k | GETCHARLEN(d, Feptr, len); |
1983 | 46.6k | if (Lc == d || Loc == d) |
1984 | 5.81k | break; |
1985 | 40.8k | Feptr += len; |
1986 | 40.8k | } |
1987 | | |
1988 | | /* After \C in UTF mode, Lstart_eptr might be in the middle of a |
1989 | | Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't |
1990 | | go too far. */ |
1991 | | |
1992 | 13.1k | if (reptype != REPTYPE_POS) |
1993 | 6.55k | { |
1994 | 6.55k | for (;;) |
1995 | 18.9k | { |
1996 | 18.9k | if (Feptr <= Lstart_eptr) |
1997 | 5.82k | break; |
1998 | 13.1k | RMATCH(Fecode, RM205); |
1999 | 12.9k | if (rrc != MATCH_NOMATCH) |
2000 | 556 | RRETURN(rrc); |
2001 | 12.4k | Feptr--; |
2002 | 12.4k | BACKCHAR(Feptr); |
2003 | 12.4k | } |
2004 | 6.55k | } |
2005 | 13.1k | } |
2006 | 72.8k | else |
2007 | 72.8k | #endif /* SUPPORT_UNICODE */ |
2008 | | |
2009 | | /* Not UTF mode */ |
2010 | 72.8k | { |
2011 | 1.10M | for (i = Lmin; i < Lmax; i++) |
2012 | 1.05M | { |
2013 | 1.05M | if (Feptr >= mb->end_subject) |
2014 | 5.67k | { |
2015 | 5.67k | SCHECK_PARTIAL(); |
2016 | 5.65k | break; |
2017 | 5.67k | } |
2018 | | |
2019 | 1.04M | if (Lc == *Feptr || Loc == *Feptr) |
2020 | 10.7k | break; |
2021 | 1.03M | Feptr++; |
2022 | 1.03M | } |
2023 | | |
2024 | 72.8k | if (reptype != REPTYPE_POS) |
2025 | 30.1k | { |
2026 | 30.1k | for (;;) |
2027 | 79.1k | { |
2028 | 79.1k | if (Feptr == Lstart_eptr) |
2029 | 29.2k | break; |
2030 | 49.8k | RMATCH(Fecode, RM30); |
2031 | 49.2k | if (rrc != MATCH_NOMATCH) |
2032 | 374 | RRETURN(rrc); |
2033 | 48.9k | Feptr--; |
2034 | 48.9k | } |
2035 | 30.1k | } |
2036 | 72.8k | } |
2037 | 86.0k | } |
2038 | 106k | } |
2039 | | |
2040 | | /* Caseful comparisons */ |
2041 | | |
2042 | 805k | else |
2043 | 805k | { |
2044 | 805k | #ifdef SUPPORT_UNICODE |
2045 | 805k | if (utf) |
2046 | 266k | { |
2047 | 266k | uint32_t d; |
2048 | 641k | for (i = 1; i <= Lmin; i++) |
2049 | 393k | { |
2050 | 393k | if (Feptr >= mb->end_subject) |
2051 | 5.48k | { |
2052 | 5.48k | SCHECK_PARTIAL(); |
2053 | 5.47k | RRETURN(MATCH_NOMATCH); |
2054 | 5.47k | } |
2055 | | |
2056 | 387k | GETCHARINC(d, Feptr); |
2057 | 387k | if (Lc == d) |
2058 | 13.0k | RRETURN(MATCH_NOMATCH); |
2059 | 387k | } |
2060 | 266k | } |
2061 | 538k | else |
2062 | 538k | #endif |
2063 | | /* Not UTF mode */ |
2064 | 538k | { |
2065 | 1.02M | for (i = 1; i <= Lmin; i++) |
2066 | 514k | { |
2067 | 514k | if (Feptr >= mb->end_subject) |
2068 | 11.1k | { |
2069 | 11.1k | SCHECK_PARTIAL(); |
2070 | 11.1k | RRETURN(MATCH_NOMATCH); |
2071 | 11.1k | } |
2072 | | |
2073 | 502k | if (Lc == *Feptr++) |
2074 | 18.0k | RRETURN(MATCH_NOMATCH); |
2075 | 502k | } |
2076 | 538k | } |
2077 | | |
2078 | 757k | if (Lmin == Lmax) |
2079 | 262k | continue; |
2080 | | |
2081 | 495k | if (reptype == REPTYPE_MIN) |
2082 | 21.4k | { |
2083 | 21.4k | #ifdef SUPPORT_UNICODE |
2084 | 21.4k | if (utf) |
2085 | 9.81k | { |
2086 | 9.81k | uint32_t d; |
2087 | 9.81k | for (;;) |
2088 | 31.5k | { |
2089 | 31.5k | RMATCH(Fecode, RM206); |
2090 | 30.4k | if (rrc != MATCH_NOMATCH) |
2091 | 873 | RRETURN(rrc); |
2092 | 29.5k | if (Lmin++ >= Lmax) |
2093 | 2.68k | RRETURN(MATCH_NOMATCH); |
2094 | 26.8k | if (Feptr >= mb->end_subject) |
2095 | 3.06k | { |
2096 | 3.06k | SCHECK_PARTIAL(); |
2097 | 3.05k | RRETURN(MATCH_NOMATCH); |
2098 | 3.05k | } |
2099 | | |
2100 | 23.8k | GETCHARINC(d, Feptr); |
2101 | 23.8k | if (Lc == d) |
2102 | 2.08k | RRETURN(MATCH_NOMATCH); |
2103 | 23.8k | } |
2104 | 9.81k | } |
2105 | 11.6k | else |
2106 | 11.6k | #endif |
2107 | | /* Not UTF mode */ |
2108 | 11.6k | { |
2109 | 11.6k | for (;;) |
2110 | 47.1k | { |
2111 | 47.1k | RMATCH(Fecode, RM31); |
2112 | 46.1k | if (rrc != MATCH_NOMATCH) |
2113 | 430 | RRETURN(rrc); |
2114 | 45.7k | if (Lmin++ >= Lmax) |
2115 | 5.41k | RRETURN(MATCH_NOMATCH); |
2116 | 40.3k | if (Feptr >= mb->end_subject) |
2117 | 2.60k | { |
2118 | 2.60k | SCHECK_PARTIAL(); |
2119 | 2.59k | RRETURN(MATCH_NOMATCH); |
2120 | 2.59k | } |
2121 | | |
2122 | 37.7k | if (Lc == *Feptr++) |
2123 | 2.28k | RRETURN(MATCH_NOMATCH); |
2124 | 37.7k | } |
2125 | 11.6k | } |
2126 | | |
2127 | 21.4k | PCRE2_UNREACHABLE(); // Control never reaches here |
2128 | 21.4k | } |
2129 | | |
2130 | | /* Maximize case */ |
2131 | | |
2132 | 473k | else |
2133 | 473k | { |
2134 | 473k | Lstart_eptr = Feptr; |
2135 | | |
2136 | 473k | #ifdef SUPPORT_UNICODE |
2137 | 473k | if (utf) |
2138 | 122k | { |
2139 | 122k | uint32_t d; |
2140 | 352k | for (i = Lmin; i < Lmax; i++) |
2141 | 246k | { |
2142 | 246k | int len = 1; |
2143 | 246k | if (Feptr >= mb->end_subject) |
2144 | 5.16k | { |
2145 | 5.16k | SCHECK_PARTIAL(); |
2146 | 5.15k | break; |
2147 | 5.16k | } |
2148 | | |
2149 | 241k | GETCHARLEN(d, Feptr, len); |
2150 | 241k | if (Lc == d) |
2151 | 11.0k | break; |
2152 | 230k | Feptr += len; |
2153 | 230k | } |
2154 | | |
2155 | | /* After \C in UTF mode, Lstart_eptr might be in the middle of a |
2156 | | Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't |
2157 | | go too far. */ |
2158 | | |
2159 | 122k | if (reptype != REPTYPE_POS) |
2160 | 7.79k | { |
2161 | 7.79k | for (;;) |
2162 | 24.3k | { |
2163 | 24.3k | if (Feptr <= Lstart_eptr) |
2164 | 7.37k | break; |
2165 | 17.0k | RMATCH(Fecode, RM207); |
2166 | 16.8k | if (rrc != MATCH_NOMATCH) |
2167 | 254 | RRETURN(rrc); |
2168 | 16.5k | Feptr--; |
2169 | 16.5k | BACKCHAR(Feptr); |
2170 | 16.5k | } |
2171 | 7.79k | } |
2172 | 122k | } |
2173 | 351k | else |
2174 | 351k | #endif |
2175 | | /* Not UTF mode */ |
2176 | 351k | { |
2177 | 1.69M | for (i = Lmin; i < Lmax; i++) |
2178 | 1.45M | { |
2179 | 1.45M | if (Feptr >= mb->end_subject) |
2180 | 29.7k | { |
2181 | 29.7k | SCHECK_PARTIAL(); |
2182 | 29.6k | break; |
2183 | 29.7k | } |
2184 | | |
2185 | 1.42M | if (Lc == *Feptr) |
2186 | 83.5k | break; |
2187 | 1.34M | Feptr++; |
2188 | 1.34M | } |
2189 | | |
2190 | 351k | if (reptype != REPTYPE_POS) |
2191 | 87.9k | { |
2192 | 87.9k | for (;;) |
2193 | 428k | { |
2194 | 428k | if (Feptr == Lstart_eptr) |
2195 | 83.3k | break; |
2196 | 345k | RMATCH(Fecode, RM32); |
2197 | 341k | if (rrc != MATCH_NOMATCH) |
2198 | 1.18k | RRETURN(rrc); |
2199 | 340k | Feptr--; |
2200 | 340k | } |
2201 | 87.9k | } |
2202 | 351k | } |
2203 | 473k | } |
2204 | 495k | } |
2205 | | |
2206 | 553k | break; |
2207 | | |
2208 | 553k | #undef Lstart_eptr |
2209 | 553k | #undef Lmin |
2210 | 553k | #undef Lmax |
2211 | 553k | #undef Lc |
2212 | 553k | #undef Loc |
2213 | | |
2214 | | |
2215 | | /* ===================================================================== */ |
2216 | | /* Match a bit-mapped character class, possibly repeatedly. These opcodes |
2217 | | are used when all the characters in the class have values in the range |
2218 | | 0-255, and either the matching is caseful, or the characters are in the |
2219 | | range 0-127 when UTF processing is enabled. The only difference between |
2220 | | OP_CLASS and OP_NCLASS occurs when a data character outside the range is |
2221 | | encountered. */ |
2222 | | |
2223 | 857k | #define Lbyte_map_address F->fields.class_repeat.byte_map_address |
2224 | 553k | #define Lbyte_map ((const unsigned char *)Lbyte_map_address) |
2225 | 553k | #define Lstart_eptr F->fields.class_repeat.start_eptr |
2226 | 1.39M | #define Lmin F->fields.class_repeat.min |
2227 | 1.04M | #define Lmax F->fields.class_repeat.max |
2228 | | |
2229 | 553k | case OP_NCLASS: |
2230 | 470k | case OP_CLASS: |
2231 | 470k | { |
2232 | 470k | Lbyte_map_address = Fecode + 1; // Save for matching |
2233 | 470k | Fecode += 1 + (32 / sizeof(PCRE2_UCHAR)); // Advance past the item |
2234 | | |
2235 | | /* Look past the end of the item to see if there is repeat information |
2236 | | following. Then obey similar code to character type repeats. */ |
2237 | | |
2238 | 470k | switch (*Fecode) |
2239 | 470k | { |
2240 | 12.3k | case OP_CRSTAR: |
2241 | 17.5k | case OP_CRMINSTAR: |
2242 | 29.4k | case OP_CRPLUS: |
2243 | 35.1k | case OP_CRMINPLUS: |
2244 | 55.4k | case OP_CRQUERY: |
2245 | 68.5k | case OP_CRMINQUERY: |
2246 | 74.2k | case OP_CRPOSSTAR: |
2247 | 80.0k | case OP_CRPOSPLUS: |
2248 | 92.1k | case OP_CRPOSQUERY: |
2249 | 92.1k | fc = *Fecode++ - OP_CRSTAR; |
2250 | 92.1k | Lmin = rep_min[fc]; |
2251 | 92.1k | Lmax = rep_max[fc]; |
2252 | 92.1k | reptype = rep_typ[fc]; |
2253 | 92.1k | break; |
2254 | | |
2255 | 6.91k | case OP_CRRANGE: |
2256 | 29.0k | case OP_CRMINRANGE: |
2257 | 70.7k | case OP_CRPOSRANGE: |
2258 | 70.7k | Lmin = GET2(Fecode, 1); |
2259 | 70.7k | Lmax = GET2(Fecode, 1 + IMM2_SIZE); |
2260 | 70.7k | if (Lmax == 0) |
2261 | 1.85k | Lmax = UINT32_MAX; // Max 0 => infinity |
2262 | 70.7k | reptype = rep_typ[*Fecode - OP_CRSTAR]; |
2263 | 70.7k | Fecode += 1 + 2 * IMM2_SIZE; |
2264 | 70.7k | break; |
2265 | | |
2266 | 307k | default: // No repeat follows |
2267 | 307k | Lmin = Lmax = 1; |
2268 | 307k | break; |
2269 | 470k | } |
2270 | | |
2271 | | /* First, ensure the minimum number of matches are present. */ |
2272 | | |
2273 | 470k | #ifdef SUPPORT_UNICODE |
2274 | 470k | if (utf) |
2275 | 149k | { |
2276 | 173k | for (i = 1; i <= Lmin; i++) |
2277 | 130k | { |
2278 | 130k | if (Feptr >= mb->end_subject) |
2279 | 3.91k | { |
2280 | 3.91k | SCHECK_PARTIAL(); |
2281 | 3.90k | RRETURN(MATCH_NOMATCH); |
2282 | 3.90k | } |
2283 | | |
2284 | 126k | GETCHARINC(fc, Feptr); |
2285 | 126k | if (fc > 255) |
2286 | 73.6k | { |
2287 | 73.6k | if (Fop == OP_CLASS) |
2288 | 71.2k | RRETURN(MATCH_NOMATCH); |
2289 | 73.6k | } |
2290 | 52.8k | else if ((Lbyte_map[fc / 8] & (1u << (fc & 7))) == 0) |
2291 | 32.0k | { |
2292 | 32.0k | RRETURN(MATCH_NOMATCH); |
2293 | 32.0k | } |
2294 | 126k | } |
2295 | 149k | } |
2296 | 320k | else |
2297 | 320k | #endif |
2298 | | /* Not UTF mode */ |
2299 | 320k | { |
2300 | 432k | for (i = 1; i <= Lmin; i++) |
2301 | 278k | { |
2302 | 278k | if (Feptr >= mb->end_subject) |
2303 | 7.06k | { |
2304 | 7.06k | SCHECK_PARTIAL(); |
2305 | 7.03k | RRETURN(MATCH_NOMATCH); |
2306 | 7.03k | } |
2307 | | |
2308 | 271k | fc = *Feptr++; |
2309 | 271k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
2310 | 271k | if (fc > 255) |
2311 | 117k | { |
2312 | 117k | if (Fop == OP_CLASS) |
2313 | 101k | RRETURN(MATCH_NOMATCH); |
2314 | 117k | } |
2315 | 154k | else |
2316 | 154k | #endif |
2317 | 154k | if ((Lbyte_map[fc / 8] & (1u << (fc & 7))) == 0) |
2318 | 57.7k | RRETURN(MATCH_NOMATCH); |
2319 | 271k | } |
2320 | 320k | } |
2321 | | |
2322 | | /* If Lmax == Lmin we are done. Continue with main loop. */ |
2323 | | |
2324 | 196k | if (Lmin == Lmax) |
2325 | 102k | continue; |
2326 | | |
2327 | | /* If minimizing, keep testing the rest of the expression and advancing |
2328 | | the pointer while it matches the class. */ |
2329 | | |
2330 | 93.9k | if (reptype == REPTYPE_MIN) |
2331 | 25.6k | { |
2332 | 25.6k | #ifdef SUPPORT_UNICODE |
2333 | 25.6k | if (utf) |
2334 | 17.3k | { |
2335 | 17.3k | for (;;) |
2336 | 40.9k | { |
2337 | 40.9k | RMATCH(Fecode, RM200); |
2338 | 40.0k | if (rrc != MATCH_NOMATCH) |
2339 | 606 | RRETURN(rrc); |
2340 | 39.4k | if (Lmin++ >= Lmax) |
2341 | 6.43k | RRETURN(MATCH_NOMATCH); |
2342 | 33.0k | if (Feptr >= mb->end_subject) |
2343 | 2.19k | { |
2344 | 2.19k | SCHECK_PARTIAL(); |
2345 | 2.18k | RRETURN(MATCH_NOMATCH); |
2346 | 2.18k | } |
2347 | | |
2348 | 30.8k | GETCHARINC(fc, Feptr); |
2349 | 30.8k | if (fc > 255) |
2350 | 10.2k | { |
2351 | 10.2k | if (Fop == OP_CLASS) |
2352 | 1.34k | RRETURN(MATCH_NOMATCH); |
2353 | 10.2k | } |
2354 | 20.5k | else if ((Lbyte_map[fc / 8] & (1u << (fc & 7))) == 0) |
2355 | 5.83k | { |
2356 | 5.83k | RRETURN(MATCH_NOMATCH); |
2357 | 5.83k | } |
2358 | 30.8k | } |
2359 | 17.3k | } |
2360 | 8.32k | else |
2361 | 8.32k | #endif |
2362 | | /* Not UTF mode */ |
2363 | 8.32k | { |
2364 | 8.32k | for (;;) |
2365 | 17.3k | { |
2366 | 17.3k | RMATCH(Fecode, RM23); |
2367 | 16.0k | if (rrc != MATCH_NOMATCH) |
2368 | 444 | RRETURN(rrc); |
2369 | 15.6k | if (Lmin++ >= Lmax) |
2370 | 1.47k | RRETURN(MATCH_NOMATCH); |
2371 | 14.1k | if (Feptr >= mb->end_subject) |
2372 | 2.10k | { |
2373 | 2.10k | SCHECK_PARTIAL(); |
2374 | 2.08k | RRETURN(MATCH_NOMATCH); |
2375 | 2.08k | } |
2376 | | |
2377 | 12.0k | fc = *Feptr++; |
2378 | 12.0k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
2379 | 12.0k | if (fc > 255) |
2380 | 2.93k | { |
2381 | 2.93k | if (Fop == OP_CLASS) |
2382 | 500 | RRETURN(MATCH_NOMATCH); |
2383 | 2.93k | } |
2384 | 9.10k | else |
2385 | 9.10k | #endif |
2386 | 9.10k | if ((Lbyte_map[fc / 8] & (1u << (fc & 7))) == 0) |
2387 | 2.55k | RRETURN(MATCH_NOMATCH); |
2388 | 12.0k | } |
2389 | 8.32k | } |
2390 | | |
2391 | 25.6k | PCRE2_UNREACHABLE(); // Control never reaches here |
2392 | 25.6k | } |
2393 | | |
2394 | | /* If maximizing, find the longest possible run, then work backwards. */ |
2395 | | |
2396 | 68.2k | else |
2397 | 68.2k | { |
2398 | 68.2k | Lstart_eptr = Feptr; |
2399 | | |
2400 | 68.2k | #ifdef SUPPORT_UNICODE |
2401 | 68.2k | if (utf) |
2402 | 10.3k | { |
2403 | 34.2k | for (i = Lmin; i < Lmax; i++) |
2404 | 33.3k | { |
2405 | 33.3k | int len = 1; |
2406 | 33.3k | if (Feptr >= mb->end_subject) |
2407 | 3.04k | { |
2408 | 3.04k | SCHECK_PARTIAL(); |
2409 | 3.03k | break; |
2410 | 3.04k | } |
2411 | | |
2412 | 30.3k | GETCHARLEN(fc, Feptr, len); |
2413 | 30.3k | if (fc > 255) |
2414 | 5.84k | { |
2415 | 5.84k | if (Fop == OP_CLASS) |
2416 | 660 | break; |
2417 | 5.84k | } |
2418 | 24.4k | else if ((Lbyte_map[fc / 8] & (1u << (fc & 7))) == 0) |
2419 | 5.75k | { |
2420 | 5.75k | break; |
2421 | 5.75k | } |
2422 | | |
2423 | 23.9k | Feptr += len; |
2424 | 23.9k | } |
2425 | | |
2426 | 10.3k | if (reptype == REPTYPE_POS) |
2427 | 5.44k | continue; // No backtracking |
2428 | | |
2429 | | /* After \C in UTF mode, Lstart_eptr might be in the middle of a |
2430 | | Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't |
2431 | | go too far. */ |
2432 | | |
2433 | 4.89k | for (;;) |
2434 | 13.1k | { |
2435 | 13.1k | RMATCH(Fecode, RM201); |
2436 | 11.8k | if (rrc != MATCH_NOMATCH) |
2437 | 335 | RRETURN(rrc); |
2438 | 11.5k | if (Feptr-- <= Lstart_eptr) |
2439 | 3.26k | break; // Tried at original position |
2440 | 8.26k | BACKCHAR(Feptr); |
2441 | 8.26k | } |
2442 | 4.89k | } |
2443 | 57.8k | else |
2444 | 57.8k | #endif |
2445 | | /* Not UTF mode */ |
2446 | 57.8k | { |
2447 | 214k | for (i = Lmin; i < Lmax; i++) |
2448 | 199k | { |
2449 | 199k | if (Feptr >= mb->end_subject) |
2450 | 10.0k | { |
2451 | 10.0k | SCHECK_PARTIAL(); |
2452 | 9.97k | break; |
2453 | 10.0k | } |
2454 | | |
2455 | 188k | fc = *Feptr; |
2456 | 188k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
2457 | 188k | if (fc > 255) |
2458 | 63.4k | { |
2459 | 63.4k | if (Fop == OP_CLASS) |
2460 | 5.78k | break; |
2461 | 63.4k | } |
2462 | 125k | else |
2463 | 125k | #endif |
2464 | 125k | if ((Lbyte_map[fc / 8] & (1u << (fc & 7))) == 0) |
2465 | 26.5k | break; |
2466 | 156k | Feptr++; |
2467 | 156k | } |
2468 | | |
2469 | 57.7k | if (reptype == REPTYPE_POS) |
2470 | 18.9k | continue; // No backtracking |
2471 | | |
2472 | 177k | while (Feptr >= Lstart_eptr) |
2473 | 146k | { |
2474 | 146k | RMATCH(Fecode, RM24); |
2475 | 140k | if (rrc != MATCH_NOMATCH) |
2476 | 925 | RRETURN(rrc); |
2477 | 139k | Feptr--; |
2478 | 139k | } |
2479 | 38.8k | } |
2480 | | |
2481 | 35.1k | RRETURN(MATCH_NOMATCH); |
2482 | 35.1k | } |
2483 | 93.9k | } |
2484 | | |
2485 | 93.9k | PCRE2_UNREACHABLE(); // Control never reaches here |
2486 | | |
2487 | 0 | #undef Lbyte_map_address |
2488 | 0 | #undef Lbyte_map |
2489 | 0 | #undef Lstart_eptr |
2490 | 0 | #undef Lmin |
2491 | 0 | #undef Lmax |
2492 | | |
2493 | | |
2494 | | /* ===================================================================== */ |
2495 | | /* Match an extended character class. In the 8-bit library, this opcode is |
2496 | | encountered only when UTF-8 mode mode is supported. In the 16-bit and |
2497 | | 32-bit libraries, codepoints greater than 255 may be encountered even when |
2498 | | UTF is not supported. */ |
2499 | | |
2500 | 307k | #define Lstart_eptr F->fields.xclass_repeat.start_eptr |
2501 | 5.00M | #define Lxclass_data F->fields.xclass_repeat.xclass_data |
2502 | 2.18M | #define Lmin F->fields.xclass_repeat.min |
2503 | 4.94M | #define Lmax F->fields.xclass_repeat.max |
2504 | | |
2505 | 0 | #ifdef SUPPORT_WIDE_CHARS |
2506 | 643k | case OP_XCLASS: |
2507 | 643k | { |
2508 | 643k | Lxclass_data = Fecode + 1 + LINK_SIZE; // Save for matching |
2509 | 643k | Fecode += GET(Fecode, 1); // Advance past the item |
2510 | | |
2511 | 643k | switch (*Fecode) |
2512 | 643k | { |
2513 | 11.6k | case OP_CRSTAR: |
2514 | 21.0k | case OP_CRMINSTAR: |
2515 | 34.4k | case OP_CRPLUS: |
2516 | 45.2k | case OP_CRMINPLUS: |
2517 | 68.3k | case OP_CRQUERY: |
2518 | 75.5k | case OP_CRMINQUERY: |
2519 | 128k | case OP_CRPOSSTAR: |
2520 | 153k | case OP_CRPOSPLUS: |
2521 | 159k | case OP_CRPOSQUERY: |
2522 | 159k | fc = *Fecode++ - OP_CRSTAR; |
2523 | 159k | Lmin = rep_min[fc]; |
2524 | 159k | Lmax = rep_max[fc]; |
2525 | 159k | reptype = rep_typ[fc]; |
2526 | 159k | break; |
2527 | | |
2528 | 14.3k | case OP_CRRANGE: |
2529 | 33.0k | case OP_CRMINRANGE: |
2530 | 42.3k | case OP_CRPOSRANGE: |
2531 | 42.3k | Lmin = GET2(Fecode, 1); |
2532 | 42.3k | Lmax = GET2(Fecode, 1 + IMM2_SIZE); |
2533 | 42.3k | if (Lmax == 0) |
2534 | 751 | Lmax = UINT32_MAX; // Max 0 => infinity |
2535 | 42.3k | reptype = rep_typ[*Fecode - OP_CRSTAR]; |
2536 | 42.3k | Fecode += 1 + 2 * IMM2_SIZE; |
2537 | 42.3k | break; |
2538 | | |
2539 | 441k | default: // No repeat follows |
2540 | 441k | Lmin = Lmax = 1; |
2541 | 441k | break; |
2542 | 643k | } |
2543 | | |
2544 | | /* First, ensure the minimum number of matches are present. */ |
2545 | | |
2546 | 927k | for (i = 1; i <= Lmin; i++) |
2547 | 536k | { |
2548 | 536k | if (Feptr >= mb->end_subject) |
2549 | 14.3k | { |
2550 | 14.3k | SCHECK_PARTIAL(); |
2551 | 14.3k | RRETURN(MATCH_NOMATCH); |
2552 | 14.3k | } |
2553 | | |
2554 | 522k | GETCHARINCTEST(fc, Feptr); |
2555 | 522k | if (!PRIV(xclass)(fc, Lxclass_data, (const uint8_t *)mb->start_code, utf)) |
2556 | 238k | RRETURN(MATCH_NOMATCH); |
2557 | 522k | } |
2558 | | |
2559 | | /* If Lmax == Lmin we can just continue with the main loop. */ |
2560 | | |
2561 | 390k | if (Lmin == Lmax) |
2562 | 237k | continue; |
2563 | | |
2564 | | /* If minimizing, keep testing the rest of the expression and advancing |
2565 | | the pointer while it matches the class. */ |
2566 | | |
2567 | 153k | if (reptype == REPTYPE_MIN) |
2568 | 27.4k | { |
2569 | 27.4k | for (;;) |
2570 | 104k | { |
2571 | 104k | RMATCH(Fecode, RM100); |
2572 | 101k | if (rrc != MATCH_NOMATCH) |
2573 | 432 | RRETURN(rrc); |
2574 | 100k | if (Lmin++ >= Lmax) |
2575 | 6.44k | RRETURN(MATCH_NOMATCH); |
2576 | 94.3k | if (Feptr >= mb->end_subject) |
2577 | 3.11k | { |
2578 | 3.11k | SCHECK_PARTIAL(); |
2579 | 3.09k | RRETURN(MATCH_NOMATCH); |
2580 | 3.09k | } |
2581 | | |
2582 | 91.2k | GETCHARINCTEST(fc, Feptr); |
2583 | 91.2k | if (!PRIV(xclass)(fc, Lxclass_data, (const uint8_t *)mb->start_code, utf)) |
2584 | 14.3k | RRETURN(MATCH_NOMATCH); |
2585 | 91.2k | } |
2586 | | |
2587 | 27.4k | PCRE2_UNREACHABLE(); // Control never reaches here |
2588 | 27.4k | } |
2589 | | |
2590 | | /* If maximizing, find the longest possible run, then work backwards. */ |
2591 | | |
2592 | 125k | else |
2593 | 125k | { |
2594 | 125k | Lstart_eptr = Feptr; |
2595 | 3.77M | for (i = Lmin; i < Lmax; i++) |
2596 | 3.75M | { |
2597 | 3.75M | int len = 1; |
2598 | 3.75M | if (Feptr >= mb->end_subject) |
2599 | 10.2k | { |
2600 | 10.2k | SCHECK_PARTIAL(); |
2601 | 10.2k | break; |
2602 | 10.2k | } |
2603 | 3.74M | #ifdef SUPPORT_UNICODE |
2604 | 3.74M | GETCHARLENTEST(fc, Feptr, len); |
2605 | | #else |
2606 | | fc = *Feptr; |
2607 | | #endif |
2608 | 3.74M | if (!PRIV(xclass)(fc, Lxclass_data, (const uint8_t *)mb->start_code, utf)) |
2609 | 100k | break; |
2610 | 3.64M | Feptr += len; |
2611 | 3.64M | } |
2612 | | |
2613 | 125k | if (reptype == REPTYPE_POS) |
2614 | 75.9k | continue; // No backtracking |
2615 | | |
2616 | | /* After \C in UTF mode, Lstart_eptr might be in the middle of a |
2617 | | Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't |
2618 | | go too far. */ |
2619 | | |
2620 | 50.0k | for (;;) |
2621 | 186k | { |
2622 | 186k | RMATCH(Fecode, RM101); |
2623 | 181k | if (rrc != MATCH_NOMATCH) |
2624 | 594 | RRETURN(rrc); |
2625 | 181k | if (Feptr-- <= Lstart_eptr) |
2626 | 44.0k | break; // Tried at original position |
2627 | 136k | #ifdef SUPPORT_UNICODE |
2628 | 136k | if (utf) |
2629 | 14.1k | BACKCHAR(Feptr); |
2630 | 136k | #endif |
2631 | 136k | } |
2632 | | |
2633 | 44.0k | RRETURN(MATCH_NOMATCH); |
2634 | 44.0k | } |
2635 | | |
2636 | 153k | PCRE2_UNREACHABLE(); // Control never reaches here |
2637 | 153k | } |
2638 | 0 | #endif /* SUPPORT_WIDE_CHARS: end of XCLASS */ |
2639 | | |
2640 | 0 | #undef Lstart_eptr |
2641 | 0 | #undef Lxclass_data |
2642 | 0 | #undef Lmin |
2643 | 0 | #undef Lmax |
2644 | | |
2645 | | |
2646 | | /* ===================================================================== */ |
2647 | | /* Match a complex, set-based character class. This opcodes are used when |
2648 | | there is complex nesting or logical operations within the character |
2649 | | class. */ |
2650 | | |
2651 | 28.9k | #define Lstart_eptr F->fields.eclass_repeat.start_eptr |
2652 | 347k | #define Leclass_data F->fields.eclass_repeat.eclass_data |
2653 | 173k | #define Leclass_len F->fields.eclass_repeat.eclass_len |
2654 | 250k | #define Lmin F->fields.eclass_repeat.min |
2655 | 167k | #define Lmax F->fields.eclass_repeat.max |
2656 | | |
2657 | 0 | #ifdef SUPPORT_WIDE_CHARS |
2658 | 71.7k | case OP_ECLASS: |
2659 | 71.7k | { |
2660 | 71.7k | Leclass_data = Fecode + 1 + LINK_SIZE; // Save for matching |
2661 | 71.7k | Fecode += GET(Fecode, 1); // Advance past the item |
2662 | 71.7k | Leclass_len = (PCRE2_SIZE)(Fecode - Leclass_data); |
2663 | | |
2664 | 71.7k | switch (*Fecode) |
2665 | 71.7k | { |
2666 | 1.52k | case OP_CRSTAR: |
2667 | 2.99k | case OP_CRMINSTAR: |
2668 | 4.35k | case OP_CRPLUS: |
2669 | 5.28k | case OP_CRMINPLUS: |
2670 | 9.47k | case OP_CRQUERY: |
2671 | 14.2k | case OP_CRMINQUERY: |
2672 | 15.2k | case OP_CRPOSSTAR: |
2673 | 19.0k | case OP_CRPOSPLUS: |
2674 | 19.8k | case OP_CRPOSQUERY: |
2675 | 19.8k | fc = *Fecode++ - OP_CRSTAR; |
2676 | 19.8k | Lmin = rep_min[fc]; |
2677 | 19.8k | Lmax = rep_max[fc]; |
2678 | 19.8k | reptype = rep_typ[fc]; |
2679 | 19.8k | break; |
2680 | | |
2681 | 359 | case OP_CRRANGE: |
2682 | 724 | case OP_CRMINRANGE: |
2683 | 973 | case OP_CRPOSRANGE: |
2684 | 973 | Lmin = GET2(Fecode, 1); |
2685 | 973 | Lmax = GET2(Fecode, 1 + IMM2_SIZE); |
2686 | 973 | if (Lmax == 0) |
2687 | 392 | Lmax = UINT32_MAX; // Max 0 => infinity |
2688 | 973 | reptype = rep_typ[*Fecode - OP_CRSTAR]; |
2689 | 973 | Fecode += 1 + 2 * IMM2_SIZE; |
2690 | 973 | break; |
2691 | | |
2692 | 50.9k | default: // No repeat follows |
2693 | 50.9k | Lmin = Lmax = 1; |
2694 | 50.9k | break; |
2695 | 71.7k | } |
2696 | | |
2697 | | /* First, ensure the minimum number of matches are present. */ |
2698 | | |
2699 | 102k | for (i = 1; i <= Lmin; i++) |
2700 | 59.3k | { |
2701 | 59.3k | if (Feptr >= mb->end_subject) |
2702 | 2.04k | { |
2703 | 2.04k | SCHECK_PARTIAL(); |
2704 | 2.03k | RRETURN(MATCH_NOMATCH); |
2705 | 2.03k | } |
2706 | | |
2707 | 57.3k | GETCHARINCTEST(fc, Feptr); |
2708 | 57.3k | if (!PRIV(eclass)(fc, Leclass_data, Leclass_data + Leclass_len, |
2709 | 57.3k | (const uint8_t *)mb->start_code, utf)) |
2710 | 26.4k | RRETURN(MATCH_NOMATCH); |
2711 | 57.3k | } |
2712 | | |
2713 | | /* If Lmax == Lmin we can just continue with the main loop. */ |
2714 | | |
2715 | 43.2k | if (Lmin == Lmax) |
2716 | 26.2k | continue; |
2717 | | |
2718 | | /* If minimizing, keep testing the rest of the expression and advancing |
2719 | | the pointer while it matches the class. */ |
2720 | | |
2721 | 16.9k | if (reptype == REPTYPE_MIN) |
2722 | 6.82k | { |
2723 | 6.82k | for (;;) |
2724 | 22.8k | { |
2725 | 22.8k | RMATCH(Fecode, RM102); |
2726 | 22.7k | if (rrc != MATCH_NOMATCH) |
2727 | 238 | RRETURN(rrc); |
2728 | 22.4k | if (Lmin++ >= Lmax) |
2729 | 1.80k | RRETURN(MATCH_NOMATCH); |
2730 | 20.6k | if (Feptr >= mb->end_subject) |
2731 | 1.45k | { |
2732 | 1.45k | SCHECK_PARTIAL(); |
2733 | 1.45k | RRETURN(MATCH_NOMATCH); |
2734 | 1.45k | } |
2735 | | |
2736 | 19.2k | GETCHARINCTEST(fc, Feptr); |
2737 | 19.2k | if (!PRIV(eclass)(fc, Leclass_data, Leclass_data + Leclass_len, |
2738 | 19.2k | (const uint8_t *)mb->start_code, utf)) |
2739 | 3.18k | RRETURN(MATCH_NOMATCH); |
2740 | 19.2k | } |
2741 | | |
2742 | 6.82k | PCRE2_UNREACHABLE(); // Control never reaches here |
2743 | 6.82k | } |
2744 | | |
2745 | | /* If maximizing, find the longest possible run, then work backwards. */ |
2746 | | |
2747 | 10.1k | else |
2748 | 10.1k | { |
2749 | 10.1k | Lstart_eptr = Feptr; |
2750 | 29.1k | for (i = Lmin; i < Lmax; i++) |
2751 | 27.5k | { |
2752 | 27.5k | int len = 1; |
2753 | 27.5k | if (Feptr >= mb->end_subject) |
2754 | 2.24k | { |
2755 | 2.24k | SCHECK_PARTIAL(); |
2756 | 2.23k | break; |
2757 | 2.24k | } |
2758 | 25.2k | #ifdef SUPPORT_UNICODE |
2759 | 25.2k | GETCHARLENTEST(fc, Feptr, len); |
2760 | | #else |
2761 | | fc = *Feptr; |
2762 | | #endif |
2763 | 25.2k | if (!PRIV(eclass)(fc, Leclass_data, Leclass_data + Leclass_len, |
2764 | 25.2k | (const uint8_t *)mb->start_code, utf)) |
2765 | 6.33k | break; |
2766 | 18.9k | Feptr += len; |
2767 | 18.9k | } |
2768 | | |
2769 | 10.1k | if (reptype == REPTYPE_POS) |
2770 | 3.35k | continue; // No backtracking |
2771 | | |
2772 | | /* After \C in UTF mode, Lstart_eptr might be in the middle of a |
2773 | | Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't |
2774 | | go too far. */ |
2775 | | |
2776 | 6.79k | for (;;) |
2777 | 19.5k | { |
2778 | 19.5k | RMATCH(Fecode, RM103); |
2779 | 19.3k | if (rrc != MATCH_NOMATCH) |
2780 | 563 | RRETURN(rrc); |
2781 | 18.7k | if (Feptr-- <= Lstart_eptr) |
2782 | 6.04k | break; // Tried at original position |
2783 | 12.7k | #ifdef SUPPORT_UNICODE |
2784 | 12.7k | if (utf) |
2785 | 2.79k | BACKCHAR(Feptr); |
2786 | 12.7k | #endif |
2787 | 12.7k | } |
2788 | | |
2789 | 6.04k | RRETURN(MATCH_NOMATCH); |
2790 | 6.04k | } |
2791 | | |
2792 | 16.9k | PCRE2_UNREACHABLE(); // Control never reaches here |
2793 | 16.9k | } |
2794 | 0 | #endif /* SUPPORT_WIDE_CHARS: end of ECLASS */ |
2795 | | |
2796 | 0 | #undef Lstart_eptr |
2797 | 0 | #undef Leclass_data |
2798 | 0 | #undef Leclass_len |
2799 | 0 | #undef Lmin |
2800 | 0 | #undef Lmax |
2801 | | |
2802 | | |
2803 | | /* ===================================================================== */ |
2804 | | /* Match various character types when PCRE2_UCP is not set. These opcodes |
2805 | | are not generated when PCRE2_UCP is set - instead appropriate property |
2806 | | tests are compiled. */ |
2807 | | |
2808 | 139k | case OP_NOT_DIGIT: |
2809 | 139k | if (Feptr >= mb->end_subject) |
2810 | 5.41k | { |
2811 | 5.41k | SCHECK_PARTIAL(); |
2812 | 5.39k | RRETURN(MATCH_NOMATCH); |
2813 | 5.39k | } |
2814 | | |
2815 | 134k | GETCHARINCTEST(fc, Feptr); |
2816 | 134k | if (CHMAX_255(fc) && (mb->ctypes[fc] & ctype_digit) != 0) |
2817 | 3.53k | RRETURN(MATCH_NOMATCH); |
2818 | 130k | Fecode++; |
2819 | 130k | break; |
2820 | | |
2821 | 42.5k | case OP_DIGIT: |
2822 | 42.5k | if (Feptr >= mb->end_subject) |
2823 | 4.82k | { |
2824 | 4.82k | SCHECK_PARTIAL(); |
2825 | 4.81k | RRETURN(MATCH_NOMATCH); |
2826 | 4.81k | } |
2827 | | |
2828 | 37.6k | GETCHARINCTEST(fc, Feptr); |
2829 | 37.6k | if (!CHMAX_255(fc) || (mb->ctypes[fc] & ctype_digit) == 0) |
2830 | 36.2k | RRETURN(MATCH_NOMATCH); |
2831 | 1.41k | Fecode++; |
2832 | 1.41k | break; |
2833 | | |
2834 | 112k | case OP_NOT_WHITESPACE: |
2835 | 112k | if (Feptr >= mb->end_subject) |
2836 | 7.90k | { |
2837 | 7.90k | SCHECK_PARTIAL(); |
2838 | 7.86k | RRETURN(MATCH_NOMATCH); |
2839 | 7.86k | } |
2840 | | |
2841 | 104k | GETCHARINCTEST(fc, Feptr); |
2842 | 104k | if (CHMAX_255(fc) && (mb->ctypes[fc] & ctype_space) != 0) |
2843 | 2.05k | RRETURN(MATCH_NOMATCH); |
2844 | 102k | Fecode++; |
2845 | 102k | break; |
2846 | | |
2847 | 65.1k | case OP_WHITESPACE: |
2848 | 65.1k | if (Feptr >= mb->end_subject) |
2849 | 6.37k | { |
2850 | 6.37k | SCHECK_PARTIAL(); |
2851 | 6.34k | RRETURN(MATCH_NOMATCH); |
2852 | 6.34k | } |
2853 | | |
2854 | 58.7k | GETCHARINCTEST(fc, Feptr); |
2855 | 58.7k | if (!CHMAX_255(fc) || (mb->ctypes[fc] & ctype_space) == 0) |
2856 | 57.0k | RRETURN(MATCH_NOMATCH); |
2857 | 1.69k | Fecode++; |
2858 | 1.69k | break; |
2859 | | |
2860 | 54.6k | case OP_NOT_WORDCHAR: |
2861 | 54.6k | if (Feptr >= mb->end_subject) |
2862 | 6.92k | { |
2863 | 6.92k | SCHECK_PARTIAL(); |
2864 | 6.90k | RRETURN(MATCH_NOMATCH); |
2865 | 6.90k | } |
2866 | | |
2867 | 47.7k | GETCHARINCTEST(fc, Feptr); |
2868 | 47.7k | if (CHMAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0) |
2869 | 8.18k | RRETURN(MATCH_NOMATCH); |
2870 | 39.5k | Fecode++; |
2871 | 39.5k | break; |
2872 | | |
2873 | 44.5k | case OP_WORDCHAR: |
2874 | 44.5k | if (Feptr >= mb->end_subject) |
2875 | 4.10k | { |
2876 | 4.10k | SCHECK_PARTIAL(); |
2877 | 4.08k | RRETURN(MATCH_NOMATCH); |
2878 | 4.08k | } |
2879 | | |
2880 | 40.4k | GETCHARINCTEST(fc, Feptr); |
2881 | 40.4k | if (!CHMAX_255(fc) || (mb->ctypes[fc] & ctype_word) == 0) |
2882 | 33.0k | RRETURN(MATCH_NOMATCH); |
2883 | 7.41k | Fecode++; |
2884 | 7.41k | break; |
2885 | | |
2886 | 126k | case OP_ANYNL: |
2887 | 126k | if (Feptr >= mb->end_subject) |
2888 | 10.7k | { |
2889 | 10.7k | SCHECK_PARTIAL(); |
2890 | 10.7k | RRETURN(MATCH_NOMATCH); |
2891 | 10.7k | } |
2892 | | |
2893 | 115k | GETCHARINCTEST(fc, Feptr); |
2894 | 115k | switch (fc) |
2895 | 115k | { |
2896 | 104k | default: |
2897 | 104k | RRETURN(MATCH_NOMATCH); |
2898 | | |
2899 | 2.60k | case CHAR_CR: |
2900 | 2.60k | if (Feptr >= mb->end_subject) |
2901 | 953 | { |
2902 | 953 | SCHECK_PARTIAL(); |
2903 | 953 | } |
2904 | 1.65k | else if (*Feptr == CHAR_LF) |
2905 | 734 | { |
2906 | 734 | Feptr++; |
2907 | 734 | } |
2908 | | |
2909 | 2.55k | break; |
2910 | | |
2911 | 4.66k | case CHAR_LF: |
2912 | 4.66k | break; |
2913 | | |
2914 | 712 | case CHAR_VT: |
2915 | 1.43k | case CHAR_FF: |
2916 | 1.91k | case CHAR_NEL: |
2917 | 1.91k | #ifndef EBCDIC |
2918 | 3.34k | case 0x2028: |
2919 | 4.05k | case 0x2029: |
2920 | 4.05k | #endif /* Not EBCDIC */ |
2921 | 4.05k | if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) |
2922 | 0 | RRETURN(MATCH_NOMATCH); |
2923 | 4.05k | break; |
2924 | 115k | } |
2925 | | |
2926 | 11.2k | Fecode++; |
2927 | 11.2k | break; |
2928 | | |
2929 | 263k | case OP_NOT_HSPACE: |
2930 | 263k | if (Feptr >= mb->end_subject) |
2931 | 10.8k | { |
2932 | 10.8k | SCHECK_PARTIAL(); |
2933 | 10.8k | RRETURN(MATCH_NOMATCH); |
2934 | 10.8k | } |
2935 | | |
2936 | 253k | GETCHARINCTEST(fc, Feptr); |
2937 | 253k | switch (fc) |
2938 | 253k | { |
2939 | 167k | HSPACE_CASES: |
2940 | 167k | RRETURN(MATCH_NOMATCH); // Byte and multibyte cases |
2941 | 236k | default: |
2942 | 236k | break; |
2943 | 253k | } |
2944 | | |
2945 | 236k | Fecode++; |
2946 | 236k | break; |
2947 | | |
2948 | 126k | case OP_HSPACE: |
2949 | 126k | if (Feptr >= mb->end_subject) |
2950 | 14.5k | { |
2951 | 14.5k | SCHECK_PARTIAL(); |
2952 | 14.4k | RRETURN(MATCH_NOMATCH); |
2953 | 14.4k | } |
2954 | | |
2955 | 111k | GETCHARINCTEST(fc, Feptr); |
2956 | 111k | switch (fc) |
2957 | 111k | { |
2958 | 20.3k | HSPACE_CASES: |
2959 | 20.3k | break; // Byte and multibyte cases |
2960 | 91.5k | default: |
2961 | 91.5k | RRETURN(MATCH_NOMATCH); |
2962 | 111k | } |
2963 | | |
2964 | 20.3k | Fecode++; |
2965 | 20.3k | break; |
2966 | | |
2967 | 51.1k | case OP_NOT_VSPACE: |
2968 | 51.1k | if (Feptr >= mb->end_subject) |
2969 | 4.49k | { |
2970 | 4.49k | SCHECK_PARTIAL(); |
2971 | 4.46k | RRETURN(MATCH_NOMATCH); |
2972 | 4.46k | } |
2973 | | |
2974 | 46.6k | GETCHARINCTEST(fc, Feptr); |
2975 | 46.6k | switch (fc) |
2976 | 46.6k | { |
2977 | 19.6k | VSPACE_CASES: |
2978 | 19.6k | RRETURN(MATCH_NOMATCH); |
2979 | 41.9k | default: |
2980 | 41.9k | break; |
2981 | 46.6k | } |
2982 | | |
2983 | 41.9k | Fecode++; |
2984 | 41.9k | break; |
2985 | | |
2986 | 110k | case OP_VSPACE: |
2987 | 110k | if (Feptr >= mb->end_subject) |
2988 | 7.84k | { |
2989 | 7.84k | SCHECK_PARTIAL(); |
2990 | 7.82k | RRETURN(MATCH_NOMATCH); |
2991 | 7.82k | } |
2992 | | |
2993 | 102k | GETCHARINCTEST(fc, Feptr); |
2994 | 102k | switch (fc) |
2995 | 102k | { |
2996 | 7.97k | VSPACE_CASES: |
2997 | 7.97k | break; |
2998 | 94.8k | default: |
2999 | 94.8k | RRETURN(MATCH_NOMATCH); |
3000 | 102k | } |
3001 | | |
3002 | 7.97k | Fecode++; |
3003 | 7.97k | break; |
3004 | | |
3005 | | |
3006 | 0 | #ifdef SUPPORT_UNICODE |
3007 | | |
3008 | | /* ===================================================================== */ |
3009 | | /* Check the next character by Unicode property. We will get here only |
3010 | | if the support is in the binary; otherwise a compile-time error occurs. */ |
3011 | | |
3012 | 222k | case OP_PROP: |
3013 | 433k | case OP_NOTPROP: |
3014 | 433k | if (Feptr >= mb->end_subject) |
3015 | 21.6k | { |
3016 | 21.6k | SCHECK_PARTIAL(); |
3017 | 21.5k | RRETURN(MATCH_NOMATCH); |
3018 | 21.5k | } |
3019 | | |
3020 | 411k | GETCHARINCTEST(fc, Feptr); |
3021 | 411k | { |
3022 | 411k | const uint32_t *cp; |
3023 | 411k | uint32_t chartype; |
3024 | 411k | const ucd_record *prop = GET_UCD(fc); |
3025 | 411k | BOOL notmatch = Fop == OP_NOTPROP; |
3026 | | |
3027 | 411k | switch (Fecode[1]) |
3028 | 411k | { |
3029 | 4.09k | case PT_LAMP: |
3030 | 4.09k | chartype = prop->chartype; |
3031 | 4.09k | if ((chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt) == notmatch) |
3032 | 1.73k | RRETURN(MATCH_NOMATCH); |
3033 | 2.35k | break; |
3034 | | |
3035 | 16.3k | case PT_GC: |
3036 | 16.3k | if ((Fecode[2] == PRIV(ucp_gentype)[prop->chartype]) == notmatch) |
3037 | 7.79k | RRETURN(MATCH_NOMATCH); |
3038 | 8.55k | break; |
3039 | | |
3040 | 33.0k | case PT_PC: |
3041 | 33.0k | if ((Fecode[2] == prop->chartype) == notmatch) |
3042 | 17.8k | RRETURN(MATCH_NOMATCH); |
3043 | 15.1k | break; |
3044 | | |
3045 | 15.1k | case PT_SC: |
3046 | 2.52k | if ((Fecode[2] == prop->script) == notmatch) |
3047 | 1.34k | RRETURN(MATCH_NOMATCH); |
3048 | 1.17k | break; |
3049 | | |
3050 | 10.5k | case PT_SCX: |
3051 | 10.5k | { |
3052 | 10.5k | BOOL ok = (Fecode[2] == prop->script || |
3053 | 9.65k | MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Fecode[2]) != 0); |
3054 | 10.5k | if (ok == notmatch) |
3055 | 8.09k | RRETURN(MATCH_NOMATCH); |
3056 | 10.5k | } |
3057 | | |
3058 | 2.41k | break; |
3059 | | |
3060 | | /* These are specials */ |
3061 | | |
3062 | 6.93k | case PT_ALNUM: |
3063 | 6.93k | chartype = prop->chartype; |
3064 | 6.93k | if ((PRIV(ucp_gentype)[chartype] == ucp_L || PRIV(ucp_gentype)[chartype] == ucp_N) == |
3065 | 6.93k | notmatch) |
3066 | 3.37k | RRETURN(MATCH_NOMATCH); |
3067 | 3.55k | break; |
3068 | | |
3069 | | /* Perl space used to exclude VT, but from Perl 5.18 it is included, |
3070 | | which means that Perl space and POSIX space are now identical. PCRE |
3071 | | was changed at release 8.34. */ |
3072 | | |
3073 | 220k | case PT_SPACE: // Perl space |
3074 | 221k | case PT_PXSPACE: // POSIX space |
3075 | 221k | switch (fc) |
3076 | 221k | { |
3077 | 169k | HSPACE_CASES: |
3078 | 169k | VSPACE_CASES: |
3079 | 127k | if (notmatch) |
3080 | 10.7k | RRETURN(MATCH_NOMATCH); |
3081 | 9.32k | break; |
3082 | | |
3083 | 201k | default: |
3084 | 201k | if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == notmatch) |
3085 | 100k | RRETURN(MATCH_NOMATCH); |
3086 | 100k | break; |
3087 | 221k | } |
3088 | | |
3089 | 109k | break; |
3090 | | |
3091 | 109k | case PT_WORD: |
3092 | 29.0k | chartype = prop->chartype; |
3093 | 29.0k | if ((PRIV(ucp_gentype)[chartype] == ucp_L || PRIV(ucp_gentype)[chartype] == ucp_N || |
3094 | 16.7k | chartype == ucp_Mn || chartype == ucp_Pc) == notmatch) |
3095 | 15.5k | RRETURN(MATCH_NOMATCH); |
3096 | 13.4k | break; |
3097 | | |
3098 | 40.8k | case PT_CLIST: |
3099 | | #if PCRE2_CODE_UNIT_WIDTH == 32 |
3100 | | if (fc > MAX_UTF_CODE_POINT) |
3101 | | { |
3102 | | if (notmatch) |
3103 | | break; |
3104 | | ; |
3105 | | RRETURN(MATCH_NOMATCH); |
3106 | | } |
3107 | | #endif |
3108 | 40.8k | cp = PRIV(ucd_caseless_sets) + Fecode[2]; |
3109 | 40.8k | for (;;) |
3110 | 93.7k | { |
3111 | 93.7k | if (fc < *cp) |
3112 | 32.7k | { |
3113 | 32.7k | if (notmatch) |
3114 | 1.61k | { |
3115 | 1.61k | break; |
3116 | 1.61k | } |
3117 | 31.1k | else |
3118 | 31.1k | { |
3119 | 31.1k | RRETURN(MATCH_NOMATCH); |
3120 | 31.1k | } |
3121 | 32.7k | } |
3122 | | |
3123 | 61.0k | if (fc == *cp++) |
3124 | 8.08k | { |
3125 | 8.08k | if (notmatch) |
3126 | 550 | { |
3127 | 550 | RRETURN(MATCH_NOMATCH); |
3128 | 550 | } |
3129 | 7.53k | else |
3130 | 7.53k | { |
3131 | 7.53k | break; |
3132 | 7.53k | } |
3133 | 8.08k | } |
3134 | 61.0k | } |
3135 | | |
3136 | 9.14k | break; |
3137 | | |
3138 | 30.9k | case PT_UCNC: |
3139 | 30.9k | if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT || fc == CHAR_GRAVE_ACCENT || |
3140 | 28.6k | (fc >= 0xa0 && fc <= 0xd7ff) || fc >= 0xe000) == notmatch) |
3141 | 7.58k | RRETURN(MATCH_NOMATCH); |
3142 | 23.3k | break; |
3143 | | |
3144 | 23.3k | case PT_BIDICL: |
3145 | 6.57k | if ((UCD_BIDICLASS_PROP(prop) == Fecode[2]) == notmatch) |
3146 | 2.21k | RRETURN(MATCH_NOMATCH); |
3147 | 4.35k | break; |
3148 | | |
3149 | 9.40k | case PT_BOOL: |
3150 | 9.40k | { |
3151 | 9.40k | BOOL ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Fecode[2]) != 0; |
3152 | 9.40k | if (ok == notmatch) |
3153 | 8.92k | RRETURN(MATCH_NOMATCH); |
3154 | 9.40k | } |
3155 | | |
3156 | 480 | break; |
3157 | | |
3158 | | /* This should never occur */ |
3159 | | |
3160 | | /* LCOV_EXCL_START */ |
3161 | 480 | default: |
3162 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
3163 | 0 | return PCRE2_ERROR_INTERNAL; |
3164 | | /* LCOV_EXCL_STOP */ |
3165 | 411k | } |
3166 | | |
3167 | 194k | Fecode += 3; |
3168 | 194k | } |
3169 | | |
3170 | 0 | break; |
3171 | | |
3172 | | |
3173 | | /* ===================================================================== */ |
3174 | | /* Match an extended Unicode sequence. We will get here only if the support |
3175 | | is in the binary; otherwise a compile-time error occurs. */ |
3176 | | |
3177 | 115k | case OP_EXTUNI: |
3178 | 115k | if (Feptr >= mb->end_subject) |
3179 | 4.70k | { |
3180 | 4.70k | SCHECK_PARTIAL(); |
3181 | 4.69k | RRETURN(MATCH_NOMATCH); |
3182 | 4.69k | } |
3183 | 111k | else |
3184 | 111k | { |
3185 | 111k | GETCHARINCTEST(fc, Feptr); |
3186 | 111k | Feptr = PRIV(extuni)(fc, Feptr, mb->check_subject, mb->end_subject, utf, NULL); |
3187 | 111k | } |
3188 | | |
3189 | 111k | CHECK_PARTIAL(); |
3190 | 111k | Fecode++; |
3191 | 111k | break; |
3192 | | |
3193 | 0 | #endif /* SUPPORT_UNICODE */ |
3194 | | |
3195 | | |
3196 | | /* ===================================================================== */ |
3197 | | /* Match a single character type repeatedly. Note that the property type |
3198 | | does not need to be in a stack frame as it is not used within an RMATCH() |
3199 | | loop. */ |
3200 | | |
3201 | 6.88M | #define Lstart_eptr F->fields.type_repeat.start_eptr |
3202 | 14.2M | #define Lmin F->fields.type_repeat.min |
3203 | 12.3M | #define Lmax F->fields.type_repeat.max |
3204 | 18.3M | #define Lctype F->fields.type_repeat.ctype |
3205 | 1.44M | #define Lpropvalue F->fields.type_repeat.propvalue |
3206 | | |
3207 | 402k | case OP_TYPEEXACT: |
3208 | 402k | Lmin = Lmax = GET2(Fecode, 1); |
3209 | 402k | Fecode += 1 + IMM2_SIZE; |
3210 | 402k | goto REPEATTYPE; |
3211 | | |
3212 | 72.0k | case OP_TYPEUPTO: |
3213 | 90.5k | case OP_TYPEMINUPTO: |
3214 | 90.5k | Lmin = 0; |
3215 | 90.5k | Lmax = GET2(Fecode, 1); |
3216 | 90.5k | reptype = (*Fecode == OP_TYPEMINUPTO) ? REPTYPE_MIN : REPTYPE_MAX; |
3217 | 90.5k | Fecode += 1 + IMM2_SIZE; |
3218 | 90.5k | goto REPEATTYPE; |
3219 | | |
3220 | 161k | case OP_TYPEPOSSTAR: |
3221 | 161k | reptype = REPTYPE_POS; |
3222 | 161k | Lmin = 0; |
3223 | 161k | Lmax = UINT32_MAX; |
3224 | 161k | Fecode++; |
3225 | 161k | goto REPEATTYPE; |
3226 | | |
3227 | 399k | case OP_TYPEPOSPLUS: |
3228 | 399k | reptype = REPTYPE_POS; |
3229 | 399k | Lmin = 1; |
3230 | 399k | Lmax = UINT32_MAX; |
3231 | 399k | Fecode++; |
3232 | 399k | goto REPEATTYPE; |
3233 | | |
3234 | 350k | case OP_TYPEPOSQUERY: |
3235 | 350k | reptype = REPTYPE_POS; |
3236 | 350k | Lmin = 0; |
3237 | 350k | Lmax = 1; |
3238 | 350k | Fecode++; |
3239 | 350k | goto REPEATTYPE; |
3240 | | |
3241 | 132k | case OP_TYPEPOSUPTO: |
3242 | 132k | reptype = REPTYPE_POS; |
3243 | 132k | Lmin = 0; |
3244 | 132k | Lmax = GET2(Fecode, 1); |
3245 | 132k | Fecode += 1 + IMM2_SIZE; |
3246 | 132k | goto REPEATTYPE; |
3247 | | |
3248 | 239k | case OP_TYPESTAR: |
3249 | 377k | case OP_TYPEMINSTAR: |
3250 | 788k | case OP_TYPEPLUS: |
3251 | 984k | case OP_TYPEMINPLUS: |
3252 | 1.31M | case OP_TYPEQUERY: |
3253 | 1.46M | case OP_TYPEMINQUERY: |
3254 | 1.46M | fc = *Fecode++ - OP_TYPESTAR; |
3255 | 1.46M | Lmin = rep_min[fc]; |
3256 | 1.46M | Lmax = rep_max[fc]; |
3257 | 1.46M | reptype = rep_typ[fc]; |
3258 | | |
3259 | | /* Common code for all repeated character type matches. */ |
3260 | | |
3261 | 3.00M | REPEATTYPE: |
3262 | 3.00M | Lctype = *Fecode++; // Code for the character type |
3263 | | |
3264 | 3.00M | #ifdef SUPPORT_UNICODE |
3265 | 3.00M | if (Lctype == OP_PROP || Lctype == OP_NOTPROP) |
3266 | 790k | { |
3267 | 790k | proptype = *Fecode++; |
3268 | 790k | Lpropvalue = *Fecode++; |
3269 | 790k | } |
3270 | 2.21M | else |
3271 | 2.21M | { |
3272 | 2.21M | proptype = -1; |
3273 | 2.21M | } |
3274 | 3.00M | #endif |
3275 | | |
3276 | | /* First, ensure the minimum number of matches are present. Use inline |
3277 | | code for maximizing the speed, and do the type test once at the start |
3278 | | (i.e. keep it out of the loops). As there are no calls to RMATCH in the |
3279 | | loops, we can use an ordinary variable for "notmatch". The code for UTF |
3280 | | mode is separated out for tidiness, except for Unicode property tests. */ |
3281 | | |
3282 | 3.00M | if (Lmin > 0) |
3283 | 1.40M | { |
3284 | 1.40M | #ifdef SUPPORT_UNICODE |
3285 | 1.40M | if (proptype >= 0) // Property tests in all modes |
3286 | 397k | { |
3287 | 397k | BOOL notmatch = Lctype == OP_NOTPROP; |
3288 | 397k | switch (proptype) |
3289 | 397k | { |
3290 | 19.3k | case PT_LAMP: |
3291 | 33.7k | for (i = 1; i <= Lmin; i++) |
3292 | 24.3k | { |
3293 | 24.3k | int chartype; |
3294 | 24.3k | if (Feptr >= mb->end_subject) |
3295 | 2.45k | { |
3296 | 2.45k | SCHECK_PARTIAL(); |
3297 | 2.43k | RRETURN(MATCH_NOMATCH); |
3298 | 2.43k | } |
3299 | | |
3300 | 21.9k | GETCHARINCTEST(fc, Feptr); |
3301 | 21.9k | chartype = UCD_CHARTYPE(fc); |
3302 | 21.9k | if ((chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt) == notmatch) |
3303 | 7.56k | RRETURN(MATCH_NOMATCH); |
3304 | 21.9k | } |
3305 | | |
3306 | 9.35k | break; |
3307 | | |
3308 | 17.7k | case PT_GC: |
3309 | 26.9k | for (i = 1; i <= Lmin; i++) |
3310 | 19.6k | { |
3311 | 19.6k | if (Feptr >= mb->end_subject) |
3312 | 3.51k | { |
3313 | 3.51k | SCHECK_PARTIAL(); |
3314 | 3.50k | RRETURN(MATCH_NOMATCH); |
3315 | 3.50k | } |
3316 | | |
3317 | 16.1k | GETCHARINCTEST(fc, Feptr); |
3318 | 16.1k | if ((UCD_CATEGORY(fc) == Lpropvalue) == notmatch) |
3319 | 6.95k | RRETURN(MATCH_NOMATCH); |
3320 | 16.1k | } |
3321 | | |
3322 | 7.25k | break; |
3323 | | |
3324 | 25.5k | case PT_PC: |
3325 | 48.4k | for (i = 1; i <= Lmin; i++) |
3326 | 31.3k | { |
3327 | 31.3k | if (Feptr >= mb->end_subject) |
3328 | 3.41k | { |
3329 | 3.41k | SCHECK_PARTIAL(); |
3330 | 3.39k | RRETURN(MATCH_NOMATCH); |
3331 | 3.39k | } |
3332 | | |
3333 | 27.9k | GETCHARINCTEST(fc, Feptr); |
3334 | 27.9k | if ((UCD_CHARTYPE(fc) == Lpropvalue) == notmatch) |
3335 | 4.99k | RRETURN(MATCH_NOMATCH); |
3336 | 27.9k | } |
3337 | | |
3338 | 17.1k | break; |
3339 | | |
3340 | 22.6k | case PT_SC: |
3341 | 27.3k | for (i = 1; i <= Lmin; i++) |
3342 | 24.8k | { |
3343 | 24.8k | if (Feptr >= mb->end_subject) |
3344 | 2.29k | { |
3345 | 2.29k | SCHECK_PARTIAL(); |
3346 | 2.28k | RRETURN(MATCH_NOMATCH); |
3347 | 2.28k | } |
3348 | | |
3349 | 22.5k | GETCHARINCTEST(fc, Feptr); |
3350 | 22.5k | if ((UCD_SCRIPT(fc) == Lpropvalue) == notmatch) |
3351 | 17.8k | RRETURN(MATCH_NOMATCH); |
3352 | 22.5k | } |
3353 | | |
3354 | 2.54k | break; |
3355 | | |
3356 | 8.46k | case PT_SCX: |
3357 | 22.0k | for (i = 1; i <= Lmin; i++) |
3358 | 19.0k | { |
3359 | 19.0k | BOOL ok; |
3360 | 19.0k | const ucd_record *prop; |
3361 | 19.0k | if (Feptr >= mb->end_subject) |
3362 | 1.86k | { |
3363 | 1.86k | SCHECK_PARTIAL(); |
3364 | 1.85k | RRETURN(MATCH_NOMATCH); |
3365 | 1.85k | } |
3366 | | |
3367 | 17.1k | GETCHARINCTEST(fc, Feptr); |
3368 | 17.1k | prop = GET_UCD(fc); |
3369 | 17.1k | ok = (prop->script == Lpropvalue || |
3370 | 16.6k | MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0); |
3371 | 17.1k | if (ok == notmatch) |
3372 | 3.60k | RRETURN(MATCH_NOMATCH); |
3373 | 17.1k | } |
3374 | | |
3375 | 2.99k | break; |
3376 | | |
3377 | 26.5k | case PT_ALNUM: |
3378 | 41.6k | for (i = 1; i <= Lmin; i++) |
3379 | 27.6k | { |
3380 | 27.6k | int category; |
3381 | 27.6k | if (Feptr >= mb->end_subject) |
3382 | 3.12k | { |
3383 | 3.12k | SCHECK_PARTIAL(); |
3384 | 3.11k | RRETURN(MATCH_NOMATCH); |
3385 | 3.11k | } |
3386 | | |
3387 | 24.4k | GETCHARINCTEST(fc, Feptr); |
3388 | 24.4k | category = UCD_CATEGORY(fc); |
3389 | 24.4k | if ((category == ucp_L || category == ucp_N) == notmatch) |
3390 | 9.40k | RRETURN(MATCH_NOMATCH); |
3391 | 24.4k | } |
3392 | | |
3393 | 14.0k | break; |
3394 | | |
3395 | | /* Perl space used to exclude VT, but from Perl 5.18 it is included, |
3396 | | which means that Perl space and POSIX space are now identical. PCRE |
3397 | | was changed at release 8.34. */ |
3398 | | |
3399 | 108k | case PT_SPACE: // Perl space |
3400 | 109k | case PT_PXSPACE: // POSIX space |
3401 | 210k | for (i = 1; i <= Lmin; i++) |
3402 | 167k | { |
3403 | 167k | if (Feptr >= mb->end_subject) |
3404 | 10.3k | { |
3405 | 10.3k | SCHECK_PARTIAL(); |
3406 | 10.3k | RRETURN(MATCH_NOMATCH); |
3407 | 10.3k | } |
3408 | | |
3409 | 157k | GETCHARINCTEST(fc, Feptr); |
3410 | 157k | switch (fc) |
3411 | 157k | { |
3412 | 239k | HSPACE_CASES: |
3413 | 239k | VSPACE_CASES: |
3414 | 170k | if (notmatch) |
3415 | 22.3k | RRETURN(MATCH_NOMATCH); |
3416 | 4.12k | break; |
3417 | | |
3418 | 130k | default: |
3419 | 130k | if ((UCD_CATEGORY(fc) == ucp_Z) == notmatch) |
3420 | 34.2k | RRETURN(MATCH_NOMATCH); |
3421 | 96.7k | break; |
3422 | 157k | } |
3423 | 157k | } |
3424 | | |
3425 | 42.3k | break; |
3426 | | |
3427 | 88.4k | case PT_WORD: |
3428 | 147k | for (i = 1; i <= Lmin; i++) |
3429 | 125k | { |
3430 | 125k | int chartype, category; |
3431 | 125k | if (Feptr >= mb->end_subject) |
3432 | 3.47k | { |
3433 | 3.47k | SCHECK_PARTIAL(); |
3434 | 3.44k | RRETURN(MATCH_NOMATCH); |
3435 | 3.44k | } |
3436 | | |
3437 | 121k | GETCHARINCTEST(fc, Feptr); |
3438 | 121k | chartype = UCD_CHARTYPE(fc); |
3439 | 121k | category = PRIV(ucp_gentype)[chartype]; |
3440 | 121k | if ((category == ucp_L || category == ucp_N || chartype == ucp_Mn || |
3441 | 58.0k | chartype == ucp_Pc) == notmatch) |
3442 | 62.5k | RRETURN(MATCH_NOMATCH); |
3443 | 121k | } |
3444 | | |
3445 | 22.4k | break; |
3446 | | |
3447 | 22.4k | case PT_CLIST: |
3448 | 23.8k | for (i = 1; i <= Lmin; i++) |
3449 | 19.1k | { |
3450 | 19.1k | const uint32_t *cp; |
3451 | 19.1k | if (Feptr >= mb->end_subject) |
3452 | 3.20k | { |
3453 | 3.20k | SCHECK_PARTIAL(); |
3454 | 3.20k | RRETURN(MATCH_NOMATCH); |
3455 | 3.20k | } |
3456 | | |
3457 | 15.9k | GETCHARINCTEST(fc, Feptr); |
3458 | | #if PCRE2_CODE_UNIT_WIDTH == 32 |
3459 | | if (fc > MAX_UTF_CODE_POINT) |
3460 | | { |
3461 | | if (notmatch) |
3462 | | continue; |
3463 | | RRETURN(MATCH_NOMATCH); |
3464 | | } |
3465 | | #endif |
3466 | 15.9k | cp = PRIV(ucd_caseless_sets) + Lpropvalue; |
3467 | 15.9k | for (;;) |
3468 | 36.8k | { |
3469 | 36.8k | if (fc < *cp) |
3470 | 13.3k | { |
3471 | 13.3k | if (notmatch) |
3472 | 5.49k | break; |
3473 | 7.86k | RRETURN(MATCH_NOMATCH); |
3474 | 7.86k | } |
3475 | | |
3476 | 23.4k | if (fc == *cp++) |
3477 | 2.59k | { |
3478 | 2.59k | if (notmatch) |
3479 | 1.12k | RRETURN(MATCH_NOMATCH); |
3480 | 1.47k | break; |
3481 | 2.59k | } |
3482 | 23.4k | } |
3483 | 15.9k | } |
3484 | | |
3485 | 4.67k | break; |
3486 | | |
3487 | 33.2k | case PT_UCNC: |
3488 | 71.1k | for (i = 1; i <= Lmin; i++) |
3489 | 53.1k | { |
3490 | 53.1k | if (Feptr >= mb->end_subject) |
3491 | 2.75k | { |
3492 | 2.75k | SCHECK_PARTIAL(); |
3493 | 2.74k | RRETURN(MATCH_NOMATCH); |
3494 | 2.74k | } |
3495 | | |
3496 | 50.3k | GETCHARINCTEST(fc, Feptr); |
3497 | 50.3k | if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT || fc == CHAR_GRAVE_ACCENT || |
3498 | 47.7k | (fc >= 0xa0 && fc <= 0xd7ff) || fc >= 0xe000) == notmatch) |
3499 | 12.5k | RRETURN(MATCH_NOMATCH); |
3500 | 50.3k | } |
3501 | | |
3502 | 17.9k | break; |
3503 | | |
3504 | 21.0k | case PT_BIDICL: |
3505 | 30.4k | for (i = 1; i <= Lmin; i++) |
3506 | 22.1k | { |
3507 | 22.1k | if (Feptr >= mb->end_subject) |
3508 | 2.43k | { |
3509 | 2.43k | SCHECK_PARTIAL(); |
3510 | 2.42k | RRETURN(MATCH_NOMATCH); |
3511 | 2.42k | } |
3512 | | |
3513 | 19.7k | GETCHARINCTEST(fc, Feptr); |
3514 | 19.7k | if ((UCD_BIDICLASS(fc) == Lpropvalue) == notmatch) |
3515 | 10.2k | RRETURN(MATCH_NOMATCH); |
3516 | 19.7k | } |
3517 | | |
3518 | 8.32k | break; |
3519 | | |
3520 | 8.36k | case PT_BOOL: |
3521 | 27.0k | for (i = 1; i <= Lmin; i++) |
3522 | 22.8k | { |
3523 | 22.8k | BOOL ok; |
3524 | 22.8k | const ucd_record *prop; |
3525 | 22.8k | if (Feptr >= mb->end_subject) |
3526 | 2.88k | { |
3527 | 2.88k | SCHECK_PARTIAL(); |
3528 | 2.86k | RRETURN(MATCH_NOMATCH); |
3529 | 2.86k | } |
3530 | | |
3531 | 19.9k | GETCHARINCTEST(fc, Feptr); |
3532 | 19.9k | prop = GET_UCD(fc); |
3533 | 19.9k | ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Lpropvalue) != 0; |
3534 | 19.9k | if (ok == notmatch) |
3535 | 1.35k | RRETURN(MATCH_NOMATCH); |
3536 | 19.9k | } |
3537 | | |
3538 | 4.13k | break; |
3539 | | |
3540 | | /* This should not occur */ |
3541 | | |
3542 | | /* LCOV_EXCL_START */ |
3543 | 4.13k | default: |
3544 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
3545 | 0 | return PCRE2_ERROR_INTERNAL; |
3546 | | /* LCOV_EXCL_STOP */ |
3547 | 397k | } |
3548 | 397k | } |
3549 | | |
3550 | | /* Match extended Unicode sequences. We will get here only if the |
3551 | | support is in the binary; otherwise a compile-time error occurs. */ |
3552 | | |
3553 | 1.01M | else if (Lctype == OP_EXTUNI) |
3554 | 45.4k | { |
3555 | 222k | for (i = 1; i <= Lmin; i++) |
3556 | 190k | { |
3557 | 190k | if (Feptr >= mb->end_subject) |
3558 | 13.5k | { |
3559 | 13.5k | SCHECK_PARTIAL(); |
3560 | 13.5k | RRETURN(MATCH_NOMATCH); |
3561 | 13.5k | } |
3562 | 176k | else |
3563 | 176k | { |
3564 | 176k | GETCHARINCTEST(fc, Feptr); |
3565 | 176k | Feptr = PRIV(extuni)(fc, Feptr, mb->check_subject, mb->end_subject, utf, NULL); |
3566 | 176k | } |
3567 | | |
3568 | 176k | CHECK_PARTIAL(); |
3569 | 176k | } |
3570 | 45.4k | } |
3571 | 966k | else |
3572 | 966k | #endif /* SUPPORT_UNICODE */ |
3573 | | |
3574 | | /* Handle all other cases in UTF mode */ |
3575 | | |
3576 | 966k | #ifdef SUPPORT_UNICODE |
3577 | 966k | if (utf) |
3578 | 258k | { |
3579 | 258k | switch (Lctype) |
3580 | 258k | { |
3581 | 30.7k | case OP_ANY: |
3582 | 68.6k | for (i = 1; i <= Lmin; i++) |
3583 | 43.2k | { |
3584 | 43.2k | if (Feptr >= mb->end_subject) |
3585 | 4.80k | { |
3586 | 4.80k | SCHECK_PARTIAL(); |
3587 | 4.79k | RRETURN(MATCH_NOMATCH); |
3588 | 4.79k | } |
3589 | | |
3590 | 38.4k | if (IS_NEWLINE(Feptr)) |
3591 | 574 | RRETURN(MATCH_NOMATCH); |
3592 | 37.8k | if (mb->partial != 0 && Feptr + 1 >= mb->end_subject && |
3593 | 878 | NLBLOCK->nltype == NLTYPE_FIXED && NLBLOCK->nllen == 2 && |
3594 | 0 | *Feptr == NLBLOCK->nl[0]) |
3595 | 0 | { |
3596 | 0 | mb->hitend = TRUE; |
3597 | 0 | if (mb->partial > 1) |
3598 | 0 | return PCRE2_ERROR_PARTIAL; |
3599 | 0 | } |
3600 | | |
3601 | 37.8k | Feptr++; |
3602 | 37.8k | ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); |
3603 | 37.8k | } |
3604 | | |
3605 | 25.4k | break; |
3606 | | |
3607 | 25.4k | case OP_ALLANY: |
3608 | 36.1k | for (i = 1; i <= Lmin; i++) |
3609 | 23.3k | { |
3610 | 23.3k | if (Feptr >= mb->end_subject) |
3611 | 3.78k | { |
3612 | 3.78k | SCHECK_PARTIAL(); |
3613 | 3.77k | RRETURN(MATCH_NOMATCH); |
3614 | 3.77k | } |
3615 | | |
3616 | 19.6k | Feptr++; |
3617 | 19.6k | ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); |
3618 | 19.6k | } |
3619 | | |
3620 | 12.7k | break; |
3621 | | |
3622 | 12.7k | case OP_ANYBYTE: |
3623 | 0 | if (Feptr > mb->end_subject - Lmin) |
3624 | 0 | RRETURN(MATCH_NOMATCH); |
3625 | 0 | Feptr += Lmin; |
3626 | 0 | break; |
3627 | | |
3628 | 34.4k | case OP_ANYNL: |
3629 | 41.1k | for (i = 1; i <= Lmin; i++) |
3630 | 36.0k | { |
3631 | 36.0k | if (Feptr >= mb->end_subject) |
3632 | 5.29k | { |
3633 | 5.29k | SCHECK_PARTIAL(); |
3634 | 5.28k | RRETURN(MATCH_NOMATCH); |
3635 | 5.28k | } |
3636 | | |
3637 | 30.7k | GETCHARINC(fc, Feptr); |
3638 | 30.7k | switch (fc) |
3639 | 30.7k | { |
3640 | 24.1k | default: |
3641 | 24.1k | RRETURN(MATCH_NOMATCH); |
3642 | | |
3643 | 2.70k | case CHAR_CR: |
3644 | 2.70k | if (Feptr < mb->end_subject && *Feptr == CHAR_LF) |
3645 | 658 | Feptr++; |
3646 | 2.70k | break; |
3647 | | |
3648 | 1.55k | case CHAR_LF: |
3649 | 1.55k | break; |
3650 | | |
3651 | 357 | case CHAR_VT: |
3652 | 967 | case CHAR_FF: |
3653 | 1.53k | case CHAR_NEL: |
3654 | 1.53k | #ifndef EBCDIC |
3655 | 2.08k | case 0x2028: |
3656 | 2.34k | case 0x2029: |
3657 | 2.34k | #endif /* Not EBCDIC */ |
3658 | 2.34k | if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) |
3659 | 0 | RRETURN(MATCH_NOMATCH); |
3660 | 2.34k | break; |
3661 | 30.7k | } |
3662 | 30.7k | } |
3663 | | |
3664 | 5.10k | break; |
3665 | | |
3666 | 47.5k | case OP_NOT_HSPACE: |
3667 | 115k | for (i = 1; i <= Lmin; i++) |
3668 | 84.4k | { |
3669 | 84.4k | if (Feptr >= mb->end_subject) |
3670 | 6.05k | { |
3671 | 6.05k | SCHECK_PARTIAL(); |
3672 | 6.02k | RRETURN(MATCH_NOMATCH); |
3673 | 6.02k | } |
3674 | | |
3675 | 78.4k | GETCHARINC(fc, Feptr); |
3676 | 78.4k | switch (fc) |
3677 | 78.4k | { |
3678 | 113k | HSPACE_CASES: |
3679 | 113k | RRETURN(MATCH_NOMATCH); |
3680 | 67.7k | default: |
3681 | 67.7k | break; |
3682 | 78.4k | } |
3683 | 78.4k | } |
3684 | | |
3685 | 30.8k | break; |
3686 | | |
3687 | 34.5k | case OP_HSPACE: |
3688 | 40.9k | for (i = 1; i <= Lmin; i++) |
3689 | 35.9k | { |
3690 | 35.9k | if (Feptr >= mb->end_subject) |
3691 | 4.40k | { |
3692 | 4.40k | SCHECK_PARTIAL(); |
3693 | 4.35k | RRETURN(MATCH_NOMATCH); |
3694 | 4.35k | } |
3695 | | |
3696 | 31.5k | GETCHARINC(fc, Feptr); |
3697 | 31.5k | switch (fc) |
3698 | 31.5k | { |
3699 | 6.40k | HSPACE_CASES: |
3700 | 6.40k | break; |
3701 | 25.1k | default: |
3702 | 25.1k | RRETURN(MATCH_NOMATCH); |
3703 | 31.5k | } |
3704 | 31.5k | } |
3705 | | |
3706 | 4.95k | break; |
3707 | | |
3708 | 22.7k | case OP_NOT_VSPACE: |
3709 | 227k | for (i = 1; i <= Lmin; i++) |
3710 | 215k | { |
3711 | 215k | if (Feptr >= mb->end_subject) |
3712 | 5.15k | { |
3713 | 5.15k | SCHECK_PARTIAL(); |
3714 | 5.14k | RRETURN(MATCH_NOMATCH); |
3715 | 5.14k | } |
3716 | | |
3717 | 210k | GETCHARINC(fc, Feptr); |
3718 | 210k | switch (fc) |
3719 | 210k | { |
3720 | 18.5k | VSPACE_CASES: |
3721 | 18.5k | RRETURN(MATCH_NOMATCH); |
3722 | 205k | default: |
3723 | 205k | break; |
3724 | 210k | } |
3725 | 210k | } |
3726 | | |
3727 | 12.7k | break; |
3728 | | |
3729 | 13.4k | case OP_VSPACE: |
3730 | 15.8k | for (i = 1; i <= Lmin; i++) |
3731 | 14.2k | { |
3732 | 14.2k | if (Feptr >= mb->end_subject) |
3733 | 3.34k | { |
3734 | 3.34k | SCHECK_PARTIAL(); |
3735 | 3.33k | RRETURN(MATCH_NOMATCH); |
3736 | 3.33k | } |
3737 | | |
3738 | 10.9k | GETCHARINC(fc, Feptr); |
3739 | 10.9k | switch (fc) |
3740 | 10.9k | { |
3741 | 2.38k | VSPACE_CASES: |
3742 | 2.38k | break; |
3743 | 8.56k | default: |
3744 | 8.56k | RRETURN(MATCH_NOMATCH); |
3745 | 10.9k | } |
3746 | 10.9k | } |
3747 | | |
3748 | 1.58k | break; |
3749 | | |
3750 | 12.8k | case OP_NOT_DIGIT: |
3751 | 25.8k | for (i = 1; i <= Lmin; i++) |
3752 | 16.3k | { |
3753 | 16.3k | if (Feptr >= mb->end_subject) |
3754 | 2.08k | { |
3755 | 2.08k | SCHECK_PARTIAL(); |
3756 | 2.08k | RRETURN(MATCH_NOMATCH); |
3757 | 2.08k | } |
3758 | | |
3759 | 14.2k | GETCHARINC(fc, Feptr); |
3760 | 14.2k | if (fc < 128 && (mb->ctypes[fc] & ctype_digit) != 0) |
3761 | 1.20k | RRETURN(MATCH_NOMATCH); |
3762 | 14.2k | } |
3763 | | |
3764 | 9.51k | break; |
3765 | | |
3766 | 9.51k | case OP_DIGIT: |
3767 | 10.0k | for (i = 1; i <= Lmin; i++) |
3768 | 9.66k | { |
3769 | 9.66k | uint32_t cc; |
3770 | 9.66k | if (Feptr >= mb->end_subject) |
3771 | 2.09k | { |
3772 | 2.09k | SCHECK_PARTIAL(); |
3773 | 2.08k | RRETURN(MATCH_NOMATCH); |
3774 | 2.08k | } |
3775 | | |
3776 | 7.56k | cc = *Feptr; |
3777 | 7.56k | if (cc >= 128 || (mb->ctypes[cc] & ctype_digit) == 0) |
3778 | 6.30k | RRETURN(MATCH_NOMATCH); |
3779 | 1.26k | Feptr++; |
3780 | | /* No need to skip more code units - we know it has only one. */ |
3781 | 1.26k | } |
3782 | | |
3783 | 438 | break; |
3784 | | |
3785 | 13.2k | case OP_NOT_WHITESPACE: |
3786 | 28.5k | for (i = 1; i <= Lmin; i++) |
3787 | 18.7k | { |
3788 | 18.7k | uint32_t cc; |
3789 | 18.7k | if (Feptr >= mb->end_subject) |
3790 | 2.68k | { |
3791 | 2.68k | SCHECK_PARTIAL(); |
3792 | 2.67k | RRETURN(MATCH_NOMATCH); |
3793 | 2.67k | } |
3794 | | |
3795 | 16.1k | cc = *Feptr; |
3796 | 16.1k | if (cc < 128 && (mb->ctypes[cc] & ctype_space) != 0) |
3797 | 792 | RRETURN(MATCH_NOMATCH); |
3798 | 15.3k | Feptr++; |
3799 | 15.3k | ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); |
3800 | 15.3k | } |
3801 | | |
3802 | 9.76k | break; |
3803 | | |
3804 | 9.76k | case OP_WHITESPACE: |
3805 | 6.86k | for (i = 1; i <= Lmin; i++) |
3806 | 6.59k | { |
3807 | 6.59k | uint32_t cc; |
3808 | 6.59k | if (Feptr >= mb->end_subject) |
3809 | 1.91k | { |
3810 | 1.91k | SCHECK_PARTIAL(); |
3811 | 1.91k | RRETURN(MATCH_NOMATCH); |
3812 | 1.91k | } |
3813 | | |
3814 | 4.67k | cc = *Feptr; |
3815 | 4.67k | if (cc >= 128 || (mb->ctypes[cc] & ctype_space) == 0) |
3816 | 4.17k | RRETURN(MATCH_NOMATCH); |
3817 | 497 | Feptr++; |
3818 | | /* No need to skip more code units - we know it has only one. */ |
3819 | 497 | } |
3820 | | |
3821 | 277 | break; |
3822 | | |
3823 | 9.56k | case OP_NOT_WORDCHAR: |
3824 | 18.1k | for (i = 1; i <= Lmin; i++) |
3825 | 12.8k | { |
3826 | 12.8k | uint32_t cc; |
3827 | 12.8k | if (Feptr >= mb->end_subject) |
3828 | 2.29k | { |
3829 | 2.29k | SCHECK_PARTIAL(); |
3830 | 2.29k | RRETURN(MATCH_NOMATCH); |
3831 | 2.29k | } |
3832 | | |
3833 | 10.5k | cc = *Feptr; |
3834 | 10.5k | if (cc < 128 && (mb->ctypes[cc] & ctype_word) != 0) |
3835 | 1.95k | RRETURN(MATCH_NOMATCH); |
3836 | 8.58k | Feptr++; |
3837 | 8.58k | ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); |
3838 | 8.58k | } |
3839 | | |
3840 | 5.31k | break; |
3841 | | |
3842 | 7.90k | case OP_WORDCHAR: |
3843 | 9.78k | for (i = 1; i <= Lmin; i++) |
3844 | 8.68k | { |
3845 | 8.68k | uint32_t cc; |
3846 | 8.68k | if (Feptr >= mb->end_subject) |
3847 | 2.04k | { |
3848 | 2.04k | SCHECK_PARTIAL(); |
3849 | 2.04k | RRETURN(MATCH_NOMATCH); |
3850 | 2.04k | } |
3851 | | |
3852 | 6.64k | cc = *Feptr; |
3853 | 6.64k | if (cc >= 128 || (mb->ctypes[cc] & ctype_word) == 0) |
3854 | 4.76k | RRETURN(MATCH_NOMATCH); |
3855 | 1.88k | Feptr++; |
3856 | | /* No need to skip more code units - we know it has only one. */ |
3857 | 1.88k | } |
3858 | | |
3859 | 1.09k | break; |
3860 | | |
3861 | | /* LCOV_EXCL_START */ |
3862 | 1.09k | default: |
3863 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
3864 | 0 | return PCRE2_ERROR_INTERNAL; |
3865 | | /* LCOV_EXCL_STOP */ |
3866 | 258k | } // End switch (Lctype) |
3867 | 258k | } |
3868 | | |
3869 | 707k | else |
3870 | 707k | #endif /* SUPPORT_UNICODE */ |
3871 | | |
3872 | | /* Code for the non-UTF case for minimum matching of operators other |
3873 | | than OP_PROP and OP_NOTPROP. */ |
3874 | | |
3875 | 707k | switch (Lctype) |
3876 | 707k | { |
3877 | 69.4k | case OP_ANY: |
3878 | 145k | for (i = 1; i <= Lmin; i++) |
3879 | 88.6k | { |
3880 | 88.6k | if (Feptr >= mb->end_subject) |
3881 | 11.6k | { |
3882 | 11.6k | SCHECK_PARTIAL(); |
3883 | 11.6k | RRETURN(MATCH_NOMATCH); |
3884 | 11.6k | } |
3885 | | |
3886 | 76.9k | if (IS_NEWLINE(Feptr)) |
3887 | 1.31k | RRETURN(MATCH_NOMATCH); |
3888 | 75.6k | if (mb->partial != 0 && Feptr + 1 >= mb->end_subject && |
3889 | 2.86k | NLBLOCK->nltype == NLTYPE_FIXED && NLBLOCK->nllen == 2 && |
3890 | 0 | *Feptr == NLBLOCK->nl[0]) |
3891 | 0 | { |
3892 | 0 | mb->hitend = TRUE; |
3893 | 0 | if (mb->partial > 1) |
3894 | 0 | return PCRE2_ERROR_PARTIAL; |
3895 | 0 | } |
3896 | | |
3897 | 75.6k | Feptr++; |
3898 | 75.6k | } |
3899 | | |
3900 | 56.5k | break; |
3901 | | |
3902 | 56.5k | case OP_ALLANY: |
3903 | 12.4k | if (Feptr > mb->end_subject - Lmin) |
3904 | 3.08k | { |
3905 | 3.08k | SCHECK_PARTIAL(); |
3906 | 3.06k | RRETURN(MATCH_NOMATCH); |
3907 | 3.06k | } |
3908 | | |
3909 | 9.38k | Feptr += Lmin; |
3910 | 9.38k | break; |
3911 | | |
3912 | | /* This OP_ANYBYTE case will never be reached because \C gets turned |
3913 | | into OP_ALLANY in non-UTF mode. Cut out the code so that coverage |
3914 | | reports don't complain about it's never being used. */ |
3915 | | |
3916 | | /* case OP_ANYBYTE: |
3917 | | * if (Feptr > mb->end_subject - Lmin) |
3918 | | * { |
3919 | | * SCHECK_PARTIAL(); |
3920 | | * RRETURN(MATCH_NOMATCH); |
3921 | | * } |
3922 | | * |
3923 | | * Feptr += Lmin; |
3924 | | * break; |
3925 | | */ |
3926 | | |
3927 | 50.0k | case OP_ANYNL: |
3928 | 59.2k | for (i = 1; i <= Lmin; i++) |
3929 | 52.0k | { |
3930 | 52.0k | if (Feptr >= mb->end_subject) |
3931 | 7.17k | { |
3932 | 7.17k | SCHECK_PARTIAL(); |
3933 | 7.13k | RRETURN(MATCH_NOMATCH); |
3934 | 7.13k | } |
3935 | | |
3936 | 44.8k | switch (*Feptr++) |
3937 | 44.8k | { |
3938 | 35.6k | default: |
3939 | 35.6k | RRETURN(MATCH_NOMATCH); |
3940 | | |
3941 | 3.01k | case CHAR_CR: |
3942 | 3.01k | if (Feptr < mb->end_subject && *Feptr == CHAR_LF) |
3943 | 632 | Feptr++; |
3944 | 3.01k | break; |
3945 | | |
3946 | 2.64k | case CHAR_LF: |
3947 | 2.64k | break; |
3948 | | |
3949 | 1.26k | case CHAR_VT: |
3950 | 1.87k | case CHAR_FF: |
3951 | 2.41k | case CHAR_NEL: |
3952 | 2.41k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
3953 | 2.93k | case 0x2028: |
3954 | 3.58k | case 0x2029: |
3955 | 3.58k | #endif |
3956 | 3.58k | if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) |
3957 | 0 | RRETURN(MATCH_NOMATCH); |
3958 | 3.58k | break; |
3959 | 44.8k | } |
3960 | 44.8k | } |
3961 | | |
3962 | 7.23k | break; |
3963 | | |
3964 | 69.5k | case OP_NOT_HSPACE: |
3965 | 154k | for (i = 1; i <= Lmin; i++) |
3966 | 105k | { |
3967 | 105k | if (Feptr >= mb->end_subject) |
3968 | 7.28k | { |
3969 | 7.28k | SCHECK_PARTIAL(); |
3970 | 7.25k | RRETURN(MATCH_NOMATCH); |
3971 | 7.25k | } |
3972 | | |
3973 | 98.4k | switch (*Feptr++) |
3974 | 98.4k | { |
3975 | 84.6k | default: |
3976 | 84.6k | break; |
3977 | 84.6k | HSPACE_BYTE_CASES: |
3978 | 7.07k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
3979 | 146k | HSPACE_MULTIBYTE_CASES: |
3980 | 146k | #endif |
3981 | 146k | RRETURN(MATCH_NOMATCH); |
3982 | 98.4k | } |
3983 | 98.4k | } |
3984 | | |
3985 | 48.4k | break; |
3986 | | |
3987 | 48.4k | case OP_HSPACE: |
3988 | 48.1k | for (i = 1; i <= Lmin; i++) |
3989 | 39.0k | { |
3990 | 39.0k | if (Feptr >= mb->end_subject) |
3991 | 6.51k | { |
3992 | 6.51k | SCHECK_PARTIAL(); |
3993 | 6.44k | RRETURN(MATCH_NOMATCH); |
3994 | 6.44k | } |
3995 | | |
3996 | 32.5k | switch (*Feptr++) |
3997 | 32.5k | { |
3998 | 22.2k | default: |
3999 | 22.2k | RRETURN(MATCH_NOMATCH); |
4000 | 3.06k | HSPACE_BYTE_CASES: |
4001 | 3.06k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
4002 | 92.7k | HSPACE_MULTIBYTE_CASES: |
4003 | 92.7k | #endif |
4004 | 92.7k | break; |
4005 | 32.5k | } |
4006 | 32.5k | } |
4007 | | |
4008 | 9.08k | break; |
4009 | | |
4010 | 26.5k | case OP_NOT_VSPACE: |
4011 | 90.2k | for (i = 1; i <= Lmin; i++) |
4012 | 73.5k | { |
4013 | 73.5k | if (Feptr >= mb->end_subject) |
4014 | 5.86k | { |
4015 | 5.86k | SCHECK_PARTIAL(); |
4016 | 5.85k | RRETURN(MATCH_NOMATCH); |
4017 | 5.85k | } |
4018 | | |
4019 | 67.6k | switch (*Feptr++) |
4020 | 67.6k | { |
4021 | 8.96k | VSPACE_BYTE_CASES: |
4022 | 8.96k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
4023 | 8.96k | VSPACE_MULTIBYTE_CASES: |
4024 | 7.38k | #endif |
4025 | 7.38k | RRETURN(MATCH_NOMATCH); |
4026 | 63.6k | default: |
4027 | 63.6k | break; |
4028 | 67.6k | } |
4029 | 67.6k | } |
4030 | | |
4031 | 16.7k | break; |
4032 | | |
4033 | 19.6k | case OP_VSPACE: |
4034 | 22.8k | for (i = 1; i <= Lmin; i++) |
4035 | 20.2k | { |
4036 | 20.2k | if (Feptr >= mb->end_subject) |
4037 | 4.25k | { |
4038 | 4.25k | SCHECK_PARTIAL(); |
4039 | 4.23k | RRETURN(MATCH_NOMATCH); |
4040 | 4.23k | } |
4041 | | |
4042 | 15.9k | switch (*Feptr++) |
4043 | 15.9k | { |
4044 | 12.7k | default: |
4045 | 12.7k | RRETURN(MATCH_NOMATCH); |
4046 | 6.99k | VSPACE_BYTE_CASES: |
4047 | 6.99k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
4048 | 6.99k | VSPACE_MULTIBYTE_CASES: |
4049 | 6.12k | #endif |
4050 | 6.12k | break; |
4051 | 15.9k | } |
4052 | 15.9k | } |
4053 | | |
4054 | 2.66k | break; |
4055 | | |
4056 | 38.9k | case OP_NOT_DIGIT: |
4057 | 81.6k | for (i = 1; i <= Lmin; i++) |
4058 | 49.8k | { |
4059 | 49.8k | if (Feptr >= mb->end_subject) |
4060 | 3.92k | { |
4061 | 3.92k | SCHECK_PARTIAL(); |
4062 | 3.90k | RRETURN(MATCH_NOMATCH); |
4063 | 3.90k | } |
4064 | | |
4065 | 45.8k | if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_digit) != 0) |
4066 | 3.21k | RRETURN(MATCH_NOMATCH); |
4067 | 42.6k | Feptr++; |
4068 | 42.6k | } |
4069 | | |
4070 | 31.8k | break; |
4071 | | |
4072 | 31.8k | case OP_DIGIT: |
4073 | 18.5k | for (i = 1; i <= Lmin; i++) |
4074 | 17.6k | { |
4075 | 17.6k | if (Feptr >= mb->end_subject) |
4076 | 3.11k | { |
4077 | 3.11k | SCHECK_PARTIAL(); |
4078 | 3.09k | RRETURN(MATCH_NOMATCH); |
4079 | 3.09k | } |
4080 | | |
4081 | 14.5k | if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_digit) == 0) |
4082 | 12.9k | RRETURN(MATCH_NOMATCH); |
4083 | 1.60k | Feptr++; |
4084 | 1.60k | } |
4085 | | |
4086 | 899 | break; |
4087 | | |
4088 | 63.1k | case OP_NOT_WHITESPACE: |
4089 | 143k | for (i = 1; i <= Lmin; i++) |
4090 | 96.2k | { |
4091 | 96.2k | if (Feptr >= mb->end_subject) |
4092 | 11.5k | { |
4093 | 11.5k | SCHECK_PARTIAL(); |
4094 | 11.5k | RRETURN(MATCH_NOMATCH); |
4095 | 11.5k | } |
4096 | | |
4097 | 84.7k | if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_space) != 0) |
4098 | 4.61k | RRETURN(MATCH_NOMATCH); |
4099 | 80.1k | Feptr++; |
4100 | 80.1k | } |
4101 | | |
4102 | 46.9k | break; |
4103 | | |
4104 | 179k | case OP_WHITESPACE: |
4105 | 185k | for (i = 1; i <= Lmin; i++) |
4106 | 179k | { |
4107 | 179k | if (Feptr >= mb->end_subject) |
4108 | 3.12k | { |
4109 | 3.12k | SCHECK_PARTIAL(); |
4110 | 3.11k | RRETURN(MATCH_NOMATCH); |
4111 | 3.11k | } |
4112 | | |
4113 | 176k | if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_space) == 0) |
4114 | 171k | RRETURN(MATCH_NOMATCH); |
4115 | 5.57k | Feptr++; |
4116 | 5.57k | } |
4117 | | |
4118 | 5.28k | break; |
4119 | | |
4120 | 105k | case OP_NOT_WORDCHAR: |
4121 | 286k | for (i = 1; i <= Lmin; i++) |
4122 | 200k | { |
4123 | 200k | if (Feptr >= mb->end_subject) |
4124 | 3.14k | { |
4125 | 3.14k | SCHECK_PARTIAL(); |
4126 | 3.12k | RRETURN(MATCH_NOMATCH); |
4127 | 3.12k | } |
4128 | | |
4129 | 197k | if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_word) != 0) |
4130 | 16.1k | RRETURN(MATCH_NOMATCH); |
4131 | 181k | Feptr++; |
4132 | 181k | } |
4133 | | |
4134 | 85.9k | break; |
4135 | | |
4136 | 85.9k | case OP_WORDCHAR: |
4137 | 22.5k | for (i = 1; i <= Lmin; i++) |
4138 | 19.6k | { |
4139 | 19.6k | if (Feptr >= mb->end_subject) |
4140 | 4.07k | { |
4141 | 4.07k | SCHECK_PARTIAL(); |
4142 | 4.05k | RRETURN(MATCH_NOMATCH); |
4143 | 4.05k | } |
4144 | | |
4145 | 15.5k | if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_word) == 0) |
4146 | 11.1k | RRETURN(MATCH_NOMATCH); |
4147 | 4.39k | Feptr++; |
4148 | 4.39k | } |
4149 | | |
4150 | 2.88k | break; |
4151 | | |
4152 | | /* LCOV_EXCL_START */ |
4153 | 2.88k | default: |
4154 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
4155 | 0 | return PCRE2_ERROR_INTERNAL; |
4156 | | /* LCOV_EXCL_STOP */ |
4157 | 707k | } |
4158 | 1.40M | } |
4159 | | |
4160 | | /* If Lmin = Lmax we are done. Continue with the main loop. */ |
4161 | | |
4162 | 2.22M | if (Lmin == Lmax) |
4163 | 142k | continue; |
4164 | | |
4165 | | /* If minimizing, we have to test the rest of the pattern before each |
4166 | | subsequent match. This means we cannot use a local "notmatch" variable as |
4167 | | in the other cases. As all 4 temporary 32-bit values in the frame are |
4168 | | already in use, just test the type each time. */ |
4169 | | |
4170 | 2.07M | if (reptype == REPTYPE_MIN) |
4171 | 426k | { |
4172 | 426k | #ifdef SUPPORT_UNICODE |
4173 | 426k | if (proptype >= 0) |
4174 | 148k | { |
4175 | 148k | switch (proptype) |
4176 | 148k | { |
4177 | 9.24k | case PT_LAMP: |
4178 | 9.24k | for (;;) |
4179 | 31.0k | { |
4180 | 31.0k | int chartype; |
4181 | 31.0k | RMATCH(Fecode, RM208); |
4182 | 30.9k | if (rrc != MATCH_NOMATCH) |
4183 | 319 | RRETURN(rrc); |
4184 | 30.6k | if (Lmin++ >= Lmax) |
4185 | 549 | RRETURN(MATCH_NOMATCH); |
4186 | 30.0k | if (Feptr >= mb->end_subject) |
4187 | 2.81k | { |
4188 | 2.81k | SCHECK_PARTIAL(); |
4189 | 2.80k | RRETURN(MATCH_NOMATCH); |
4190 | 2.80k | } |
4191 | | |
4192 | 27.2k | GETCHARINCTEST(fc, Feptr); |
4193 | 27.2k | chartype = UCD_CHARTYPE(fc); |
4194 | 27.2k | if ((chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt) == |
4195 | 27.2k | (Lctype == OP_NOTPROP)) |
4196 | 5.47k | RRETURN(MATCH_NOMATCH); |
4197 | 27.2k | } |
4198 | | |
4199 | 9.24k | PCRE2_UNREACHABLE(); // Control never reaches here |
4200 | | |
4201 | 5.42k | case PT_GC: |
4202 | 5.42k | for (;;) |
4203 | 15.0k | { |
4204 | 15.0k | RMATCH(Fecode, RM209); |
4205 | 14.5k | if (rrc != MATCH_NOMATCH) |
4206 | 295 | RRETURN(rrc); |
4207 | 14.2k | if (Lmin++ >= Lmax) |
4208 | 871 | RRETURN(MATCH_NOMATCH); |
4209 | 13.3k | if (Feptr >= mb->end_subject) |
4210 | 2.21k | { |
4211 | 2.21k | SCHECK_PARTIAL(); |
4212 | 2.20k | RRETURN(MATCH_NOMATCH); |
4213 | 2.20k | } |
4214 | | |
4215 | 11.1k | GETCHARINCTEST(fc, Feptr); |
4216 | 11.1k | if ((UCD_CATEGORY(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) |
4217 | 1.56k | RRETURN(MATCH_NOMATCH); |
4218 | 11.1k | } |
4219 | | |
4220 | 5.42k | PCRE2_UNREACHABLE(); // Control never reaches here |
4221 | | |
4222 | 14.2k | case PT_PC: |
4223 | 14.2k | for (;;) |
4224 | 72.5k | { |
4225 | 72.5k | RMATCH(Fecode, RM210); |
4226 | 71.8k | if (rrc != MATCH_NOMATCH) |
4227 | 401 | RRETURN(rrc); |
4228 | 71.4k | if (Lmin++ >= Lmax) |
4229 | 2.07k | RRETURN(MATCH_NOMATCH); |
4230 | 69.3k | if (Feptr >= mb->end_subject) |
4231 | 7.24k | { |
4232 | 7.24k | SCHECK_PARTIAL(); |
4233 | 7.23k | RRETURN(MATCH_NOMATCH); |
4234 | 7.23k | } |
4235 | | |
4236 | 62.1k | GETCHARINCTEST(fc, Feptr); |
4237 | 62.1k | if ((UCD_CHARTYPE(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) |
4238 | 3.84k | RRETURN(MATCH_NOMATCH); |
4239 | 62.1k | } |
4240 | | |
4241 | 14.2k | PCRE2_UNREACHABLE(); // Control never reaches here |
4242 | | |
4243 | 5.66k | case PT_SC: |
4244 | 5.66k | for (;;) |
4245 | 22.6k | { |
4246 | 22.6k | RMATCH(Fecode, RM211); |
4247 | 22.3k | if (rrc != MATCH_NOMATCH) |
4248 | 221 | RRETURN(rrc); |
4249 | 22.1k | if (Lmin++ >= Lmax) |
4250 | 1.13k | RRETURN(MATCH_NOMATCH); |
4251 | 20.9k | if (Feptr >= mb->end_subject) |
4252 | 2.30k | { |
4253 | 2.30k | SCHECK_PARTIAL(); |
4254 | 2.30k | RRETURN(MATCH_NOMATCH); |
4255 | 2.30k | } |
4256 | | |
4257 | 18.6k | GETCHARINCTEST(fc, Feptr); |
4258 | 18.6k | if ((UCD_SCRIPT(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) |
4259 | 1.66k | RRETURN(MATCH_NOMATCH); |
4260 | 18.6k | } |
4261 | | |
4262 | 5.66k | PCRE2_UNREACHABLE(); // Control never reaches here |
4263 | | |
4264 | 6.16k | case PT_SCX: |
4265 | 6.16k | for (;;) |
4266 | 18.8k | { |
4267 | 18.8k | BOOL ok; |
4268 | 18.8k | const ucd_record *prop; |
4269 | 18.8k | RMATCH(Fecode, RM224); |
4270 | 18.7k | if (rrc != MATCH_NOMATCH) |
4271 | 220 | RRETURN(rrc); |
4272 | 18.5k | if (Lmin++ >= Lmax) |
4273 | 2.20k | RRETURN(MATCH_NOMATCH); |
4274 | 16.3k | if (Feptr >= mb->end_subject) |
4275 | 1.71k | { |
4276 | 1.71k | SCHECK_PARTIAL(); |
4277 | 1.70k | RRETURN(MATCH_NOMATCH); |
4278 | 1.70k | } |
4279 | | |
4280 | 14.6k | GETCHARINCTEST(fc, Feptr); |
4281 | 14.6k | prop = GET_UCD(fc); |
4282 | 14.6k | ok = (prop->script == Lpropvalue || |
4283 | 13.7k | MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0); |
4284 | 14.6k | if (ok == (Lctype == OP_NOTPROP)) |
4285 | 1.94k | RRETURN(MATCH_NOMATCH); |
4286 | 14.6k | } |
4287 | | |
4288 | 6.16k | PCRE2_UNREACHABLE(); // Control never reaches here |
4289 | | |
4290 | 7.24k | case PT_ALNUM: |
4291 | 7.24k | for (;;) |
4292 | 15.6k | { |
4293 | 15.6k | int category; |
4294 | 15.6k | RMATCH(Fecode, RM212); |
4295 | 15.5k | if (rrc != MATCH_NOMATCH) |
4296 | 260 | RRETURN(rrc); |
4297 | 15.3k | if (Lmin++ >= Lmax) |
4298 | 337 | RRETURN(MATCH_NOMATCH); |
4299 | 14.9k | if (Feptr >= mb->end_subject) |
4300 | 1.91k | { |
4301 | 1.91k | SCHECK_PARTIAL(); |
4302 | 1.90k | RRETURN(MATCH_NOMATCH); |
4303 | 1.90k | } |
4304 | | |
4305 | 13.0k | GETCHARINCTEST(fc, Feptr); |
4306 | 13.0k | category = UCD_CATEGORY(fc); |
4307 | 13.0k | if ((category == ucp_L || category == ucp_N) == (Lctype == OP_NOTPROP)) |
4308 | 4.64k | RRETURN(MATCH_NOMATCH); |
4309 | 13.0k | } |
4310 | | |
4311 | 7.24k | PCRE2_UNREACHABLE(); // Control never reaches here |
4312 | | |
4313 | | /* Perl space used to exclude VT, but from Perl 5.18 it is included, |
4314 | | which means that Perl space and POSIX space are now identical. PCRE |
4315 | | was changed at release 8.34. */ |
4316 | | |
4317 | 45.2k | case PT_SPACE: // Perl space |
4318 | 46.0k | case PT_PXSPACE: // POSIX space |
4319 | 46.0k | for (;;) |
4320 | 192k | { |
4321 | 192k | RMATCH(Fecode, RM213); |
4322 | 191k | if (rrc != MATCH_NOMATCH) |
4323 | 1.05k | RRETURN(rrc); |
4324 | 190k | if (Lmin++ >= Lmax) |
4325 | 9.84k | RRETURN(MATCH_NOMATCH); |
4326 | 180k | if (Feptr >= mb->end_subject) |
4327 | 7.68k | { |
4328 | 7.68k | SCHECK_PARTIAL(); |
4329 | 7.67k | RRETURN(MATCH_NOMATCH); |
4330 | 7.67k | } |
4331 | | |
4332 | 173k | GETCHARINCTEST(fc, Feptr); |
4333 | 173k | switch (fc) |
4334 | 173k | { |
4335 | 162k | HSPACE_CASES: |
4336 | 162k | VSPACE_CASES: |
4337 | 124k | if (Lctype == OP_NOTPROP) |
4338 | 19.2k | RRETURN(MATCH_NOMATCH); |
4339 | 678 | break; |
4340 | | |
4341 | 153k | default: |
4342 | 153k | if ((UCD_CATEGORY(fc) == ucp_Z) == (Lctype == OP_NOTPROP)) |
4343 | 7.00k | RRETURN(MATCH_NOMATCH); |
4344 | 146k | break; |
4345 | 173k | } |
4346 | 173k | } |
4347 | | |
4348 | 46.0k | PCRE2_UNREACHABLE(); // Control never reaches here |
4349 | | |
4350 | 18.7k | case PT_WORD: |
4351 | 18.7k | for (;;) |
4352 | 29.4k | { |
4353 | 29.4k | int chartype, category; |
4354 | 29.4k | RMATCH(Fecode, RM214); |
4355 | 28.6k | if (rrc != MATCH_NOMATCH) |
4356 | 367 | RRETURN(rrc); |
4357 | 28.2k | if (Lmin++ >= Lmax) |
4358 | 1.98k | RRETURN(MATCH_NOMATCH); |
4359 | 26.2k | if (Feptr >= mb->end_subject) |
4360 | 3.92k | { |
4361 | 3.92k | SCHECK_PARTIAL(); |
4362 | 3.92k | RRETURN(MATCH_NOMATCH); |
4363 | 3.92k | } |
4364 | | |
4365 | 22.3k | GETCHARINCTEST(fc, Feptr); |
4366 | 22.3k | chartype = UCD_CHARTYPE(fc); |
4367 | 22.3k | category = PRIV(ucp_gentype)[chartype]; |
4368 | 22.3k | if ((category == ucp_L || category == ucp_N || chartype == ucp_Mn || |
4369 | 22.3k | chartype == ucp_Pc) == (Lctype == OP_NOTPROP)) |
4370 | 11.6k | RRETURN(MATCH_NOMATCH); |
4371 | 22.3k | } |
4372 | | |
4373 | 18.7k | PCRE2_UNREACHABLE(); // Control never reaches here |
4374 | | |
4375 | 13.6k | case PT_CLIST: |
4376 | 13.6k | for (;;) |
4377 | 30.0k | { |
4378 | 30.0k | const uint32_t *cp; |
4379 | 30.0k | RMATCH(Fecode, RM215); |
4380 | 28.7k | if (rrc != MATCH_NOMATCH) |
4381 | 280 | RRETURN(rrc); |
4382 | 28.4k | if (Lmin++ >= Lmax) |
4383 | 982 | RRETURN(MATCH_NOMATCH); |
4384 | 27.5k | if (Feptr >= mb->end_subject) |
4385 | 2.25k | { |
4386 | 2.25k | SCHECK_PARTIAL(); |
4387 | 2.25k | RRETURN(MATCH_NOMATCH); |
4388 | 2.25k | } |
4389 | | |
4390 | 25.2k | GETCHARINCTEST(fc, Feptr); |
4391 | | #if PCRE2_CODE_UNIT_WIDTH == 32 |
4392 | | if (fc > MAX_UTF_CODE_POINT) |
4393 | | { |
4394 | | if (Lctype == OP_NOTPROP) |
4395 | | continue; |
4396 | | RRETURN(MATCH_NOMATCH); |
4397 | | } |
4398 | | #endif |
4399 | 25.2k | cp = PRIV(ucd_caseless_sets) + Lpropvalue; |
4400 | 25.2k | for (;;) |
4401 | 66.5k | { |
4402 | 66.5k | if (fc < *cp) |
4403 | 22.4k | { |
4404 | 22.4k | if (Lctype == OP_NOTPROP) |
4405 | 14.8k | break; |
4406 | 7.63k | RRETURN(MATCH_NOMATCH); |
4407 | 7.63k | } |
4408 | | |
4409 | 44.1k | if (fc == *cp++) |
4410 | 2.80k | { |
4411 | 2.80k | if (Lctype == OP_NOTPROP) |
4412 | 1.23k | RRETURN(MATCH_NOMATCH); |
4413 | 1.57k | break; |
4414 | 2.80k | } |
4415 | 44.1k | } |
4416 | 25.2k | } |
4417 | | |
4418 | 13.6k | PCRE2_UNREACHABLE(); // Control never reaches here |
4419 | | |
4420 | 9.48k | case PT_UCNC: |
4421 | 9.48k | for (;;) |
4422 | 45.5k | { |
4423 | 45.5k | RMATCH(Fecode, RM216); |
4424 | 45.4k | if (rrc != MATCH_NOMATCH) |
4425 | 231 | RRETURN(rrc); |
4426 | 45.2k | if (Lmin++ >= Lmax) |
4427 | 1.49k | RRETURN(MATCH_NOMATCH); |
4428 | 43.7k | if (Feptr >= mb->end_subject) |
4429 | 2.27k | { |
4430 | 2.27k | SCHECK_PARTIAL(); |
4431 | 2.25k | RRETURN(MATCH_NOMATCH); |
4432 | 2.25k | } |
4433 | | |
4434 | 41.4k | GETCHARINCTEST(fc, Feptr); |
4435 | 41.4k | if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT || fc == CHAR_GRAVE_ACCENT || |
4436 | 41.4k | (fc >= 0xa0 && fc <= 0xd7ff) || fc >= 0xe000) == (Lctype == OP_NOTPROP)) |
4437 | 5.37k | RRETURN(MATCH_NOMATCH); |
4438 | 41.4k | } |
4439 | | |
4440 | 9.48k | PCRE2_UNREACHABLE(); // Control never reaches here |
4441 | | |
4442 | 5.26k | case PT_BIDICL: |
4443 | 5.26k | for (;;) |
4444 | 18.0k | { |
4445 | 18.0k | RMATCH(Fecode, RM223); |
4446 | 17.9k | if (rrc != MATCH_NOMATCH) |
4447 | 200 | RRETURN(rrc); |
4448 | 17.7k | if (Lmin++ >= Lmax) |
4449 | 825 | RRETURN(MATCH_NOMATCH); |
4450 | 16.9k | if (Feptr >= mb->end_subject) |
4451 | 1.82k | { |
4452 | 1.82k | SCHECK_PARTIAL(); |
4453 | 1.81k | RRETURN(MATCH_NOMATCH); |
4454 | 1.81k | } |
4455 | | |
4456 | 15.1k | GETCHARINCTEST(fc, Feptr); |
4457 | 15.1k | if ((UCD_BIDICLASS(fc) == Lpropvalue) == (Lctype == OP_NOTPROP)) |
4458 | 2.37k | RRETURN(MATCH_NOMATCH); |
4459 | 15.1k | } |
4460 | | |
4461 | 5.26k | PCRE2_UNREACHABLE(); // Control never reaches here |
4462 | | |
4463 | 7.00k | case PT_BOOL: |
4464 | 7.00k | for (;;) |
4465 | 51.6k | { |
4466 | 51.6k | BOOL ok; |
4467 | 51.6k | const ucd_record *prop; |
4468 | 51.6k | RMATCH(Fecode, RM222); |
4469 | 51.5k | if (rrc != MATCH_NOMATCH) |
4470 | 312 | RRETURN(rrc); |
4471 | 51.2k | if (Lmin++ >= Lmax) |
4472 | 3.22k | RRETURN(MATCH_NOMATCH); |
4473 | 47.9k | if (Feptr >= mb->end_subject) |
4474 | 2.39k | { |
4475 | 2.39k | SCHECK_PARTIAL(); |
4476 | 2.37k | RRETURN(MATCH_NOMATCH); |
4477 | 2.37k | } |
4478 | | |
4479 | 45.5k | GETCHARINCTEST(fc, Feptr); |
4480 | 45.5k | prop = GET_UCD(fc); |
4481 | 45.5k | ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Lpropvalue) != 0; |
4482 | 45.5k | if (ok == (Lctype == OP_NOTPROP)) |
4483 | 924 | RRETURN(MATCH_NOMATCH); |
4484 | 45.5k | } |
4485 | | |
4486 | 7.00k | PCRE2_UNREACHABLE(); // Control never reaches here |
4487 | | |
4488 | | /* This should never occur */ |
4489 | | |
4490 | | /* LCOV_EXCL_START */ |
4491 | 0 | default: |
4492 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
4493 | 0 | return PCRE2_ERROR_INTERNAL; |
4494 | | /* LCOV_EXCL_STOP */ |
4495 | 148k | } |
4496 | 148k | } |
4497 | | |
4498 | | /* Match extended Unicode sequences. We will get here only if the |
4499 | | support is in the binary; otherwise a compile-time error occurs. */ |
4500 | | |
4501 | 277k | else if (Lctype == OP_EXTUNI) |
4502 | 17.2k | { |
4503 | 17.2k | for (;;) |
4504 | 96.2k | { |
4505 | 96.2k | RMATCH(Fecode, RM217); |
4506 | 94.5k | if (rrc != MATCH_NOMATCH) |
4507 | 4.14k | RRETURN(rrc); |
4508 | 90.3k | if (Lmin++ >= Lmax) |
4509 | 2.54k | RRETURN(MATCH_NOMATCH); |
4510 | 87.8k | if (Feptr >= mb->end_subject) |
4511 | 8.85k | { |
4512 | 8.85k | SCHECK_PARTIAL(); |
4513 | 8.84k | RRETURN(MATCH_NOMATCH); |
4514 | 8.84k | } |
4515 | 78.9k | else |
4516 | 78.9k | { |
4517 | 78.9k | GETCHARINCTEST(fc, Feptr); |
4518 | 78.9k | Feptr = PRIV(extuni)(fc, Feptr, mb->check_subject, mb->end_subject, utf, NULL); |
4519 | 78.9k | } |
4520 | | |
4521 | 78.9k | CHECK_PARTIAL(); |
4522 | 78.9k | } |
4523 | 17.2k | } |
4524 | 260k | else |
4525 | 260k | #endif /* SUPPORT_UNICODE */ |
4526 | | |
4527 | | /* UTF mode for non-property testing character types. */ |
4528 | | |
4529 | 260k | #ifdef SUPPORT_UNICODE |
4530 | 260k | if (utf) |
4531 | 148k | { |
4532 | 148k | for (;;) |
4533 | 516k | { |
4534 | 516k | RMATCH(Fecode, RM218); |
4535 | 511k | if (rrc != MATCH_NOMATCH) |
4536 | 2.98k | RRETURN(rrc); |
4537 | 508k | if (Lmin++ >= Lmax) |
4538 | 14.1k | RRETURN(MATCH_NOMATCH); |
4539 | 494k | if (Feptr >= mb->end_subject) |
4540 | 51.0k | { |
4541 | 51.0k | SCHECK_PARTIAL(); |
4542 | 51.0k | RRETURN(MATCH_NOMATCH); |
4543 | 51.0k | } |
4544 | | |
4545 | 443k | if (Lctype == OP_ANY && IS_NEWLINE(Feptr)) |
4546 | 786 | RRETURN(MATCH_NOMATCH); |
4547 | 442k | GETCHARINC(fc, Feptr); |
4548 | 442k | switch (Lctype) |
4549 | 442k | { |
4550 | 84.2k | case OP_ANY: // This is the non-NL case |
4551 | 84.2k | if (mb->partial != 0 && // Take care with CRLF partial |
4552 | 15.8k | Feptr >= mb->end_subject && NLBLOCK->nltype == NLTYPE_FIXED && |
4553 | 2.52k | NLBLOCK->nllen == 2 && fc == NLBLOCK->nl[0]) |
4554 | 0 | { |
4555 | 0 | mb->hitend = TRUE; |
4556 | 0 | if (mb->partial > 1) |
4557 | 0 | return PCRE2_ERROR_PARTIAL; |
4558 | 0 | } |
4559 | | |
4560 | 84.2k | break; |
4561 | | |
4562 | 84.2k | case OP_ALLANY: |
4563 | 41.1k | case OP_ANYBYTE: |
4564 | 41.1k | break; |
4565 | | |
4566 | 18.6k | case OP_ANYNL: |
4567 | 18.6k | switch (fc) |
4568 | 18.6k | { |
4569 | 13.2k | default: |
4570 | 13.2k | RRETURN(MATCH_NOMATCH); |
4571 | | |
4572 | 1.53k | case CHAR_CR: |
4573 | 1.53k | if (Feptr < mb->end_subject && *Feptr == CHAR_LF) |
4574 | 478 | Feptr++; |
4575 | 1.53k | break; |
4576 | | |
4577 | 447 | case CHAR_LF: |
4578 | 447 | break; |
4579 | | |
4580 | 399 | case CHAR_VT: |
4581 | 939 | case CHAR_FF: |
4582 | 1.62k | case CHAR_NEL: |
4583 | 1.62k | #ifndef EBCDIC |
4584 | 1.95k | case 0x2028: |
4585 | 3.47k | case 0x2029: |
4586 | 3.47k | #endif /* Not EBCDIC */ |
4587 | 3.47k | if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) |
4588 | 0 | RRETURN(MATCH_NOMATCH); |
4589 | 3.47k | break; |
4590 | 18.6k | } |
4591 | | |
4592 | 5.46k | break; |
4593 | | |
4594 | 128k | case OP_NOT_HSPACE: |
4595 | 128k | switch (fc) |
4596 | 128k | { |
4597 | 98.7k | HSPACE_CASES: |
4598 | 98.7k | RRETURN(MATCH_NOMATCH); |
4599 | 119k | default: |
4600 | 119k | break; |
4601 | 128k | } |
4602 | | |
4603 | 119k | break; |
4604 | | |
4605 | 119k | case OP_HSPACE: |
4606 | 29.0k | switch (fc) |
4607 | 29.0k | { |
4608 | 6.00k | HSPACE_CASES: |
4609 | 6.00k | break; |
4610 | 23.0k | default: |
4611 | 23.0k | RRETURN(MATCH_NOMATCH); |
4612 | 29.0k | } |
4613 | | |
4614 | 6.00k | break; |
4615 | | |
4616 | 27.2k | case OP_NOT_VSPACE: |
4617 | 27.2k | switch (fc) |
4618 | 27.2k | { |
4619 | 13.6k | VSPACE_CASES: |
4620 | 13.6k | RRETURN(MATCH_NOMATCH); |
4621 | 24.0k | default: |
4622 | 24.0k | break; |
4623 | 27.2k | } |
4624 | | |
4625 | 24.0k | break; |
4626 | | |
4627 | 24.0k | case OP_VSPACE: |
4628 | 10.9k | switch (fc) |
4629 | 10.9k | { |
4630 | 2.01k | VSPACE_CASES: |
4631 | 2.01k | break; |
4632 | 8.95k | default: |
4633 | 8.95k | RRETURN(MATCH_NOMATCH); |
4634 | 10.9k | } |
4635 | | |
4636 | 2.01k | break; |
4637 | | |
4638 | 28.1k | case OP_NOT_DIGIT: |
4639 | 28.1k | if (fc < 256 && (mb->ctypes[fc] & ctype_digit) != 0) |
4640 | 560 | RRETURN(MATCH_NOMATCH); |
4641 | 27.5k | break; |
4642 | | |
4643 | 27.5k | case OP_DIGIT: |
4644 | 1.91k | if (fc >= 256 || (mb->ctypes[fc] & ctype_digit) == 0) |
4645 | 1.60k | RRETURN(MATCH_NOMATCH); |
4646 | 311 | break; |
4647 | | |
4648 | 46.7k | case OP_NOT_WHITESPACE: |
4649 | 46.7k | if (fc < 256 && (mb->ctypes[fc] & ctype_space) != 0) |
4650 | 1.91k | RRETURN(MATCH_NOMATCH); |
4651 | 44.8k | break; |
4652 | | |
4653 | 44.8k | case OP_WHITESPACE: |
4654 | 1.79k | if (fc >= 256 || (mb->ctypes[fc] & ctype_space) == 0) |
4655 | 1.58k | RRETURN(MATCH_NOMATCH); |
4656 | 211 | break; |
4657 | | |
4658 | 14.7k | case OP_NOT_WORDCHAR: |
4659 | 14.7k | if (fc < 256 && (mb->ctypes[fc] & ctype_word) != 0) |
4660 | 2.07k | RRETURN(MATCH_NOMATCH); |
4661 | 12.6k | break; |
4662 | | |
4663 | 12.6k | case OP_WORDCHAR: |
4664 | 9.27k | if (fc >= 256 || (mb->ctypes[fc] & ctype_word) == 0) |
4665 | 8.42k | RRETURN(MATCH_NOMATCH); |
4666 | 847 | break; |
4667 | | |
4668 | | /* LCOV_EXCL_START */ |
4669 | 847 | default: |
4670 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
4671 | 0 | return PCRE2_ERROR_INTERNAL; |
4672 | | /* LCOV_EXCL_STOP */ |
4673 | 442k | } |
4674 | 442k | } |
4675 | 148k | } |
4676 | 112k | else |
4677 | 112k | #endif /* SUPPORT_UNICODE */ |
4678 | | |
4679 | | /* Not UTF mode */ |
4680 | 112k | { |
4681 | 112k | for (;;) |
4682 | 449k | { |
4683 | 449k | RMATCH(Fecode, RM33); |
4684 | 446k | if (rrc != MATCH_NOMATCH) |
4685 | 1.35k | RRETURN(rrc); |
4686 | 445k | if (Lmin++ >= Lmax) |
4687 | 14.0k | RRETURN(MATCH_NOMATCH); |
4688 | 431k | if (Feptr >= mb->end_subject) |
4689 | 22.6k | { |
4690 | 22.6k | SCHECK_PARTIAL(); |
4691 | 22.6k | RRETURN(MATCH_NOMATCH); |
4692 | 22.6k | } |
4693 | | |
4694 | 408k | if (Lctype == OP_ANY && IS_NEWLINE(Feptr)) |
4695 | 1.12k | RRETURN(MATCH_NOMATCH); |
4696 | 407k | fc = *Feptr++; |
4697 | 407k | switch (Lctype) |
4698 | 407k | { |
4699 | 101k | case OP_ANY: // This is the non-NL case |
4700 | 101k | if (mb->partial != 0 && // Take care with CRLF partial |
4701 | 43.0k | Feptr >= mb->end_subject && NLBLOCK->nltype == NLTYPE_FIXED && |
4702 | 964 | NLBLOCK->nllen == 2 && fc == NLBLOCK->nl[0]) |
4703 | 0 | { |
4704 | 0 | mb->hitend = TRUE; |
4705 | 0 | if (mb->partial > 1) |
4706 | 0 | return PCRE2_ERROR_PARTIAL; |
4707 | 0 | } |
4708 | | |
4709 | 101k | break; |
4710 | | |
4711 | 101k | case OP_ALLANY: |
4712 | 11.4k | case OP_ANYBYTE: |
4713 | 11.4k | break; |
4714 | | |
4715 | 16.3k | case OP_ANYNL: |
4716 | 16.3k | switch (fc) |
4717 | 16.3k | { |
4718 | 11.2k | default: |
4719 | 11.2k | RRETURN(MATCH_NOMATCH); |
4720 | | |
4721 | 1.86k | case CHAR_CR: |
4722 | 1.86k | if (Feptr < mb->end_subject && *Feptr == CHAR_LF) |
4723 | 866 | Feptr++; |
4724 | 1.86k | break; |
4725 | | |
4726 | 1.40k | case CHAR_LF: |
4727 | 1.40k | break; |
4728 | | |
4729 | 352 | case CHAR_VT: |
4730 | 939 | case CHAR_FF: |
4731 | 1.19k | case CHAR_NEL: |
4732 | 1.19k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
4733 | 1.57k | case 0x2028: |
4734 | 1.81k | case 0x2029: |
4735 | 1.81k | #endif |
4736 | 1.81k | if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) |
4737 | 0 | RRETURN(MATCH_NOMATCH); |
4738 | 1.81k | break; |
4739 | 16.3k | } |
4740 | | |
4741 | 5.08k | break; |
4742 | | |
4743 | 173k | case OP_NOT_HSPACE: |
4744 | 173k | switch (fc) |
4745 | 173k | { |
4746 | 163k | default: |
4747 | 163k | break; |
4748 | 163k | HSPACE_BYTE_CASES: |
4749 | 4.85k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
4750 | 101k | HSPACE_MULTIBYTE_CASES: |
4751 | 101k | #endif |
4752 | 101k | RRETURN(MATCH_NOMATCH); |
4753 | 173k | } |
4754 | | |
4755 | 163k | break; |
4756 | | |
4757 | 163k | case OP_HSPACE: |
4758 | 27.4k | switch (fc) |
4759 | 27.4k | { |
4760 | 22.4k | default: |
4761 | 22.4k | RRETURN(MATCH_NOMATCH); |
4762 | 2.05k | HSPACE_BYTE_CASES: |
4763 | 2.05k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
4764 | 50.0k | HSPACE_MULTIBYTE_CASES: |
4765 | 50.0k | #endif |
4766 | 50.0k | break; |
4767 | 27.4k | } |
4768 | | |
4769 | 4.95k | break; |
4770 | | |
4771 | 20.8k | case OP_NOT_VSPACE: |
4772 | 20.8k | switch (fc) |
4773 | 20.8k | { |
4774 | 18.5k | default: |
4775 | 18.5k | break; |
4776 | 18.5k | VSPACE_BYTE_CASES: |
4777 | 5.34k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
4778 | 5.34k | VSPACE_MULTIBYTE_CASES: |
4779 | 4.29k | #endif |
4780 | 4.29k | RRETURN(MATCH_NOMATCH); |
4781 | 20.8k | } |
4782 | | |
4783 | 18.5k | break; |
4784 | | |
4785 | 18.5k | case OP_VSPACE: |
4786 | 9.79k | switch (fc) |
4787 | 9.79k | { |
4788 | 7.42k | default: |
4789 | 7.42k | RRETURN(MATCH_NOMATCH); |
4790 | 4.50k | VSPACE_BYTE_CASES: |
4791 | 4.50k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
4792 | 4.50k | VSPACE_MULTIBYTE_CASES: |
4793 | 4.11k | #endif |
4794 | 4.11k | break; |
4795 | 9.79k | } |
4796 | | |
4797 | 2.36k | break; |
4798 | | |
4799 | 10.2k | case OP_NOT_DIGIT: |
4800 | 10.2k | if (MAX_255(fc) && (mb->ctypes[fc] & ctype_digit) != 0) |
4801 | 558 | RRETURN(MATCH_NOMATCH); |
4802 | 9.68k | break; |
4803 | | |
4804 | 9.68k | case OP_DIGIT: |
4805 | 3.30k | if (!MAX_255(fc) || (mb->ctypes[fc] & ctype_digit) == 0) |
4806 | 3.08k | RRETURN(MATCH_NOMATCH); |
4807 | 226 | break; |
4808 | | |
4809 | 17.3k | case OP_NOT_WHITESPACE: |
4810 | 17.3k | if (MAX_255(fc) && (mb->ctypes[fc] & ctype_space) != 0) |
4811 | 781 | RRETURN(MATCH_NOMATCH); |
4812 | 16.5k | break; |
4813 | | |
4814 | 16.5k | case OP_WHITESPACE: |
4815 | 6.87k | if (!MAX_255(fc) || (mb->ctypes[fc] & ctype_space) == 0) |
4816 | 6.66k | RRETURN(MATCH_NOMATCH); |
4817 | 212 | break; |
4818 | | |
4819 | 2.76k | case OP_NOT_WORDCHAR: |
4820 | 2.76k | if (MAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0) |
4821 | 658 | RRETURN(MATCH_NOMATCH); |
4822 | 2.10k | break; |
4823 | | |
4824 | 6.03k | case OP_WORDCHAR: |
4825 | 6.03k | if (!MAX_255(fc) || (mb->ctypes[fc] & ctype_word) == 0) |
4826 | 5.61k | RRETURN(MATCH_NOMATCH); |
4827 | 418 | break; |
4828 | | |
4829 | | /* LCOV_EXCL_START */ |
4830 | 418 | default: |
4831 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
4832 | 0 | return PCRE2_ERROR_INTERNAL; |
4833 | | /* LCOV_EXCL_STOP */ |
4834 | 407k | } |
4835 | 407k | } |
4836 | 112k | } |
4837 | | |
4838 | 0 | PCRE2_DEBUG_UNREACHABLE(); // Control should never reach here |
4839 | 0 | } |
4840 | | |
4841 | | /* If maximizing, it is worth using inline code for speed, doing the type |
4842 | | test once at the start (i.e. keep it out of the loops). Once again, |
4843 | | "notmatch" can be an ordinary local variable because the loops do not call |
4844 | | RMATCH. */ |
4845 | | |
4846 | 1.65M | else |
4847 | 1.65M | { |
4848 | 1.65M | Lstart_eptr = Feptr; // Remember where we started |
4849 | | |
4850 | 1.65M | #ifdef SUPPORT_UNICODE |
4851 | 1.65M | if (proptype >= 0) |
4852 | 367k | { |
4853 | 367k | BOOL notmatch = Lctype == OP_NOTPROP; |
4854 | 367k | switch (proptype) |
4855 | 367k | { |
4856 | 13.8k | case PT_LAMP: |
4857 | 34.9k | for (i = Lmin; i < Lmax; i++) |
4858 | 34.2k | { |
4859 | 34.2k | int chartype; |
4860 | 34.2k | int len = 1; |
4861 | 34.2k | if (Feptr >= mb->end_subject) |
4862 | 3.84k | { |
4863 | 3.84k | SCHECK_PARTIAL(); |
4864 | 3.81k | break; |
4865 | 3.84k | } |
4866 | | |
4867 | 30.4k | GETCHARLENTEST(fc, Feptr, len); |
4868 | 30.4k | chartype = UCD_CHARTYPE(fc); |
4869 | 30.4k | if ((chartype == ucp_Lu || chartype == ucp_Ll || chartype == ucp_Lt) == notmatch) |
4870 | 9.29k | break; |
4871 | 21.1k | Feptr += len; |
4872 | 21.1k | } |
4873 | | |
4874 | 13.7k | break; |
4875 | | |
4876 | 17.8k | case PT_GC: |
4877 | 61.8k | for (i = Lmin; i < Lmax; i++) |
4878 | 59.3k | { |
4879 | 59.3k | int len = 1; |
4880 | 59.3k | if (Feptr >= mb->end_subject) |
4881 | 6.52k | { |
4882 | 6.52k | SCHECK_PARTIAL(); |
4883 | 6.48k | break; |
4884 | 6.52k | } |
4885 | | |
4886 | 52.8k | GETCHARLENTEST(fc, Feptr, len); |
4887 | 52.8k | if ((UCD_CATEGORY(fc) == Lpropvalue) == notmatch) |
4888 | 8.84k | break; |
4889 | 43.9k | Feptr += len; |
4890 | 43.9k | } |
4891 | | |
4892 | 17.8k | break; |
4893 | | |
4894 | 94.8k | case PT_PC: |
4895 | 175k | for (i = Lmin; i < Lmax; i++) |
4896 | 170k | { |
4897 | 170k | int len = 1; |
4898 | 170k | if (Feptr >= mb->end_subject) |
4899 | 6.64k | { |
4900 | 6.64k | SCHECK_PARTIAL(); |
4901 | 6.60k | break; |
4902 | 6.64k | } |
4903 | | |
4904 | 164k | GETCHARLENTEST(fc, Feptr, len); |
4905 | 164k | if ((UCD_CHARTYPE(fc) == Lpropvalue) == notmatch) |
4906 | 82.9k | break; |
4907 | 81.1k | Feptr += len; |
4908 | 81.1k | } |
4909 | | |
4910 | 94.8k | break; |
4911 | | |
4912 | 94.8k | case PT_SC: |
4913 | 32.3k | for (i = Lmin; i < Lmax; i++) |
4914 | 30.5k | { |
4915 | 30.5k | int len = 1; |
4916 | 30.5k | if (Feptr >= mb->end_subject) |
4917 | 3.97k | { |
4918 | 3.97k | SCHECK_PARTIAL(); |
4919 | 3.95k | break; |
4920 | 3.97k | } |
4921 | | |
4922 | 26.5k | GETCHARLENTEST(fc, Feptr, len); |
4923 | 26.5k | if ((UCD_SCRIPT(fc) == Lpropvalue) == notmatch) |
4924 | 3.07k | break; |
4925 | 23.4k | Feptr += len; |
4926 | 23.4k | } |
4927 | | |
4928 | 8.88k | break; |
4929 | | |
4930 | 9.67k | case PT_SCX: |
4931 | 43.6k | for (i = Lmin; i < Lmax; i++) |
4932 | 41.8k | { |
4933 | 41.8k | BOOL ok; |
4934 | 41.8k | const ucd_record *prop; |
4935 | 41.8k | int len = 1; |
4936 | 41.8k | if (Feptr >= mb->end_subject) |
4937 | 3.60k | { |
4938 | 3.60k | SCHECK_PARTIAL(); |
4939 | 3.53k | break; |
4940 | 3.60k | } |
4941 | | |
4942 | 38.2k | GETCHARLENTEST(fc, Feptr, len); |
4943 | 38.2k | prop = GET_UCD(fc); |
4944 | 38.2k | ok = (prop->script == Lpropvalue || |
4945 | 36.5k | MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0); |
4946 | 38.2k | if (ok == notmatch) |
4947 | 4.29k | break; |
4948 | 33.9k | Feptr += len; |
4949 | 33.9k | } |
4950 | | |
4951 | 9.60k | break; |
4952 | | |
4953 | 17.3k | case PT_ALNUM: |
4954 | 97.4k | for (i = Lmin; i < Lmax; i++) |
4955 | 95.9k | { |
4956 | 95.9k | int category; |
4957 | 95.9k | int len = 1; |
4958 | 95.9k | if (Feptr >= mb->end_subject) |
4959 | 4.73k | { |
4960 | 4.73k | SCHECK_PARTIAL(); |
4961 | 4.71k | break; |
4962 | 4.73k | } |
4963 | | |
4964 | 91.2k | GETCHARLENTEST(fc, Feptr, len); |
4965 | 91.2k | category = UCD_CATEGORY(fc); |
4966 | 91.2k | if ((category == ucp_L || category == ucp_N) == notmatch) |
4967 | 11.0k | break; |
4968 | 80.1k | Feptr += len; |
4969 | 80.1k | } |
4970 | | |
4971 | 17.3k | break; |
4972 | | |
4973 | | /* Perl space used to exclude VT, but from Perl 5.18 it is included, |
4974 | | which means that Perl space and POSIX space are now identical. PCRE |
4975 | | was changed at release 8.34. */ |
4976 | | |
4977 | 79.2k | case PT_SPACE: // Perl space |
4978 | 80.3k | case PT_PXSPACE: // POSIX space |
4979 | 254k | for (i = Lmin; i < Lmax; i++) |
4980 | 238k | { |
4981 | 238k | int len = 1; |
4982 | 238k | if (Feptr >= mb->end_subject) |
4983 | 11.3k | { |
4984 | 11.3k | SCHECK_PARTIAL(); |
4985 | 11.2k | break; |
4986 | 11.3k | } |
4987 | | |
4988 | 227k | GETCHARLENTEST(fc, Feptr, len); |
4989 | 227k | switch (fc) |
4990 | 227k | { |
4991 | 180k | HSPACE_CASES: |
4992 | 180k | VSPACE_CASES: |
4993 | 155k | if (notmatch) |
4994 | 22.1k | goto ENDLOOP99; // Break the loop |
4995 | 2.98k | break; |
4996 | | |
4997 | 202k | default: |
4998 | 202k | if ((UCD_CATEGORY(fc) == ucp_Z) == notmatch) |
4999 | 31.0k | goto ENDLOOP99; // Break the loop |
5000 | 171k | break; |
5001 | 227k | } |
5002 | | |
5003 | 174k | Feptr += len; |
5004 | 174k | } |
5005 | | |
5006 | 80.1k | ENDLOOP99: |
5007 | 80.1k | break; |
5008 | | |
5009 | 51.8k | case PT_WORD: |
5010 | 84.4k | for (i = Lmin; i < Lmax; i++) |
5011 | 72.5k | { |
5012 | 72.5k | int chartype, category; |
5013 | 72.5k | int len = 1; |
5014 | 72.5k | if (Feptr >= mb->end_subject) |
5015 | 3.55k | { |
5016 | 3.55k | SCHECK_PARTIAL(); |
5017 | 3.52k | break; |
5018 | 3.55k | } |
5019 | | |
5020 | 68.9k | GETCHARLENTEST(fc, Feptr, len); |
5021 | 68.9k | chartype = UCD_CHARTYPE(fc); |
5022 | 68.9k | category = PRIV(ucp_gentype)[chartype]; |
5023 | 68.9k | if ((category == ucp_L || category == ucp_N || chartype == ucp_Mn || |
5024 | 41.9k | chartype == ucp_Pc) == notmatch) |
5025 | 36.3k | break; |
5026 | 32.6k | Feptr += len; |
5027 | 32.6k | } |
5028 | | |
5029 | 51.8k | break; |
5030 | | |
5031 | 51.8k | case PT_CLIST: |
5032 | 19.3k | for (i = Lmin; i < Lmax; i++) |
5033 | 18.1k | { |
5034 | 18.1k | const uint32_t *cp; |
5035 | 18.1k | int len = 1; |
5036 | 18.1k | if (Feptr >= mb->end_subject) |
5037 | 2.28k | { |
5038 | 2.28k | SCHECK_PARTIAL(); |
5039 | 2.28k | break; |
5040 | 2.28k | } |
5041 | | |
5042 | 15.8k | GETCHARLENTEST(fc, Feptr, len); |
5043 | | #if PCRE2_CODE_UNIT_WIDTH == 32 |
5044 | | if (fc > MAX_UTF_CODE_POINT) |
5045 | | { |
5046 | | if (!notmatch) |
5047 | | goto GOT_MAX; |
5048 | | } |
5049 | | else |
5050 | | #endif |
5051 | 15.8k | { |
5052 | 15.8k | cp = PRIV(ucd_caseless_sets) + Lpropvalue; |
5053 | 15.8k | for (;;) |
5054 | 25.4k | { |
5055 | 25.4k | if (fc < *cp) |
5056 | 13.6k | { |
5057 | 13.6k | if (notmatch) |
5058 | 1.85k | break; |
5059 | 11.8k | else |
5060 | 11.8k | goto GOT_MAX; |
5061 | 13.6k | } |
5062 | | |
5063 | 11.7k | if (fc == *cp++) |
5064 | 2.20k | { |
5065 | 2.20k | if (notmatch) |
5066 | 462 | goto GOT_MAX; |
5067 | 1.73k | else |
5068 | 1.73k | break; |
5069 | 2.20k | } |
5070 | 11.7k | } |
5071 | 15.8k | } |
5072 | | |
5073 | 3.59k | Feptr += len; |
5074 | 3.59k | } |
5075 | | |
5076 | 15.7k | GOT_MAX: |
5077 | 15.7k | break; |
5078 | | |
5079 | 34.3k | case PT_UCNC: |
5080 | 108k | for (i = Lmin; i < Lmax; i++) |
5081 | 100k | { |
5082 | 100k | int len = 1; |
5083 | 100k | if (Feptr >= mb->end_subject) |
5084 | 4.50k | { |
5085 | 4.50k | SCHECK_PARTIAL(); |
5086 | 4.47k | break; |
5087 | 4.50k | } |
5088 | | |
5089 | 96.0k | GETCHARLENTEST(fc, Feptr, len); |
5090 | 96.0k | if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT || fc == CHAR_GRAVE_ACCENT || |
5091 | 93.3k | (fc >= 0xa0 && fc <= 0xd7ff) || fc >= 0xe000) == notmatch) |
5092 | 21.6k | break; |
5093 | 74.3k | Feptr += len; |
5094 | 74.3k | } |
5095 | | |
5096 | 34.2k | break; |
5097 | | |
5098 | 34.2k | case PT_BIDICL: |
5099 | 25.0k | for (i = Lmin; i < Lmax; i++) |
5100 | 23.4k | { |
5101 | 23.4k | int len = 1; |
5102 | 23.4k | if (Feptr >= mb->end_subject) |
5103 | 4.97k | { |
5104 | 4.97k | SCHECK_PARTIAL(); |
5105 | 4.94k | break; |
5106 | 4.97k | } |
5107 | | |
5108 | 18.4k | GETCHARLENTEST(fc, Feptr, len); |
5109 | 18.4k | if ((UCD_BIDICLASS(fc) == Lpropvalue) == notmatch) |
5110 | 5.75k | break; |
5111 | 12.7k | Feptr += len; |
5112 | 12.7k | } |
5113 | | |
5114 | 12.3k | break; |
5115 | | |
5116 | 12.3k | case PT_BOOL: |
5117 | 76.4k | for (i = Lmin; i < Lmax; i++) |
5118 | 73.2k | { |
5119 | 73.2k | BOOL ok; |
5120 | 73.2k | const ucd_record *prop; |
5121 | 73.2k | int len = 1; |
5122 | 73.2k | if (Feptr >= mb->end_subject) |
5123 | 7.07k | { |
5124 | 7.07k | SCHECK_PARTIAL(); |
5125 | 7.04k | break; |
5126 | 7.07k | } |
5127 | | |
5128 | 66.1k | GETCHARLENTEST(fc, Feptr, len); |
5129 | 66.1k | prop = GET_UCD(fc); |
5130 | 66.1k | ok = MAPBIT(PRIV(ucd_boolprop_sets) + UCD_BPROPS_PROP(prop), Lpropvalue) != 0; |
5131 | 66.1k | if (ok == notmatch) |
5132 | 410 | break; |
5133 | 65.7k | Feptr += len; |
5134 | 65.7k | } |
5135 | | |
5136 | 10.6k | break; |
5137 | | |
5138 | | /* LCOV_EXCL_START */ |
5139 | 10.6k | default: |
5140 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
5141 | 0 | return PCRE2_ERROR_INTERNAL; |
5142 | | /* LCOV_EXCL_STOP */ |
5143 | 367k | } |
5144 | | |
5145 | | /* Feptr is now past the end of the maximum run */ |
5146 | | |
5147 | 367k | if (reptype == REPTYPE_POS) |
5148 | 108k | continue; // No backtracking |
5149 | | |
5150 | | /* After \C in UTF mode, Lstart_eptr might be in the middle of a |
5151 | | Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't |
5152 | | go too far. */ |
5153 | | |
5154 | 258k | for (;;) |
5155 | 672k | { |
5156 | 672k | if (Feptr <= Lstart_eptr) |
5157 | 254k | break; |
5158 | 417k | RMATCH(Fecode, RM221); |
5159 | 414k | if (rrc != MATCH_NOMATCH) |
5160 | 1.10k | RRETURN(rrc); |
5161 | 413k | Feptr--; |
5162 | 413k | if (utf) |
5163 | 169k | BACKCHAR(Feptr); |
5164 | 413k | } |
5165 | 258k | } |
5166 | | |
5167 | | /* Match extended Unicode grapheme clusters. We will get here only if the |
5168 | | support is in the binary; otherwise a compile-time error occurs. */ |
5169 | | |
5170 | 1.28M | else if (Lctype == OP_EXTUNI) |
5171 | 50.8k | { |
5172 | 438k | for (i = Lmin; i < Lmax; i++) |
5173 | 427k | { |
5174 | 427k | if (Feptr >= mb->end_subject) |
5175 | 38.6k | { |
5176 | 38.6k | SCHECK_PARTIAL(); |
5177 | 38.6k | break; |
5178 | 38.6k | } |
5179 | 388k | else |
5180 | 388k | { |
5181 | 388k | GETCHARINCTEST(fc, Feptr); |
5182 | 388k | Feptr = PRIV(extuni)(fc, Feptr, mb->check_subject, mb->end_subject, utf, NULL); |
5183 | 388k | } |
5184 | | |
5185 | 388k | CHECK_PARTIAL(); |
5186 | 388k | } |
5187 | | |
5188 | | /* Feptr is now past the end of the maximum run */ |
5189 | | |
5190 | 50.5k | if (reptype == REPTYPE_POS) |
5191 | 9.31k | continue; // No backtracking |
5192 | | |
5193 | | /* We use <= Lstart_eptr rather than == Lstart_eptr to detect the start |
5194 | | of the run while backtracking because the use of \C in UTF mode can |
5195 | | cause BACKCHAR to move back past Lstart_eptr. This is just palliative; |
5196 | | the use of \C in UTF mode is fraught with danger. */ |
5197 | | |
5198 | 41.2k | for (;;) |
5199 | 263k | { |
5200 | 263k | int lgb, rgb; |
5201 | 263k | PCRE2_SPTR fptr; |
5202 | | |
5203 | 263k | if (Feptr <= Lstart_eptr) |
5204 | 32.4k | break; // At start of char run |
5205 | 231k | RMATCH(Fecode, RM219); |
5206 | 227k | if (rrc != MATCH_NOMATCH) |
5207 | 5.25k | RRETURN(rrc); |
5208 | | |
5209 | | /* Backtracking over an extended grapheme cluster involves inspecting |
5210 | | the previous two characters (if present) to see if a break is |
5211 | | permitted between them. */ |
5212 | | |
5213 | 222k | Feptr--; |
5214 | 222k | if (!utf) |
5215 | 180k | { |
5216 | 180k | fc = *Feptr; |
5217 | 180k | } |
5218 | 42.4k | else |
5219 | 42.4k | { |
5220 | 42.4k | BACKCHAR(Feptr); |
5221 | 42.4k | GETCHAR(fc, Feptr); |
5222 | 42.4k | } |
5223 | | |
5224 | 222k | rgb = UCD_GRAPHBREAK(fc); |
5225 | | |
5226 | 222k | for (;;) |
5227 | 226k | { |
5228 | 226k | if (Feptr <= Lstart_eptr) |
5229 | 24.9k | break; // At start of char run |
5230 | 201k | fptr = Feptr - 1; |
5231 | 201k | if (!utf) |
5232 | 163k | { |
5233 | 163k | fc = *fptr; |
5234 | 163k | } |
5235 | 38.2k | else |
5236 | 38.2k | { |
5237 | 38.2k | BACKCHAR(fptr); |
5238 | 38.2k | GETCHAR(fc, fptr); |
5239 | 38.2k | } |
5240 | | |
5241 | 201k | lgb = UCD_GRAPHBREAK(fc); |
5242 | 201k | if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) |
5243 | 197k | break; |
5244 | 3.76k | Feptr = fptr; |
5245 | 3.76k | rgb = lgb; |
5246 | 3.76k | } |
5247 | 222k | } |
5248 | 41.2k | } |
5249 | | |
5250 | 1.23M | else |
5251 | 1.23M | #endif /* SUPPORT_UNICODE */ |
5252 | | |
5253 | 1.23M | #ifdef SUPPORT_UNICODE |
5254 | 1.23M | if (utf) |
5255 | 211k | { |
5256 | 211k | switch (Lctype) |
5257 | 211k | { |
5258 | 22.4k | case OP_ANY: |
5259 | 117k | for (i = Lmin; i < Lmax; i++) |
5260 | 114k | { |
5261 | 114k | if (Feptr >= mb->end_subject) |
5262 | 18.7k | { |
5263 | 18.7k | SCHECK_PARTIAL(); |
5264 | 18.6k | break; |
5265 | 18.7k | } |
5266 | | |
5267 | 95.6k | if (IS_NEWLINE(Feptr)) |
5268 | 682 | break; |
5269 | 94.9k | if (mb->partial != 0 && // Take care with CRLF partial |
5270 | 28.1k | Feptr + 1 >= mb->end_subject && NLBLOCK->nltype == NLTYPE_FIXED && |
5271 | 3.58k | NLBLOCK->nllen == 2 && *Feptr == NLBLOCK->nl[0]) |
5272 | 0 | { |
5273 | 0 | mb->hitend = TRUE; |
5274 | 0 | if (mb->partial > 1) |
5275 | 0 | return PCRE2_ERROR_PARTIAL; |
5276 | 0 | } |
5277 | | |
5278 | 94.9k | Feptr++; |
5279 | 94.9k | ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); |
5280 | 94.9k | } |
5281 | | |
5282 | 22.4k | break; |
5283 | | |
5284 | 22.4k | case OP_ALLANY: |
5285 | 18.0k | if (Lmax < UINT32_MAX) |
5286 | 6.24k | { |
5287 | 12.6k | for (i = Lmin; i < Lmax; i++) |
5288 | 8.74k | { |
5289 | 8.74k | if (Feptr >= mb->end_subject) |
5290 | 2.33k | { |
5291 | 2.33k | SCHECK_PARTIAL(); |
5292 | 2.31k | break; |
5293 | 2.33k | } |
5294 | | |
5295 | 6.41k | Feptr++; |
5296 | 6.41k | ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++); |
5297 | 6.41k | } |
5298 | 6.24k | } |
5299 | 11.7k | else |
5300 | 11.7k | { |
5301 | 11.7k | Feptr = mb->end_subject; // Unlimited UTF-8 repeat |
5302 | 11.7k | SCHECK_PARTIAL(); |
5303 | 11.7k | } |
5304 | | |
5305 | 18.0k | break; |
5306 | | |
5307 | | /* The "byte" (i.e. "code unit") case is the same as non-UTF */ |
5308 | | |
5309 | 18.0k | case OP_ANYBYTE: |
5310 | 0 | fc = Lmax - Lmin; |
5311 | 0 | if (fc > (uint32_t)(mb->end_subject - Feptr)) |
5312 | 0 | { |
5313 | 0 | Feptr = mb->end_subject; |
5314 | 0 | SCHECK_PARTIAL(); |
5315 | 0 | } |
5316 | 0 | else |
5317 | 0 | { |
5318 | 0 | Feptr += fc; |
5319 | 0 | } |
5320 | | |
5321 | 0 | break; |
5322 | | |
5323 | 55.9k | case OP_ANYNL: |
5324 | 60.9k | for (i = Lmin; i < Lmax; i++) |
5325 | 59.9k | { |
5326 | 59.9k | int len = 1; |
5327 | 59.9k | if (Feptr >= mb->end_subject) |
5328 | 4.97k | { |
5329 | 4.97k | SCHECK_PARTIAL(); |
5330 | 4.94k | break; |
5331 | 4.97k | } |
5332 | | |
5333 | 54.9k | GETCHARLEN(fc, Feptr, len); |
5334 | 54.9k | if (fc == CHAR_CR) |
5335 | 1.72k | { |
5336 | 1.72k | if (++Feptr >= mb->end_subject) |
5337 | 810 | break; |
5338 | 912 | if (*Feptr == CHAR_LF) |
5339 | 336 | Feptr++; |
5340 | 912 | } |
5341 | 53.2k | else |
5342 | 53.2k | { |
5343 | 53.2k | if (fc != CHAR_LF && (mb->bsr_convention == PCRE2_BSR_ANYCRLF || |
5344 | 51.6k | (fc != CHAR_VT && fc != CHAR_FF && fc != CHAR_NEL |
5345 | 50.2k | #ifndef EBCDIC |
5346 | 50.2k | && fc != 0x2028 && fc != 0x2029 |
5347 | 51.6k | #endif /* Not EBCDIC */ |
5348 | 51.6k | ))) |
5349 | 49.1k | break; |
5350 | 4.10k | Feptr += len; |
5351 | 4.10k | } |
5352 | 54.9k | } |
5353 | | |
5354 | 55.9k | break; |
5355 | | |
5356 | 55.9k | case OP_NOT_HSPACE: |
5357 | 39.1k | case OP_HSPACE: |
5358 | 195k | for (i = Lmin; i < Lmax; i++) |
5359 | 193k | { |
5360 | 193k | BOOL gotspace; |
5361 | 193k | int len = 1; |
5362 | 193k | if (Feptr >= mb->end_subject) |
5363 | 10.1k | { |
5364 | 10.1k | SCHECK_PARTIAL(); |
5365 | 10.0k | break; |
5366 | 10.1k | } |
5367 | | |
5368 | 183k | GETCHARLEN(fc, Feptr, len); |
5369 | 183k | switch (fc) |
5370 | 183k | { |
5371 | 16.7k | HSPACE_CASES: |
5372 | 16.7k | gotspace = TRUE; |
5373 | 16.7k | break; |
5374 | 166k | default: |
5375 | 166k | gotspace = FALSE; |
5376 | 166k | break; |
5377 | 183k | } |
5378 | | |
5379 | 183k | if (gotspace == (Lctype == OP_NOT_HSPACE)) |
5380 | 26.7k | break; |
5381 | 156k | Feptr += len; |
5382 | 156k | } |
5383 | | |
5384 | 39.0k | break; |
5385 | | |
5386 | 39.0k | case OP_NOT_VSPACE: |
5387 | 16.0k | case OP_VSPACE: |
5388 | 48.7k | for (i = Lmin; i < Lmax; i++) |
5389 | 47.6k | { |
5390 | 47.6k | BOOL gotspace; |
5391 | 47.6k | int len = 1; |
5392 | 47.6k | if (Feptr >= mb->end_subject) |
5393 | 6.63k | { |
5394 | 6.63k | SCHECK_PARTIAL(); |
5395 | 6.58k | break; |
5396 | 6.63k | } |
5397 | | |
5398 | 41.0k | GETCHARLEN(fc, Feptr, len); |
5399 | 41.0k | switch (fc) |
5400 | 41.0k | { |
5401 | 6.16k | VSPACE_CASES: |
5402 | 6.16k | gotspace = TRUE; |
5403 | 6.16k | break; |
5404 | 34.8k | default: |
5405 | 34.8k | gotspace = FALSE; |
5406 | 34.8k | break; |
5407 | 41.0k | } |
5408 | | |
5409 | 41.0k | if (gotspace == (Lctype == OP_NOT_VSPACE)) |
5410 | 8.40k | break; |
5411 | 32.6k | Feptr += len; |
5412 | 32.6k | } |
5413 | | |
5414 | 16.0k | break; |
5415 | | |
5416 | 16.0k | case OP_NOT_DIGIT: |
5417 | 50.3k | for (i = Lmin; i < Lmax; i++) |
5418 | 47.6k | { |
5419 | 47.6k | int len = 1; |
5420 | 47.6k | if (Feptr >= mb->end_subject) |
5421 | 4.97k | { |
5422 | 4.97k | SCHECK_PARTIAL(); |
5423 | 4.95k | break; |
5424 | 4.97k | } |
5425 | | |
5426 | 42.6k | GETCHARLEN(fc, Feptr, len); |
5427 | 42.6k | if (fc < 256 && (mb->ctypes[fc] & ctype_digit) != 0) |
5428 | 1.51k | break; |
5429 | 41.1k | Feptr += len; |
5430 | 41.1k | } |
5431 | | |
5432 | 9.23k | break; |
5433 | | |
5434 | 11.9k | case OP_DIGIT: |
5435 | 12.8k | for (i = Lmin; i < Lmax; i++) |
5436 | 12.2k | { |
5437 | 12.2k | int len = 1; |
5438 | 12.2k | if (Feptr >= mb->end_subject) |
5439 | 2.37k | { |
5440 | 2.37k | SCHECK_PARTIAL(); |
5441 | 2.37k | break; |
5442 | 2.37k | } |
5443 | | |
5444 | 9.90k | GETCHARLEN(fc, Feptr, len); |
5445 | 9.90k | if (fc >= 256 || (mb->ctypes[fc] & ctype_digit) == 0) |
5446 | 9.03k | break; |
5447 | 868 | Feptr += len; |
5448 | 868 | } |
5449 | | |
5450 | 11.9k | break; |
5451 | | |
5452 | 11.9k | case OP_NOT_WHITESPACE: |
5453 | 47.4k | for (i = Lmin; i < Lmax; i++) |
5454 | 43.1k | { |
5455 | 43.1k | int len = 1; |
5456 | 43.1k | if (Feptr >= mb->end_subject) |
5457 | 5.17k | { |
5458 | 5.17k | SCHECK_PARTIAL(); |
5459 | 5.16k | break; |
5460 | 5.17k | } |
5461 | | |
5462 | 37.9k | GETCHARLEN(fc, Feptr, len); |
5463 | 37.9k | if (fc < 256 && (mb->ctypes[fc] & ctype_space) != 0) |
5464 | 1.86k | break; |
5465 | 36.1k | Feptr += len; |
5466 | 36.1k | } |
5467 | | |
5468 | 11.3k | break; |
5469 | | |
5470 | 11.3k | case OP_WHITESPACE: |
5471 | 11.0k | for (i = Lmin; i < Lmax; i++) |
5472 | 10.8k | { |
5473 | 10.8k | int len = 1; |
5474 | 10.8k | if (Feptr >= mb->end_subject) |
5475 | 2.10k | { |
5476 | 2.10k | SCHECK_PARTIAL(); |
5477 | 2.09k | break; |
5478 | 2.10k | } |
5479 | | |
5480 | 8.77k | GETCHARLEN(fc, Feptr, len); |
5481 | 8.77k | if (fc >= 256 || (mb->ctypes[fc] & ctype_space) == 0) |
5482 | 8.27k | break; |
5483 | 495 | Feptr += len; |
5484 | 495 | } |
5485 | | |
5486 | 10.5k | break; |
5487 | | |
5488 | 10.5k | case OP_NOT_WORDCHAR: |
5489 | 19.0k | for (i = Lmin; i < Lmax; i++) |
5490 | 18.0k | { |
5491 | 18.0k | int len = 1; |
5492 | 18.0k | if (Feptr >= mb->end_subject) |
5493 | 3.25k | { |
5494 | 3.25k | SCHECK_PARTIAL(); |
5495 | 3.25k | break; |
5496 | 3.25k | } |
5497 | | |
5498 | 14.7k | GETCHARLEN(fc, Feptr, len); |
5499 | 14.7k | if (fc < 256 && (mb->ctypes[fc] & ctype_word) != 0) |
5500 | 3.21k | break; |
5501 | 11.5k | Feptr += len; |
5502 | 11.5k | } |
5503 | | |
5504 | 7.44k | break; |
5505 | | |
5506 | 8.77k | case OP_WORDCHAR: |
5507 | 11.5k | for (i = Lmin; i < Lmax; i++) |
5508 | 11.1k | { |
5509 | 11.1k | int len = 1; |
5510 | 11.1k | if (Feptr >= mb->end_subject) |
5511 | 2.19k | { |
5512 | 2.19k | SCHECK_PARTIAL(); |
5513 | 2.18k | break; |
5514 | 2.19k | } |
5515 | | |
5516 | 8.91k | GETCHARLEN(fc, Feptr, len); |
5517 | 8.91k | if (fc >= 256 || (mb->ctypes[fc] & ctype_word) == 0) |
5518 | 6.10k | break; |
5519 | 2.80k | Feptr += len; |
5520 | 2.80k | } |
5521 | | |
5522 | 8.77k | break; |
5523 | | |
5524 | | /* LCOV_EXCL_START */ |
5525 | 8.77k | default: |
5526 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
5527 | 0 | return PCRE2_ERROR_INTERNAL; |
5528 | | /* LCOV_EXCL_STOP */ |
5529 | 211k | } |
5530 | | |
5531 | 210k | if (reptype == REPTYPE_POS) |
5532 | 79.6k | continue; // No backtracking |
5533 | | |
5534 | | /* After \C in UTF mode, Lstart_eptr might be in the middle of a |
5535 | | Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't go |
5536 | | too far. */ |
5537 | | |
5538 | 131k | for (;;) |
5539 | 389k | { |
5540 | 389k | if (Feptr <= Lstart_eptr) |
5541 | 128k | break; |
5542 | 261k | RMATCH(Fecode, RM220); |
5543 | 259k | if (rrc != MATCH_NOMATCH) |
5544 | 1.09k | RRETURN(rrc); |
5545 | 258k | Feptr--; |
5546 | 258k | BACKCHAR(Feptr); |
5547 | 258k | if (Lctype == OP_ANYNL && Feptr > Lstart_eptr && *Feptr == CHAR_NL && |
5548 | 803 | Feptr[-1] == CHAR_CR) |
5549 | 300 | Feptr--; |
5550 | 258k | } |
5551 | 131k | } |
5552 | 1.02M | else |
5553 | 1.02M | #endif /* SUPPORT_UNICODE */ |
5554 | | |
5555 | | /* Not UTF mode */ |
5556 | 1.02M | { |
5557 | 1.02M | switch (Lctype) |
5558 | 1.02M | { |
5559 | 102k | case OP_ANY: |
5560 | 782k | for (i = Lmin; i < Lmax; i++) |
5561 | 767k | { |
5562 | 767k | if (Feptr >= mb->end_subject) |
5563 | 80.2k | { |
5564 | 80.2k | SCHECK_PARTIAL(); |
5565 | 79.7k | break; |
5566 | 80.2k | } |
5567 | | |
5568 | 686k | if (IS_NEWLINE(Feptr)) |
5569 | 6.01k | break; |
5570 | 680k | if (mb->partial != 0 && // Take care with CRLF partial |
5571 | 177k | Feptr + 1 >= mb->end_subject && NLBLOCK->nltype == NLTYPE_FIXED && |
5572 | 15.3k | NLBLOCK->nllen == 2 && *Feptr == NLBLOCK->nl[0]) |
5573 | 0 | { |
5574 | 0 | mb->hitend = TRUE; |
5575 | 0 | if (mb->partial > 1) |
5576 | 0 | return PCRE2_ERROR_PARTIAL; |
5577 | 0 | } |
5578 | | |
5579 | 680k | Feptr++; |
5580 | 680k | } |
5581 | | |
5582 | 101k | break; |
5583 | | |
5584 | 101k | case OP_ALLANY: |
5585 | 14.0k | case OP_ANYBYTE: |
5586 | 14.0k | fc = Lmax - Lmin; |
5587 | 14.0k | if (fc > (uint32_t)(mb->end_subject - Feptr)) |
5588 | 11.1k | { |
5589 | 11.1k | Feptr = mb->end_subject; |
5590 | 11.1k | SCHECK_PARTIAL(); |
5591 | 11.1k | } |
5592 | 2.87k | else |
5593 | 2.87k | { |
5594 | 2.87k | Feptr += fc; |
5595 | 2.87k | } |
5596 | | |
5597 | 13.9k | break; |
5598 | | |
5599 | 107k | case OP_ANYNL: |
5600 | 123k | for (i = Lmin; i < Lmax; i++) |
5601 | 121k | { |
5602 | 121k | if (Feptr >= mb->end_subject) |
5603 | 12.3k | { |
5604 | 12.3k | SCHECK_PARTIAL(); |
5605 | 12.2k | break; |
5606 | 12.3k | } |
5607 | | |
5608 | 108k | fc = *Feptr; |
5609 | 108k | if (fc == CHAR_CR) |
5610 | 4.02k | { |
5611 | 4.02k | if (++Feptr >= mb->end_subject) |
5612 | 1.09k | break; |
5613 | 2.92k | if (*Feptr == CHAR_LF) |
5614 | 1.29k | Feptr++; |
5615 | 2.92k | } |
5616 | 104k | else |
5617 | 104k | { |
5618 | 104k | if (fc != CHAR_LF && (mb->bsr_convention == PCRE2_BSR_ANYCRLF || |
5619 | 100k | (fc != CHAR_VT && fc != CHAR_FF && fc != CHAR_NEL |
5620 | 96.1k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
5621 | 96.1k | && fc != 0x2028 && fc != 0x2029 |
5622 | 100k | #endif |
5623 | 100k | ))) |
5624 | 92.1k | break; |
5625 | 12.7k | Feptr++; |
5626 | 12.7k | } |
5627 | 108k | } |
5628 | | |
5629 | 107k | break; |
5630 | | |
5631 | 107k | case OP_NOT_HSPACE: |
5632 | 713k | for (i = Lmin; i < Lmax; i++) |
5633 | 709k | { |
5634 | 709k | if (Feptr >= mb->end_subject) |
5635 | 29.2k | { |
5636 | 29.2k | SCHECK_PARTIAL(); |
5637 | 28.9k | break; |
5638 | 29.2k | } |
5639 | | |
5640 | 679k | switch (*Feptr) |
5641 | 679k | { |
5642 | 631k | default: |
5643 | 631k | Feptr++; |
5644 | 631k | break; |
5645 | 16.0k | HSPACE_BYTE_CASES: |
5646 | 16.0k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
5647 | 464k | HSPACE_MULTIBYTE_CASES: |
5648 | 464k | #endif |
5649 | 464k | goto ENDLOOP00; |
5650 | 679k | } |
5651 | 679k | } |
5652 | | |
5653 | 81.9k | ENDLOOP00: |
5654 | 81.9k | break; |
5655 | | |
5656 | 89.0k | case OP_HSPACE: |
5657 | 103k | for (i = Lmin; i < Lmax; i++) |
5658 | 93.3k | { |
5659 | 93.3k | if (Feptr >= mb->end_subject) |
5660 | 11.1k | { |
5661 | 11.1k | SCHECK_PARTIAL(); |
5662 | 10.9k | break; |
5663 | 11.1k | } |
5664 | | |
5665 | 82.2k | switch (*Feptr) |
5666 | 82.2k | { |
5667 | 68.1k | default: |
5668 | 68.1k | goto ENDLOOP01; |
5669 | 68.1k | HSPACE_BYTE_CASES: |
5670 | 4.04k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
5671 | 136k | HSPACE_MULTIBYTE_CASES: |
5672 | 136k | #endif |
5673 | 136k | Feptr++; |
5674 | 136k | break; |
5675 | 82.2k | } |
5676 | 82.2k | } |
5677 | | |
5678 | 88.9k | ENDLOOP01: |
5679 | 88.9k | break; |
5680 | | |
5681 | 33.5k | case OP_NOT_VSPACE: |
5682 | 140k | for (i = Lmin; i < Lmax; i++) |
5683 | 132k | { |
5684 | 132k | if (Feptr >= mb->end_subject) |
5685 | 11.8k | { |
5686 | 11.8k | SCHECK_PARTIAL(); |
5687 | 11.7k | break; |
5688 | 11.8k | } |
5689 | | |
5690 | 120k | switch (*Feptr) |
5691 | 120k | { |
5692 | 107k | default: |
5693 | 107k | Feptr++; |
5694 | 107k | break; |
5695 | 28.0k | VSPACE_BYTE_CASES: |
5696 | 28.0k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
5697 | 28.0k | VSPACE_MULTIBYTE_CASES: |
5698 | 26.1k | #endif |
5699 | 26.1k | goto ENDLOOP02; |
5700 | 120k | } |
5701 | 120k | } |
5702 | | |
5703 | 33.4k | ENDLOOP02: |
5704 | 33.4k | break; |
5705 | | |
5706 | 38.3k | case OP_VSPACE: |
5707 | 43.3k | for (i = Lmin; i < Lmax; i++) |
5708 | 42.5k | { |
5709 | 42.5k | if (Feptr >= mb->end_subject) |
5710 | 7.43k | { |
5711 | 7.43k | SCHECK_PARTIAL(); |
5712 | 7.38k | break; |
5713 | 7.43k | } |
5714 | | |
5715 | 35.1k | switch (*Feptr) |
5716 | 35.1k | { |
5717 | 30.1k | default: |
5718 | 30.1k | goto ENDLOOP03; |
5719 | 30.1k | VSPACE_BYTE_CASES: |
5720 | 11.2k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
5721 | 11.2k | VSPACE_MULTIBYTE_CASES: |
5722 | 9.06k | #endif |
5723 | 9.06k | Feptr++; |
5724 | 9.06k | break; |
5725 | 35.1k | } |
5726 | 35.1k | } |
5727 | | |
5728 | 38.3k | ENDLOOP03: |
5729 | 38.3k | break; |
5730 | | |
5731 | 46.6k | case OP_NOT_DIGIT: |
5732 | 333k | for (i = Lmin; i < Lmax; i++) |
5733 | 323k | { |
5734 | 323k | if (Feptr >= mb->end_subject) |
5735 | 25.8k | { |
5736 | 25.8k | SCHECK_PARTIAL(); |
5737 | 25.6k | break; |
5738 | 25.8k | } |
5739 | | |
5740 | 297k | if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_digit) != 0) |
5741 | 10.9k | break; |
5742 | 286k | Feptr++; |
5743 | 286k | } |
5744 | | |
5745 | 46.5k | break; |
5746 | | |
5747 | 109k | case OP_DIGIT: |
5748 | 115k | for (i = Lmin; i < Lmax; i++) |
5749 | 110k | { |
5750 | 110k | if (Feptr >= mb->end_subject) |
5751 | 4.56k | { |
5752 | 4.56k | SCHECK_PARTIAL(); |
5753 | 4.53k | break; |
5754 | 4.56k | } |
5755 | | |
5756 | 105k | if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_digit) == 0) |
5757 | 100k | break; |
5758 | 5.60k | Feptr++; |
5759 | 5.60k | } |
5760 | | |
5761 | 109k | break; |
5762 | | |
5763 | 109k | case OP_NOT_WHITESPACE: |
5764 | 618k | for (i = Lmin; i < Lmax; i++) |
5765 | 592k | { |
5766 | 592k | if (Feptr >= mb->end_subject) |
5767 | 50.5k | { |
5768 | 50.5k | SCHECK_PARTIAL(); |
5769 | 50.0k | break; |
5770 | 50.5k | } |
5771 | | |
5772 | 541k | if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_space) != 0) |
5773 | 16.2k | break; |
5774 | 525k | Feptr++; |
5775 | 525k | } |
5776 | | |
5777 | 92.3k | break; |
5778 | | |
5779 | 151k | case OP_WHITESPACE: |
5780 | 155k | for (i = Lmin; i < Lmax; i++) |
5781 | 151k | { |
5782 | 151k | if (Feptr >= mb->end_subject) |
5783 | 6.70k | { |
5784 | 6.70k | SCHECK_PARTIAL(); |
5785 | 6.67k | break; |
5786 | 6.70k | } |
5787 | | |
5788 | 145k | if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_space) == 0) |
5789 | 141k | break; |
5790 | 3.83k | Feptr++; |
5791 | 3.83k | } |
5792 | | |
5793 | 151k | break; |
5794 | | |
5795 | 151k | case OP_NOT_WORDCHAR: |
5796 | 337k | for (i = Lmin; i < Lmax; i++) |
5797 | 268k | { |
5798 | 268k | if (Feptr >= mb->end_subject) |
5799 | 9.65k | { |
5800 | 9.65k | SCHECK_PARTIAL(); |
5801 | 9.59k | break; |
5802 | 9.65k | } |
5803 | | |
5804 | 258k | if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_word) != 0) |
5805 | 38.4k | break; |
5806 | 220k | Feptr++; |
5807 | 220k | } |
5808 | | |
5809 | 116k | break; |
5810 | | |
5811 | 116k | case OP_WORDCHAR: |
5812 | 46.0k | for (i = Lmin; i < Lmax; i++) |
5813 | 44.9k | { |
5814 | 44.9k | if (Feptr >= mb->end_subject) |
5815 | 8.35k | { |
5816 | 8.35k | SCHECK_PARTIAL(); |
5817 | 8.32k | break; |
5818 | 8.35k | } |
5819 | | |
5820 | 36.5k | if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_word) == 0) |
5821 | 27.7k | break; |
5822 | 8.79k | Feptr++; |
5823 | 8.79k | } |
5824 | | |
5825 | 37.2k | break; |
5826 | | |
5827 | | /* LCOV_EXCL_START */ |
5828 | 37.2k | default: |
5829 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
5830 | 0 | return PCRE2_ERROR_INTERNAL; |
5831 | | /* LCOV_EXCL_STOP */ |
5832 | 1.02M | } |
5833 | | |
5834 | 1.01M | if (reptype == REPTYPE_POS) |
5835 | 552k | continue; // No backtracking |
5836 | | |
5837 | 467k | for (;;) |
5838 | 1.93M | { |
5839 | 1.93M | if (Feptr == Lstart_eptr) |
5840 | 454k | break; |
5841 | 1.48M | RMATCH(Fecode, RM34); |
5842 | 1.47M | if (rrc != MATCH_NOMATCH) |
5843 | 3.71k | RRETURN(rrc); |
5844 | 1.47M | Feptr--; |
5845 | 1.47M | if (Lctype == OP_ANYNL && Feptr > Lstart_eptr && *Feptr == CHAR_LF && |
5846 | 1.59k | Feptr[-1] == CHAR_CR) |
5847 | 639 | Feptr--; |
5848 | 1.47M | } |
5849 | 467k | } |
5850 | 1.65M | } |
5851 | | |
5852 | 869k | break; // End of repeat character type processing |
5853 | | |
5854 | 869k | #undef Lstart_eptr |
5855 | 869k | #undef Lmin |
5856 | 869k | #undef Lmax |
5857 | 869k | #undef Lctype |
5858 | 869k | #undef Lpropvalue |
5859 | | |
5860 | | |
5861 | | /* ===================================================================== */ |
5862 | | /* Match a back reference, possibly repeatedly. Look past the end of the |
5863 | | item to see if there is repeat information following. The OP_REF and |
5864 | | OP_REFI opcodes are used for a reference to a numbered group or to a |
5865 | | non-duplicated named group. For a duplicated named group, OP_DNREF and |
5866 | | OP_DNREFI are used. In this case we must scan the list of groups to which |
5867 | | the name refers, and use the first one that is set. */ |
5868 | | |
5869 | 869k | #define Lstart F->fields.ref_repeat.start |
5870 | 1.29M | #define Loffset F->fields.ref_repeat.offset |
5871 | 869k | #define Llength F->fields.ref_repeat.length |
5872 | 869k | #define Lmin F->fields.ref_repeat.min |
5873 | 869k | #define Lmax F->fields.ref_repeat.max |
5874 | 869k | #define Lcaseless F->byte1 |
5875 | 869k | #define Lcaseopts F->byte2 |
5876 | | |
5877 | 869k | case OP_DNREF: |
5878 | 7.68k | case OP_DNREFI: |
5879 | 7.68k | Lcaseless = (uint8_t)(Fop == OP_DNREFI); |
5880 | 7.68k | Lcaseopts = (uint8_t)((Fop == OP_DNREFI) ? Fecode[1 + 2 * IMM2_SIZE] : 0); |
5881 | 7.68k | { |
5882 | 7.68k | int count = GET2(Fecode, 1 + IMM2_SIZE); |
5883 | 7.68k | PCRE2_SPTR slot = mb->name_table + GET2(Fecode, 1) * mb->name_entry_size; |
5884 | 7.68k | Fecode += 1 + 2 * IMM2_SIZE + (Fop == OP_DNREFI ? 1 : 0); |
5885 | | |
5886 | 30.4k | while (count-- > 0) |
5887 | 23.6k | { |
5888 | 23.6k | Loffset = (GET2(slot, 0) << 1) - 2; |
5889 | 23.6k | if (Loffset < Foffset_top && Fovector[Loffset] != PCRE2_UNSET) |
5890 | 840 | break; |
5891 | 22.8k | slot += mb->name_entry_size; |
5892 | 22.8k | } |
5893 | 7.68k | } |
5894 | | |
5895 | 7.68k | goto REF_REPEAT; |
5896 | | |
5897 | 201k | case OP_REF: |
5898 | 289k | case OP_REFI: |
5899 | 289k | Lcaseless = (Fop == OP_REFI); |
5900 | 289k | Lcaseopts = (Fop == OP_REFI) ? Fecode[1 + IMM2_SIZE] : 0; |
5901 | 289k | Loffset = (GET2(Fecode, 1) << 1) - 2; |
5902 | 289k | Fecode += 1 + IMM2_SIZE + (Fop == OP_REFI ? 1 : 0); |
5903 | | |
5904 | | /* Set up for repetition, or handle the non-repeated case. The maximum and |
5905 | | minimum must be in the heap frame, but as they are short-term values, we |
5906 | | use temporary fields. */ |
5907 | | |
5908 | 297k | REF_REPEAT: |
5909 | 297k | switch (*Fecode) |
5910 | 297k | { |
5911 | 44.3k | case OP_CRSTAR: |
5912 | 50.2k | case OP_CRMINSTAR: |
5913 | 75.9k | case OP_CRPLUS: |
5914 | 90.3k | case OP_CRMINPLUS: |
5915 | 95.8k | case OP_CRQUERY: |
5916 | 100k | case OP_CRMINQUERY: |
5917 | 101k | case OP_CRPOSSTAR: |
5918 | 106k | case OP_CRPOSPLUS: |
5919 | 106k | case OP_CRPOSQUERY: |
5920 | 106k | fc = *Fecode++ - OP_CRSTAR; |
5921 | 106k | Lmin = rep_min[fc]; |
5922 | 106k | Lmax = rep_max[fc]; |
5923 | 106k | reptype = rep_typ[fc]; |
5924 | 106k | break; |
5925 | | |
5926 | 44.4k | case OP_CRRANGE: |
5927 | 46.8k | case OP_CRMINRANGE: |
5928 | 50.7k | case OP_CRPOSRANGE: |
5929 | 50.7k | Lmin = GET2(Fecode, 1); |
5930 | 50.7k | Lmax = GET2(Fecode, 1 + IMM2_SIZE); |
5931 | 50.7k | reptype = rep_typ[*Fecode - OP_CRSTAR]; |
5932 | 50.7k | if (Lmax == 0) |
5933 | 2.71k | Lmax = UINT32_MAX; // Max 0 => infinity |
5934 | 50.7k | Fecode += 1 + 2 * IMM2_SIZE; |
5935 | 50.7k | break; |
5936 | | |
5937 | 139k | default: // No repeat follows |
5938 | 139k | { |
5939 | 139k | rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &length); |
5940 | 139k | if (rrc != 0) |
5941 | 121k | { |
5942 | 121k | if (rrc > 0) |
5943 | 4.77k | Feptr = mb->end_subject; // Partial match |
5944 | 121k | CHECK_PARTIAL(); |
5945 | 121k | RRETURN(MATCH_NOMATCH); |
5946 | 121k | } |
5947 | 139k | } |
5948 | | |
5949 | 17.8k | Feptr += length; |
5950 | 17.8k | continue; // With the main loop |
5951 | 297k | } |
5952 | | |
5953 | | /* Handle repeated back references. If a set group has length zero, just |
5954 | | continue with the main loop, because it matches however many times. For an |
5955 | | unset reference, if the minimum is zero, we can also just continue. We can |
5956 | | also continue if PCRE2_MATCH_UNSET_BACKREF is set, because this makes unset |
5957 | | group behave as a zero-length group. For any other unset cases, carrying |
5958 | | on will result in NOMATCH. */ |
5959 | | |
5960 | 157k | if (Loffset < Foffset_top && Fovector[Loffset] != PCRE2_UNSET) |
5961 | 135k | { |
5962 | 135k | if (Fovector[Loffset] == Fovector[Loffset + 1]) |
5963 | 11.7k | continue; |
5964 | 135k | } |
5965 | 21.9k | else // Group is not set |
5966 | 21.9k | { |
5967 | 21.9k | if (Lmin == 0 || (mb->poptions & PCRE2_MATCH_UNSET_BACKREF) != 0) |
5968 | 7.94k | continue; |
5969 | 21.9k | } |
5970 | | |
5971 | | /* First, ensure the minimum number of matches are present. */ |
5972 | | |
5973 | 151k | for (i = 1; i <= Lmin; i++) |
5974 | 96.3k | { |
5975 | 96.3k | PCRE2_SIZE slength; |
5976 | 96.3k | rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength); |
5977 | 96.3k | if (rrc != 0) |
5978 | 82.6k | { |
5979 | 82.6k | if (rrc > 0) |
5980 | 2.79k | Feptr = mb->end_subject; // Partial match |
5981 | 82.6k | CHECK_PARTIAL(); |
5982 | 82.6k | RRETURN(MATCH_NOMATCH); |
5983 | 82.6k | } |
5984 | | |
5985 | 13.7k | Feptr += slength; |
5986 | 13.7k | } |
5987 | | |
5988 | | /* If min = max, we are done. They are not both allowed to be zero. */ |
5989 | | |
5990 | 55.3k | if (Lmin == Lmax) |
5991 | 1.15k | continue; |
5992 | | |
5993 | | /* If minimizing, keep trying and advancing the pointer. */ |
5994 | | |
5995 | 54.1k | if (reptype == REPTYPE_MIN) |
5996 | 9.21k | { |
5997 | 9.21k | for (;;) |
5998 | 10.8k | { |
5999 | 10.8k | PCRE2_SIZE slength; |
6000 | 10.8k | RMATCH(Fecode, RM20); |
6001 | 10.7k | if (rrc != MATCH_NOMATCH) |
6002 | 212 | RRETURN(rrc); |
6003 | 10.5k | if (Lmin++ >= Lmax) |
6004 | 198 | RRETURN(MATCH_NOMATCH); |
6005 | 10.3k | rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength); |
6006 | 10.3k | if (rrc != 0) |
6007 | 8.69k | { |
6008 | 8.69k | if (rrc > 0) |
6009 | 588 | Feptr = mb->end_subject; // Partial match |
6010 | 8.69k | CHECK_PARTIAL(); |
6011 | 8.68k | RRETURN(MATCH_NOMATCH); |
6012 | 8.68k | } |
6013 | | |
6014 | 1.64k | Feptr += slength; |
6015 | 1.64k | } |
6016 | | |
6017 | 9.21k | PCRE2_UNREACHABLE(); // Control never reaches here |
6018 | 9.21k | } |
6019 | | |
6020 | | /* If maximizing, find the longest string and work backwards, as long as |
6021 | | the matched lengths for each iteration are the same. */ |
6022 | | |
6023 | 44.9k | else |
6024 | 44.9k | { |
6025 | 44.9k | BOOL samelengths = TRUE; |
6026 | 44.9k | Lstart = Feptr; // Starting position |
6027 | 44.9k | Llength = Fovector[Loffset + 1] - Fovector[Loffset]; |
6028 | | |
6029 | 50.0k | for (i = Lmin; i < Lmax; i++) |
6030 | 49.2k | { |
6031 | 49.2k | PCRE2_SIZE slength; |
6032 | 49.2k | rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength); |
6033 | 49.2k | if (rrc != 0) |
6034 | 44.1k | { |
6035 | | /* Can't use CHECK_PARTIAL because we don't want to update Feptr in |
6036 | | the soft partial matching case. */ |
6037 | | |
6038 | 44.1k | if (rrc > 0 && mb->partial != 0 && mb->end_subject > mb->start_used_ptr) |
6039 | 2.49k | { |
6040 | 2.49k | mb->hitend = TRUE; |
6041 | 2.49k | if (mb->partial > 1) |
6042 | 10 | return PCRE2_ERROR_PARTIAL; |
6043 | 2.49k | } |
6044 | | |
6045 | 44.1k | break; |
6046 | 44.1k | } |
6047 | | |
6048 | 5.07k | if (slength != Llength) |
6049 | 0 | samelengths = FALSE; |
6050 | 5.07k | Feptr += slength; |
6051 | 5.07k | } |
6052 | | |
6053 | | /* No recursion if the repeat type is possessive. */ |
6054 | 44.9k | if (reptype == REPTYPE_POS) |
6055 | 783 | break; |
6056 | | |
6057 | | /* If the length matched for each repetition is the same as the length of |
6058 | | the captured group, we can easily work backwards. This is the normal |
6059 | | case. However, in caseless UTF-8 mode there are pairs of case-equivalent |
6060 | | characters whose lengths (in terms of code units) differ. However, this |
6061 | | is very rare, so we handle it by re-matching fewer and fewer times. */ |
6062 | | |
6063 | 44.1k | if (samelengths) |
6064 | 44.1k | { |
6065 | 89.9k | while (Feptr >= Lstart) |
6066 | 49.1k | { |
6067 | 49.1k | RMATCH(Fecode, RM21); |
6068 | 48.9k | if (rrc != MATCH_NOMATCH) |
6069 | 3.13k | RRETURN(rrc); |
6070 | 45.7k | Feptr -= Llength; |
6071 | 45.7k | } |
6072 | 44.1k | } |
6073 | | |
6074 | | /* The rare case of non-matching lengths. Re-scan the repetition for each |
6075 | | iteration. We know that match_ref() will succeed every time. */ |
6076 | | |
6077 | 0 | else |
6078 | 0 | { |
6079 | 0 | Lmax = i; |
6080 | 0 | for (;;) |
6081 | 0 | { |
6082 | 0 | RMATCH(Fecode, RM22); |
6083 | 0 | if (rrc != MATCH_NOMATCH) |
6084 | 0 | RRETURN(rrc); |
6085 | 0 | if (Feptr == Lstart) |
6086 | 0 | break; // Failed after minimal repetition |
6087 | 0 | Feptr = Lstart; |
6088 | 0 | Lmax--; |
6089 | 0 | for (i = Lmin; i < Lmax; i++) |
6090 | 0 | { |
6091 | 0 | PCRE2_SIZE slength; |
6092 | 0 | (void)match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength); |
6093 | 0 | Feptr += slength; |
6094 | 0 | } |
6095 | 0 | } |
6096 | 0 | } |
6097 | | |
6098 | 40.7k | RRETURN(MATCH_NOMATCH); |
6099 | 40.7k | } |
6100 | | |
6101 | 0 | PCRE2_DEBUG_UNREACHABLE(); // Control should never reach here |
6102 | |
|
6103 | 0 | #undef Lstart |
6104 | 0 | #undef Loffset |
6105 | 0 | #undef Llength |
6106 | 0 | #undef Lmin |
6107 | 0 | #undef Lmax |
6108 | 0 | #undef Lcaseless |
6109 | 0 | #undef Lcaseopts |
6110 | | |
6111 | | |
6112 | | /* ========================================================================= */ |
6113 | | /* Opcodes for the start of various parenthesized items */ |
6114 | | /* ========================================================================= */ |
6115 | | |
6116 | | /* In all cases, if the result of RMATCH() is MATCH_THEN, check whether the |
6117 | | (*THEN) is within the current branch by comparing the address of OP_THEN |
6118 | | that is passed back with the end of the branch. If (*THEN) is within the |
6119 | | current branch, and the branch is one of two or more alternatives (it |
6120 | | either starts or ends with OP_ALT), we have reached the limit of THEN's |
6121 | | action, so convert the return code to NOMATCH, which will cause normal |
6122 | | backtracking to happen from now on. Otherwise, THEN is passed back to an |
6123 | | outer alternative. This implements Perl's treatment of parenthesized |
6124 | | groups, where a group not containing | does not affect the current |
6125 | | alternative, that is, (X) is NOT the same as (X|(*F)). */ |
6126 | | |
6127 | | |
6128 | | /* ===================================================================== */ |
6129 | | /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a non-possessive |
6130 | | bracket group, indicating that it may occur zero times. It may repeat |
6131 | | infinitely, or not at all - i.e. it could be ()* or ()? or even (){0} in |
6132 | | the pattern. Brackets with fixed upper repeat limits are compiled as a |
6133 | | number of copies, with the optional ones preceded by BRAZERO or BRAMINZERO. |
6134 | | Possessive groups with possible zero repeats are preceded by BRAPOSZERO. */ |
6135 | |
|
6136 | 132k | case OP_BRAZERO: |
6137 | 132k | { |
6138 | 132k | PCRE2_SPTR next_ecode; |
6139 | | |
6140 | 132k | Fecode++; |
6141 | 132k | RMATCH(Fecode, RM9); |
6142 | 82.0k | if (rrc != MATCH_NOMATCH) |
6143 | 3.29k | RRETURN(rrc); |
6144 | 78.7k | next_ecode = Fecode; |
6145 | 78.7k | do |
6146 | 86.5k | next_ecode += GET(next_ecode, 1); |
6147 | 86.5k | while (*next_ecode == OP_ALT); |
6148 | 78.7k | Fecode = next_ecode + 1 + LINK_SIZE; |
6149 | 78.7k | } |
6150 | | |
6151 | 0 | break; |
6152 | | |
6153 | 39.9k | case OP_BRAMINZERO: |
6154 | 39.9k | { |
6155 | 39.9k | PCRE2_SPTR next_ecode; |
6156 | | |
6157 | 39.9k | Fecode++; |
6158 | 39.9k | next_ecode = Fecode; |
6159 | 39.9k | do |
6160 | 42.6k | next_ecode += GET(next_ecode, 1); |
6161 | 42.6k | while (*next_ecode == OP_ALT); |
6162 | 39.9k | RMATCH(next_ecode + 1 + LINK_SIZE, RM10); |
6163 | 35.1k | if (rrc != MATCH_NOMATCH) |
6164 | 1.63k | RRETURN(rrc); |
6165 | 35.1k | } |
6166 | | |
6167 | 33.4k | break; |
6168 | | |
6169 | 61.9k | case OP_SKIPZERO: |
6170 | 61.9k | { |
6171 | 61.9k | PCRE2_SPTR next_ecode = Fecode + 1; |
6172 | 61.9k | do |
6173 | 64.0k | next_ecode += GET(next_ecode, 1); |
6174 | 64.0k | while (*next_ecode == OP_ALT); |
6175 | 61.9k | Fecode = next_ecode + 1 + LINK_SIZE; |
6176 | 61.9k | } |
6177 | | |
6178 | 61.9k | break; |
6179 | | |
6180 | | |
6181 | | /* ===================================================================== */ |
6182 | | /* Handle possessive brackets with an unlimited repeat. The end of these |
6183 | | brackets will always be OP_KETRPOS, which returns MATCH_KETRPOS without |
6184 | | going further in the pattern. */ |
6185 | | |
6186 | 493k | #define Lstart_eptr F->fields.op_brapos.start_eptr |
6187 | 400k | #define Lstart_group F->fields.op_brapos.start_group |
6188 | 796k | #define Lframe_type F->fields.op_brapos.frame_type |
6189 | 1.19M | #define Lmatched_once F->byte1 |
6190 | 687k | #define Lzero_allowed F->byte2 |
6191 | | |
6192 | 17.7k | case OP_BRAPOSZERO: |
6193 | 17.7k | Lzero_allowed = TRUE; // Zero repeat is allowed |
6194 | 17.7k | Fecode += 1; |
6195 | 17.7k | if (*Fecode == OP_CBRAPOS || *Fecode == OP_SCBRAPOS) |
6196 | 9.09k | goto POSSESSIVE_CAPTURE; |
6197 | 8.65k | goto POSSESSIVE_NON_CAPTURE; |
6198 | | |
6199 | 265k | case OP_BRAPOS: |
6200 | 276k | case OP_SBRAPOS: |
6201 | 276k | Lzero_allowed = FALSE; // Zero repeat not allowed |
6202 | | |
6203 | 285k | POSSESSIVE_NON_CAPTURE: |
6204 | 285k | Lframe_type = GF_NOCAPTURE; // Remembered frame type |
6205 | 285k | goto POSSESSIVE_GROUP; |
6206 | | |
6207 | 26.8k | case OP_CBRAPOS: |
6208 | 86.2k | case OP_SCBRAPOS: |
6209 | 86.2k | Lzero_allowed = FALSE; // Zero repeat not allowed |
6210 | | |
6211 | 95.3k | POSSESSIVE_CAPTURE: |
6212 | 95.3k | number = GET2(Fecode, 1 + LINK_SIZE); |
6213 | 95.3k | Lframe_type = GF_CAPTURE | number; // Remembered frame type |
6214 | | |
6215 | 380k | POSSESSIVE_GROUP: |
6216 | 380k | Lmatched_once = FALSE; // Never matched |
6217 | 380k | Lstart_group = Fecode; // Start of this group |
6218 | | |
6219 | 380k | for (;;) |
6220 | 416k | { |
6221 | 416k | Lstart_eptr = Feptr; // Position at group start |
6222 | 416k | group_frame_type = Lframe_type; |
6223 | 416k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM8); |
6224 | 407k | if (rrc == MATCH_KETRPOS) |
6225 | 77.6k | { |
6226 | 77.6k | Lmatched_once = TRUE; // Matched at least once |
6227 | 77.6k | if (Feptr == Lstart_eptr) // Empty match; skip to end |
6228 | 57.3k | { |
6229 | 57.3k | do |
6230 | 64.8k | Fecode += GET(Fecode, 1); |
6231 | 64.8k | while (*Fecode == OP_ALT); |
6232 | 57.3k | break; |
6233 | 57.3k | } |
6234 | | |
6235 | 20.2k | Fecode = Lstart_group; |
6236 | 20.2k | continue; |
6237 | 77.6k | } |
6238 | | |
6239 | | /* See comment above about handling THEN. */ |
6240 | | |
6241 | 329k | if (rrc == MATCH_THEN) |
6242 | 1.04k | { |
6243 | 1.04k | PCRE2_SPTR next_ecode = Fecode + GET(Fecode, 1); |
6244 | 1.04k | if (mb->verb_ecode_ptr < next_ecode && (*Fecode == OP_ALT || *next_ecode == OP_ALT)) |
6245 | 586 | rrc = MATCH_NOMATCH; |
6246 | 1.04k | } |
6247 | | |
6248 | 329k | if (rrc != MATCH_NOMATCH) |
6249 | 1.42k | RRETURN(rrc); |
6250 | 328k | Fecode += GET(Fecode, 1); |
6251 | 328k | if (*Fecode != OP_ALT) |
6252 | 312k | break; |
6253 | 328k | } |
6254 | | |
6255 | | /* Success if matched something or zero repeat allowed */ |
6256 | | |
6257 | 370k | if (Lmatched_once || Lzero_allowed) |
6258 | 72.7k | { |
6259 | 72.7k | Fecode += 1 + LINK_SIZE; |
6260 | 72.7k | break; |
6261 | 72.7k | } |
6262 | | |
6263 | 297k | RRETURN(MATCH_NOMATCH); |
6264 | | |
6265 | 0 | #undef Lstart_eptr |
6266 | 0 | #undef Lstart_group |
6267 | 0 | #undef Lframe_type |
6268 | 0 | #undef Lmatched_once |
6269 | 0 | #undef Lzero_allowed |
6270 | | |
6271 | | |
6272 | | /* ===================================================================== */ |
6273 | | /* Handle non-capturing brackets that cannot match an empty string. When we |
6274 | | get to the final alternative within the brackets, as long as there are no |
6275 | | THEN's in the pattern, we can optimize by not recording a new backtracking |
6276 | | point. (Ideally we should test for a THEN within this group, but we don't |
6277 | | have that information.) Don't do this if we are at the very top level, |
6278 | | however, because that would make handling assertions and once-only brackets |
6279 | | messier when there is nothing to go back to. */ |
6280 | | |
6281 | 13.8M | #define Lframe_type F->fields.op_bra.frame_type |
6282 | | |
6283 | 3.26M | case OP_BRA: |
6284 | 3.26M | if (mb->hasthen || Frdepth == 0) |
6285 | 2.49M | { |
6286 | 2.49M | Lframe_type = 0; |
6287 | 2.49M | goto GROUPLOOP; |
6288 | 2.49M | } |
6289 | | |
6290 | 767k | for (;;) |
6291 | 904k | { |
6292 | 904k | PCRE2_SPTR current_branch = Fecode; |
6293 | 904k | PCRE2_SPTR next_branch = current_branch + GET(current_branch, 1); |
6294 | | |
6295 | 904k | if (*next_branch != OP_ALT) |
6296 | 716k | break; |
6297 | | |
6298 | | /* This is never the final branch. We do not need to test for MATCH_THEN |
6299 | | here because this code is not used when there is a THEN in the pattern. */ |
6300 | | |
6301 | 188k | Fecode = next_branch; |
6302 | 188k | PCRE2_ASSERT((*current_branch == OP_BRA || *current_branch == OP_ALT) && |
6303 | 188k | PRIV(OP_lengths)[OP_BRA] == 1 + LINK_SIZE && |
6304 | 188k | PRIV(OP_lengths)[OP_ALT] == 1 + LINK_SIZE); |
6305 | | |
6306 | 188k | RMATCH(current_branch + 1 + LINK_SIZE, RM1); |
6307 | 150k | if (rrc != MATCH_NOMATCH) |
6308 | 13.3k | RRETURN(rrc); |
6309 | 150k | } |
6310 | | |
6311 | | /* Hit the start of the final branch. Continue at this level. */ |
6312 | | |
6313 | 716k | PCRE2_ASSERT((*Fecode == OP_BRA || *Fecode == OP_ALT) && |
6314 | 716k | PRIV(OP_lengths)[OP_BRA] == 1 + LINK_SIZE && |
6315 | 716k | PRIV(OP_lengths)[OP_ALT] == 1 + LINK_SIZE); |
6316 | 716k | Fecode += 1 + LINK_SIZE; |
6317 | 716k | break; |
6318 | | |
6319 | | |
6320 | | /* ===================================================================== */ |
6321 | | /* Handle a capturing bracket, other than those that are possessive with an |
6322 | | unlimited repeat. */ |
6323 | | |
6324 | 1.32M | case OP_CBRA: |
6325 | 1.35M | case OP_SCBRA: |
6326 | 1.35M | Lframe_type = GF_CAPTURE | GET2(Fecode, 1 + LINK_SIZE); |
6327 | 1.35M | goto GROUPLOOP; |
6328 | | |
6329 | | |
6330 | | /* ===================================================================== */ |
6331 | | /* Atomic groups and non-capturing brackets that can match an empty string |
6332 | | must record a backtracking point and also set up a chained frame. */ |
6333 | | |
6334 | 132k | case OP_ONCE: |
6335 | 192k | case OP_SCRIPT_RUN: |
6336 | 219k | case OP_SBRA: |
6337 | 219k | Lframe_type = GF_NOCAPTURE; |
6338 | | |
6339 | 4.06M | GROUPLOOP: |
6340 | 4.06M | for (;;) |
6341 | 9.77M | { |
6342 | 9.77M | group_frame_type = Lframe_type; |
6343 | 9.77M | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM2); |
6344 | 9.39M | if (rrc == MATCH_THEN) |
6345 | 16.0k | { |
6346 | 16.0k | PCRE2_SPTR next_ecode = Fecode + GET(Fecode, 1); |
6347 | 16.0k | if (mb->verb_ecode_ptr < next_ecode && (*Fecode == OP_ALT || *next_ecode == OP_ALT)) |
6348 | 3.41k | rrc = MATCH_NOMATCH; |
6349 | 16.0k | } |
6350 | | |
6351 | 9.39M | if (rrc != MATCH_NOMATCH) |
6352 | 140k | RRETURN(rrc); |
6353 | 9.25M | Fecode += GET(Fecode, 1); |
6354 | 9.25M | if (*Fecode != OP_ALT) |
6355 | 3.55M | RRETURN(MATCH_NOMATCH); |
6356 | 9.25M | } |
6357 | | |
6358 | 4.06M | PCRE2_UNREACHABLE(); // Control never reaches here |
6359 | | |
6360 | 0 | #undef Lframe_type |
6361 | | |
6362 | | |
6363 | | /* ===================================================================== */ |
6364 | | /* Pattern recursion either matches the current regex, or some |
6365 | | subexpression. The offset data is the offset to the starting bracket from |
6366 | | the start of the whole pattern. This is so that it works from duplicated |
6367 | | subpatterns. For a whole-pattern recursion, we have to infer the number |
6368 | | zero. */ |
6369 | | |
6370 | 1.43M | #define Lstart_branch F->fields.op_recurse.start_branch |
6371 | 1.34M | #define Lframe_type F->fields.op_recurse.frame_type |
6372 | | |
6373 | 607k | case OP_RECURSE: |
6374 | 607k | bracode = mb->start_code + GET(Fecode, 1); |
6375 | 607k | number = (bracode == mb->start_code) ? 0 : GET2(bracode, 1 + LINK_SIZE); |
6376 | | |
6377 | | /* If we are already in a pattern recursion, check for repeating the same |
6378 | | one without changing the subject pointer or the last referenced character |
6379 | | in the subject. This should catch convoluted mutual recursions; some |
6380 | | simple cases are caught at compile time. However, there are rare cases when |
6381 | | this check needs to be turned off. In this case, actual recursion loops |
6382 | | will be caught by the match or heap limits. */ |
6383 | | |
6384 | 607k | if (Fcurrent_recurse != RECURSE_UNSET) |
6385 | 513k | { |
6386 | 513k | offset = Flast_group_offset; |
6387 | 651k | while (offset != PCRE2_UNSET) |
6388 | 649k | { |
6389 | 649k | N = (heapframe *)((char *)match_data->heapframes + offset); |
6390 | 649k | P = (heapframe *)((char *)N - frame_size); |
6391 | 649k | if (N->group_frame_type == (GF_RECURSE | number)) |
6392 | 511k | { |
6393 | 511k | if (Feptr == P->eptr && mb->last_used_ptr == P->recurse_last_used && |
6394 | 440k | (mb->moptions & PCRE2_DISABLE_RECURSELOOP_CHECK) == 0) |
6395 | 0 | return PCRE2_ERROR_RECURSELOOP; |
6396 | 511k | break; |
6397 | 511k | } |
6398 | | |
6399 | 137k | offset = P->last_group_offset; |
6400 | 137k | } |
6401 | 513k | } |
6402 | | |
6403 | | /* Remember the current last referenced character and then run the |
6404 | | recursion branch by branch. */ |
6405 | | |
6406 | 607k | F->recurse_last_used = mb->last_used_ptr; |
6407 | 607k | Lstart_branch = bracode; |
6408 | 607k | Lframe_type = GF_RECURSE | number; |
6409 | | |
6410 | 607k | for (;;) |
6411 | 730k | { |
6412 | 730k | PCRE2_SPTR next_ecode; |
6413 | | |
6414 | 730k | group_frame_type = Lframe_type; |
6415 | 730k | RMATCH(Lstart_branch + PRIV(OP_lengths)[*Lstart_branch], RM11); |
6416 | 290k | next_ecode = Lstart_branch + GET(Lstart_branch, 1); |
6417 | | |
6418 | | /* Handle backtracking verbs, which are defined in a range that can |
6419 | | easily be tested for. PCRE does not allow THEN, SKIP, PRUNE or COMMIT to |
6420 | | escape beyond a recursion; they cause a NOMATCH for the entire recursion. |
6421 | | |
6422 | | When one of these verbs triggers, the current recursion group number is |
6423 | | recorded. If it matches the recursion we are processing, the verb |
6424 | | happened within the recursion and we must deal with it. Otherwise it must |
6425 | | have happened after the recursion completed, and so has to be passed |
6426 | | back. See comment above about handling THEN. */ |
6427 | | |
6428 | 290k | if (rrc >= MATCH_BACKTRACK_MIN && rrc <= MATCH_BACKTRACK_MAX && |
6429 | 3.90k | mb->verb_current_recurse == (Lframe_type ^ GF_RECURSE)) |
6430 | 3.05k | { |
6431 | 3.05k | if (rrc == MATCH_THEN && mb->verb_ecode_ptr < next_ecode && |
6432 | 2.09k | (*Lstart_branch == OP_ALT || *next_ecode == OP_ALT)) |
6433 | 981 | rrc = MATCH_NOMATCH; |
6434 | 2.07k | else |
6435 | 2.07k | RRETURN(MATCH_NOMATCH); |
6436 | 3.05k | } |
6437 | | |
6438 | | /* Note that carrying on after (*ACCEPT) in a recursion is handled in the |
6439 | | OP_ACCEPT code. Nothing needs to be done here. */ |
6440 | | |
6441 | 288k | if (rrc != MATCH_NOMATCH) |
6442 | 19.2k | RRETURN(rrc); |
6443 | 269k | Lstart_branch = next_ecode; |
6444 | 269k | if (*Lstart_branch != OP_ALT) |
6445 | 145k | RRETURN(MATCH_NOMATCH); |
6446 | 269k | } |
6447 | | |
6448 | 607k | PCRE2_UNREACHABLE(); // Control never reaches here |
6449 | | |
6450 | 0 | #undef Lstart_branch |
6451 | 0 | #undef Lframe_type |
6452 | | |
6453 | | |
6454 | | /* ===================================================================== */ |
6455 | | /* Positive assertions are like other groups except that PCRE doesn't allow |
6456 | | the effect of (*THEN) to escape beyond an assertion; it is therefore |
6457 | | treated as NOMATCH. (*ACCEPT) is treated as successful assertion, with its |
6458 | | captures and mark retained. Any other return is an error. */ |
6459 | | |
6460 | 175k | case OP_ASSERT: |
6461 | 254k | case OP_ASSERTBACK: |
6462 | 577k | case OP_ASSERT_NA: |
6463 | 632k | case OP_ASSERTBACK_NA: |
6464 | 632k | for (;;) |
6465 | 894k | { |
6466 | 894k | group_frame_type = GF_NOCAPTURE; |
6467 | 894k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM3); |
6468 | 668k | if (rrc == MATCH_ACCEPT) |
6469 | 6.55k | { |
6470 | 6.55k | memcpy(Fovector, (char *)assert_accept_frame + offsetof(heapframe, ovector), |
6471 | 6.55k | assert_accept_frame->offset_top * sizeof(PCRE2_SIZE)); |
6472 | 6.55k | Foffset_top = assert_accept_frame->offset_top; |
6473 | 6.55k | Fmark = assert_accept_frame->mark; |
6474 | 6.55k | break; |
6475 | 6.55k | } |
6476 | | |
6477 | 662k | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
6478 | 37.0k | RRETURN(rrc); |
6479 | 625k | Fecode += GET(Fecode, 1); |
6480 | 625k | if (*Fecode != OP_ALT) |
6481 | 363k | RRETURN(MATCH_NOMATCH); |
6482 | 625k | } |
6483 | | |
6484 | 6.55k | do |
6485 | 6.88k | Fecode += GET(Fecode, 1); |
6486 | 6.88k | while (*Fecode == OP_ALT); |
6487 | 6.55k | Fecode += 1 + LINK_SIZE; |
6488 | 6.55k | break; |
6489 | | |
6490 | | |
6491 | | /* ===================================================================== */ |
6492 | | /* Handle negative assertions. Loop for each non-matching branch as for |
6493 | | positive assertions. */ |
6494 | | |
6495 | 511k | case OP_ASSERT_NOT: |
6496 | 686k | case OP_ASSERTBACK_NOT: |
6497 | 686k | for (;;) |
6498 | 719k | { |
6499 | 719k | group_frame_type = GF_NOCAPTURE; |
6500 | 719k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM4); |
6501 | 705k | switch (rrc) |
6502 | 705k | { |
6503 | 2.45k | case MATCH_ACCEPT: // Assertion matched, therefore it fails. |
6504 | 40.2k | case MATCH_MATCH: |
6505 | 40.2k | RRETURN(MATCH_NOMATCH); |
6506 | | |
6507 | 657k | case MATCH_NOMATCH: // Branch failed, try next if present. |
6508 | 662k | case MATCH_THEN: |
6509 | 662k | Fecode += GET(Fecode, 1); |
6510 | 662k | if (*Fecode != OP_ALT) |
6511 | 629k | goto ASSERT_NOT_FAILED; |
6512 | 33.0k | break; |
6513 | | |
6514 | 33.0k | case MATCH_COMMIT: // Assertion forced to fail, therefore continue. |
6515 | 2.07k | case MATCH_SKIP: |
6516 | 2.39k | case MATCH_PRUNE: |
6517 | 2.39k | do |
6518 | 2.66k | Fecode += GET(Fecode, 1); |
6519 | 2.66k | while (*Fecode == OP_ALT); |
6520 | 2.39k | goto ASSERT_NOT_FAILED; |
6521 | | |
6522 | 546 | default: // Pass back any other return |
6523 | 546 | RRETURN(rrc); |
6524 | 705k | } |
6525 | 705k | } |
6526 | | |
6527 | | /* None of the branches have matched or there was a backtrack to (*COMMIT), |
6528 | | (*SKIP), (*PRUNE), or (*THEN) in the last branch. This is success for a |
6529 | | negative assertion, so carry on. */ |
6530 | | |
6531 | 631k | ASSERT_NOT_FAILED: |
6532 | 631k | Fecode += 1 + LINK_SIZE; |
6533 | 631k | break; |
6534 | | |
6535 | | |
6536 | | /* ===================================================================== */ |
6537 | | /* Handle scan substring operation. */ |
6538 | | |
6539 | 24.2k | #define Lsaved_end_subject F->fields.op_assert_scs.saved_end_subject |
6540 | 13.0k | #define Lsaved_eptr F->fields.op_assert_scs.saved_eptr |
6541 | 24.2k | #define Ltrue_end_extra F->fields.op_assert_scs.true_end_extra |
6542 | 0 | #define Lextra_size F->fields.op_assert_scs.extra_size |
6543 | 24.2k | #define Lsaved_moptions F->fields.op_assert_scs.saved_moptions |
6544 | | |
6545 | 26.4k | case OP_ASSERT_SCS: |
6546 | 26.4k | length = 0; |
6547 | 26.4k | { |
6548 | 26.4k | PCRE2_SPTR ecode = Fecode + 1 + LINK_SIZE; |
6549 | 26.4k | int count; |
6550 | 26.4k | PCRE2_SPTR slot; |
6551 | | |
6552 | | /* Disable compiler warning. */ |
6553 | 26.4k | offset = 0; |
6554 | 26.4k | (void)offset; |
6555 | | |
6556 | 26.4k | for (;;) |
6557 | 40.2k | { |
6558 | 40.2k | if (*ecode == OP_CREF) |
6559 | 12.3k | { |
6560 | 12.3k | length += 1 + IMM2_SIZE; |
6561 | 12.3k | offset = (GET2(ecode, 1) << 1) - 2; |
6562 | 12.3k | ecode += 1 + IMM2_SIZE; |
6563 | 12.3k | if (offset < Foffset_top && Fovector[offset] != PCRE2_UNSET) |
6564 | 6.64k | goto SCS_OFFSET_FOUND; |
6565 | 5.65k | continue; |
6566 | 12.3k | } |
6567 | | |
6568 | 27.9k | if (*ecode != OP_DNCREF) |
6569 | 13.7k | RRETURN(MATCH_NOMATCH); |
6570 | | |
6571 | 14.1k | count = GET2(ecode, 1 + IMM2_SIZE); |
6572 | 14.1k | slot = mb->name_table + GET2(ecode, 1) * mb->name_entry_size; |
6573 | 14.1k | length += 1 + 2 * IMM2_SIZE; |
6574 | 14.1k | ecode += 1 + 2 * IMM2_SIZE; |
6575 | | |
6576 | 35.1k | while (count > 0) |
6577 | 27.0k | { |
6578 | 27.0k | offset = (GET2(slot, 0) << 1) - 2; |
6579 | 27.0k | if (offset < Foffset_top && Fovector[offset] != PCRE2_UNSET) |
6580 | 6.06k | goto SCS_OFFSET_FOUND; |
6581 | 20.9k | slot += mb->name_entry_size; |
6582 | 20.9k | count--; |
6583 | 20.9k | } |
6584 | 14.1k | } |
6585 | | |
6586 | 12.7k | SCS_OFFSET_FOUND: |
6587 | | |
6588 | | /* Skip remaining options. */ |
6589 | 12.7k | for (;;) |
6590 | 13.4k | { |
6591 | 13.4k | if (*ecode == OP_CREF) |
6592 | 292 | { |
6593 | 292 | length += 1 + IMM2_SIZE; |
6594 | 292 | ecode += 1 + IMM2_SIZE; |
6595 | 292 | } |
6596 | 13.1k | else if (*ecode == OP_DNCREF) |
6597 | 396 | { |
6598 | 396 | length += 1 + 2 * IMM2_SIZE; |
6599 | 396 | ecode += 1 + 2 * IMM2_SIZE; |
6600 | 396 | } |
6601 | 12.7k | else |
6602 | 12.7k | { |
6603 | 12.7k | break; |
6604 | 12.7k | } |
6605 | 13.4k | } |
6606 | 12.7k | } |
6607 | | |
6608 | 12.7k | Lsaved_end_subject = mb->end_subject; |
6609 | 12.7k | Ltrue_end_extra = mb->true_end_subject - mb->end_subject; |
6610 | 12.7k | Lsaved_eptr = Feptr; |
6611 | 12.7k | Lsaved_moptions = mb->moptions; |
6612 | | |
6613 | 12.7k | Feptr = mb->start_subject + Fovector[offset]; |
6614 | 12.7k | mb->true_end_subject = mb->end_subject = mb->start_subject + Fovector[offset + 1]; |
6615 | 12.7k | mb->moptions &= ~PCRE2_NOTEOL; |
6616 | | |
6617 | 12.7k | for (;;) |
6618 | 13.6k | { |
6619 | 13.6k | group_frame_type = GF_NOCAPTURE; |
6620 | 13.6k | RMATCH(Fecode + 1 + LINK_SIZE + length, RM38); |
6621 | 12.5k | if (rrc == MATCH_ACCEPT) |
6622 | 380 | { |
6623 | 380 | memcpy(Fovector, (char *)assert_accept_frame + offsetof(heapframe, ovector), |
6624 | 380 | assert_accept_frame->offset_top * sizeof(PCRE2_SIZE)); |
6625 | 380 | Foffset_top = assert_accept_frame->offset_top; |
6626 | 380 | Fmark = assert_accept_frame->mark; |
6627 | 380 | mb->end_subject = Lsaved_end_subject; |
6628 | 380 | mb->true_end_subject = mb->end_subject + Ltrue_end_extra; |
6629 | 380 | mb->moptions = Lsaved_moptions; |
6630 | 380 | break; |
6631 | 380 | } |
6632 | | |
6633 | 12.1k | if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) |
6634 | 952 | { |
6635 | 952 | mb->end_subject = Lsaved_end_subject; |
6636 | 952 | mb->true_end_subject = mb->end_subject + Ltrue_end_extra; |
6637 | 952 | mb->moptions = Lsaved_moptions; |
6638 | 952 | RRETURN(rrc); |
6639 | 952 | } |
6640 | | |
6641 | 11.2k | Fecode += GET(Fecode, 1); |
6642 | 11.2k | if (*Fecode != OP_ALT) |
6643 | 10.2k | { |
6644 | 10.2k | mb->end_subject = Lsaved_end_subject; |
6645 | 10.2k | mb->true_end_subject = mb->end_subject + Ltrue_end_extra; |
6646 | 10.2k | mb->moptions = Lsaved_moptions; |
6647 | 10.2k | RRETURN(MATCH_NOMATCH); |
6648 | 10.2k | } |
6649 | | |
6650 | 981 | length = 0; |
6651 | 981 | } |
6652 | | |
6653 | 380 | do |
6654 | 744 | Fecode += GET(Fecode, 1); |
6655 | 744 | while (*Fecode == OP_ALT); |
6656 | 380 | Fecode += 1 + LINK_SIZE; |
6657 | 380 | Feptr = Lsaved_eptr; |
6658 | 380 | break; |
6659 | | |
6660 | 0 | #undef Lsaved_end_subject |
6661 | 0 | #undef Lsaved_eptr |
6662 | 0 | #undef Ltrue_end_extra |
6663 | 0 | #undef Lextra_size |
6664 | 0 | #undef Lsave_moptions |
6665 | | |
6666 | | |
6667 | | /* ===================================================================== */ |
6668 | | /* The callout item calls an external function, if one is provided, passing |
6669 | | details of the match so far. This is mainly for debugging, though the |
6670 | | function is able to force a failure. */ |
6671 | | |
6672 | 1.31M | case OP_CALLOUT: |
6673 | 1.32M | case OP_CALLOUT_STR: |
6674 | 1.32M | rrc = do_callout(F, mb, &length); |
6675 | 1.32M | if (rrc > 0) |
6676 | 0 | RRETURN(MATCH_NOMATCH); |
6677 | 1.32M | if (rrc < 0) |
6678 | 5.29k | RRETURN(rrc); |
6679 | 1.32M | Fecode += length; |
6680 | 1.32M | break; |
6681 | | |
6682 | | |
6683 | | /* ===================================================================== */ |
6684 | | /* Conditional group: compilation checked that there are no more than two |
6685 | | branches. If the condition is false, skipping the first branch takes us |
6686 | | past the end of the item if there is only one branch, but that's exactly |
6687 | | what we want. */ |
6688 | | |
6689 | 800k | #define Lstart_branch F->fields.op_cond.start_branch |
6690 | 1.83M | #define Llength F->fields.op_cond.length |
6691 | 557k | #define Lpositive F->byte1 |
6692 | | |
6693 | 379k | case OP_COND: |
6694 | 389k | case OP_SCOND: |
6695 | | |
6696 | | /* The variable Llength will be added to Fecode when the condition is |
6697 | | false, to get to the second branch. Setting it to the offset to the ALT or |
6698 | | KET, then incrementing Fecode achieves this effect. However, if the second |
6699 | | branch is non-existent, we must point to the KET so that the end of the |
6700 | | group is correctly processed. We now have Fecode pointing to the condition |
6701 | | or callout. */ |
6702 | | |
6703 | 389k | Llength = GET(Fecode, 1); // Offset to the second branch |
6704 | 389k | if (Fecode[Llength] != OP_ALT) |
6705 | 322k | Llength -= 1 + LINK_SIZE; |
6706 | 389k | Fecode += 1 + LINK_SIZE; // From this opcode |
6707 | | |
6708 | | /* Because of the way auto-callout works during compile, a callout item is |
6709 | | inserted between OP_COND and an assertion condition. Such a callout can |
6710 | | also be inserted manually. */ |
6711 | | |
6712 | 389k | if (*Fecode == OP_CALLOUT || *Fecode == OP_CALLOUT_STR) |
6713 | 14.7k | { |
6714 | 14.7k | rrc = do_callout(F, mb, &length); |
6715 | 14.7k | if (rrc > 0) |
6716 | 0 | RRETURN(MATCH_NOMATCH); |
6717 | 14.7k | if (rrc < 0) |
6718 | 37 | RRETURN(rrc); |
6719 | | |
6720 | | /* Advance Fecode past the callout, so it now points to the condition. We |
6721 | | must adjust Llength so that the value of Fecode+Llength is unchanged. */ |
6722 | | |
6723 | 14.6k | Fecode += length; |
6724 | 14.6k | Llength -= length; |
6725 | 14.6k | } |
6726 | | |
6727 | | /* Test the various possible conditions */ |
6728 | | |
6729 | 389k | condition = FALSE; |
6730 | 389k | switch (*Fecode) |
6731 | 389k | { |
6732 | 66.8k | case OP_RREF: // Group recursion test |
6733 | 66.8k | if (Fcurrent_recurse != RECURSE_UNSET) |
6734 | 27.2k | { |
6735 | 27.2k | number = GET2(Fecode, 1); |
6736 | 27.2k | condition = (number == RREF_ANY || number == Fcurrent_recurse); |
6737 | 27.2k | } |
6738 | | |
6739 | 66.8k | break; |
6740 | | |
6741 | 9.57k | case OP_DNRREF: // Duplicate named group recursion test |
6742 | 9.57k | if (Fcurrent_recurse != RECURSE_UNSET) |
6743 | 697 | { |
6744 | 697 | int count = GET2(Fecode, 1 + IMM2_SIZE); |
6745 | 697 | PCRE2_SPTR slot = mb->name_table + GET2(Fecode, 1) * mb->name_entry_size; |
6746 | 1.68k | while (count-- > 0) |
6747 | 1.18k | { |
6748 | 1.18k | number = GET2(slot, 0); |
6749 | 1.18k | condition = number == Fcurrent_recurse; |
6750 | 1.18k | if (condition) |
6751 | 205 | break; |
6752 | 984 | slot += mb->name_entry_size; |
6753 | 984 | } |
6754 | 697 | } |
6755 | | |
6756 | 9.57k | break; |
6757 | | |
6758 | 13.2k | case OP_CREF: // Numbered group used test |
6759 | 13.2k | offset = (GET2(Fecode, 1) << 1) - 2; // Doubled ref number |
6760 | 13.2k | condition = offset < Foffset_top && Fovector[offset] != PCRE2_UNSET; |
6761 | 13.2k | break; |
6762 | | |
6763 | 6.72k | case OP_DNCREF: // Duplicate named group used test |
6764 | 6.72k | { |
6765 | 6.72k | int count = GET2(Fecode, 1 + IMM2_SIZE); |
6766 | 6.72k | PCRE2_SPTR slot = mb->name_table + GET2(Fecode, 1) * mb->name_entry_size; |
6767 | 11.2k | while (count-- > 0) |
6768 | 9.58k | { |
6769 | 9.58k | offset = (GET2(slot, 0) << 1) - 2; |
6770 | 9.58k | condition = offset < Foffset_top && Fovector[offset] != PCRE2_UNSET; |
6771 | 9.58k | if (condition) |
6772 | 5.10k | break; |
6773 | 4.47k | slot += mb->name_entry_size; |
6774 | 4.47k | } |
6775 | 6.72k | } |
6776 | | |
6777 | 6.72k | break; |
6778 | | |
6779 | 0 | case OP_FALSE: |
6780 | 13.1k | case OP_FAIL: // The assertion (?!) becomes OP_FAIL |
6781 | 13.1k | break; |
6782 | | |
6783 | 0 | case OP_TRUE: |
6784 | 0 | condition = TRUE; |
6785 | 0 | break; |
6786 | | |
6787 | | /* The condition is an assertion. Run code similar to the assertion code |
6788 | | above. */ |
6789 | | |
6790 | | |
6791 | 279k | default: |
6792 | 279k | Lpositive = (uint8_t)(*Fecode == OP_ASSERT || *Fecode == OP_ASSERTBACK); |
6793 | 279k | Lstart_branch = Fecode; |
6794 | | |
6795 | 279k | for (;;) |
6796 | 285k | { |
6797 | 285k | group_frame_type = GF_CONDASSERT; |
6798 | 285k | RMATCH(Lstart_branch + PRIV(OP_lengths)[*Lstart_branch], RM5); |
6799 | | |
6800 | 284k | switch (rrc) |
6801 | 284k | { |
6802 | 235 | case MATCH_ACCEPT: // Save captures |
6803 | 235 | memcpy(Fovector, (char *)assert_accept_frame + offsetof(heapframe, ovector), |
6804 | 235 | assert_accept_frame->offset_top * sizeof(PCRE2_SIZE)); |
6805 | 235 | Foffset_top = assert_accept_frame->offset_top; |
6806 | | |
6807 | 235 | PCRE2_FALLTHROUGH /* Fall through */ |
6808 | | /* In the case of a match, the captures have already been put into |
6809 | | the current frame. */ |
6810 | | |
6811 | 22.8k | case MATCH_MATCH: |
6812 | 22.8k | condition = Lpositive; // TRUE for positive assertion |
6813 | 22.8k | break; |
6814 | | |
6815 | | /* PCRE doesn't allow the effect of (*THEN) to escape beyond an |
6816 | | assertion; it is therefore always treated as NOMATCH. */ |
6817 | | |
6818 | 259k | case MATCH_NOMATCH: |
6819 | 260k | case MATCH_THEN: |
6820 | 260k | Lstart_branch += GET(Lstart_branch, 1); |
6821 | 260k | if (*Lstart_branch == OP_ALT) |
6822 | 6.07k | continue; // Try next branch |
6823 | 254k | condition = !Lpositive; // TRUE for negative assertion |
6824 | 254k | break; |
6825 | | |
6826 | | /* These force no match without checking other branches. */ |
6827 | | |
6828 | 217 | case MATCH_COMMIT: |
6829 | 572 | case MATCH_SKIP: |
6830 | 799 | case MATCH_PRUNE: |
6831 | 799 | condition = !Lpositive; |
6832 | 799 | break; |
6833 | | |
6834 | 376 | default: |
6835 | 376 | RRETURN(rrc); |
6836 | 284k | } |
6837 | | |
6838 | 277k | break; // Out of the branch loop |
6839 | 284k | } |
6840 | | |
6841 | | /* If the condition is true, find the end of the assertion so that |
6842 | | advancing past it gets us to the start of the first branch. */ |
6843 | | |
6844 | 277k | if (condition) |
6845 | 20.0k | { |
6846 | 20.0k | do |
6847 | 22.7k | Fecode += GET(Fecode, 1); |
6848 | 22.7k | while (*Fecode == OP_ALT); |
6849 | 20.0k | } |
6850 | | |
6851 | 277k | break; // End of assertion condition |
6852 | 389k | } |
6853 | | |
6854 | | /* Choose branch according to the condition. */ |
6855 | | |
6856 | 387k | Fecode += condition ? PRIV(OP_lengths)[*Fecode] : Llength; |
6857 | | |
6858 | | /* If the opcode is OP_SCOND it means we are at a repeated conditional |
6859 | | group that might match an empty string. We must therefore descend a level |
6860 | | so that the start is remembered for checking. For OP_COND we can just |
6861 | | continue at this level. */ |
6862 | | |
6863 | 387k | if (Fop == OP_SCOND) |
6864 | 9.04k | { |
6865 | 9.04k | group_frame_type = GF_NOCAPTURE; |
6866 | 9.04k | RMATCH(Fecode, RM35); |
6867 | 8.27k | RRETURN(rrc); |
6868 | 8.27k | } |
6869 | | |
6870 | 378k | break; |
6871 | | |
6872 | 378k | #undef Lstart_branch |
6873 | 378k | #undef Llength |
6874 | 378k | #undef Lpositive |
6875 | | |
6876 | | |
6877 | | /* ========================================================================= */ |
6878 | | /* End of start of parenthesis opcodes */ |
6879 | | /* ========================================================================= */ |
6880 | | |
6881 | | |
6882 | | /* ===================================================================== */ |
6883 | | /* Move the subject pointer back by one fixed amount. This occurs at the |
6884 | | start of each branch that has a fixed length in a lookbehind assertion. If |
6885 | | we are too close to the start to move back, fail. When working with UTF-8 |
6886 | | we move back a number of characters, not bytes. */ |
6887 | | |
6888 | 378k | case OP_REVERSE: |
6889 | 215k | number = GET2(Fecode, 1); |
6890 | 215k | #ifdef SUPPORT_UNICODE |
6891 | 215k | if (utf) |
6892 | 69.8k | { |
6893 | | /* We used to do a simpler `while (number-- > 0)` but that triggers |
6894 | | clang's unsigned integer overflow sanitizer. */ |
6895 | 540k | while (number > 0) |
6896 | 504k | { |
6897 | 504k | --number; |
6898 | 504k | if (Feptr <= mb->check_subject) |
6899 | 34.5k | RRETURN(MATCH_NOMATCH); |
6900 | 470k | Feptr--; |
6901 | 470k | BACKCHAR(Feptr); |
6902 | 470k | } |
6903 | 69.8k | } |
6904 | 145k | else |
6905 | 145k | #endif |
6906 | | |
6907 | | /* No UTF support, or not in UTF mode: count is code unit count */ |
6908 | | |
6909 | 145k | { |
6910 | 145k | if ((ptrdiff_t)number > Feptr - mb->start_subject) |
6911 | 59.9k | RRETURN(MATCH_NOMATCH); |
6912 | 85.6k | Feptr -= number; |
6913 | 85.6k | } |
6914 | | |
6915 | | /* Save the earliest consulted character, then skip to next opcode */ |
6916 | | |
6917 | 120k | if (Feptr < mb->start_used_ptr) |
6918 | 43.5k | mb->start_used_ptr = Feptr; |
6919 | 120k | Fecode += 1 + IMM2_SIZE; |
6920 | 120k | break; |
6921 | | |
6922 | | |
6923 | | /* ===================================================================== */ |
6924 | | /* Move the subject pointer back by a variable amount. This occurs at the |
6925 | | start of each branch of a lookbehind assertion when the branch has a |
6926 | | variable, but limited, length. A loop is needed to try matching the branch |
6927 | | after moving back different numbers of characters. If we are too close to |
6928 | | the start to move back even the minimum amount, fail. When working with |
6929 | | UTF-8 we move back a number of characters, not bytes. */ |
6930 | | |
6931 | 750k | #define Lmin F->fields.op_vreverse.min |
6932 | 1.22M | #define Lmax F->fields.op_vreverse.max |
6933 | | |
6934 | 126k | case OP_VREVERSE: |
6935 | 126k | Lmin = GET2(Fecode, 1); |
6936 | 126k | Lmax = GET2(Fecode, 1 + IMM2_SIZE); |
6937 | | |
6938 | | /* Move back by the maximum branch length and then work forwards. This |
6939 | | ensures that items such as \d{3,5} get the maximum length, which is |
6940 | | relevant for captures, and makes for Perl compatibility. */ |
6941 | | |
6942 | 126k | #ifdef SUPPORT_UNICODE |
6943 | 126k | if (utf) |
6944 | 40.9k | { |
6945 | 443k | for (i = 0; i < Lmax; i++) |
6946 | 422k | { |
6947 | 422k | if (Feptr <= mb->check_subject) |
6948 | 19.8k | { |
6949 | 19.8k | if (i < Lmin) |
6950 | 14.8k | RRETURN(MATCH_NOMATCH); |
6951 | 4.96k | Lmax = i; |
6952 | 4.96k | break; |
6953 | 19.8k | } |
6954 | | |
6955 | 402k | Feptr--; |
6956 | 402k | BACKCHAR(Feptr); |
6957 | 402k | } |
6958 | 40.9k | } |
6959 | 85.9k | else |
6960 | 85.9k | #endif |
6961 | | |
6962 | | /* No UTF support or not in UTF mode */ |
6963 | | |
6964 | 85.9k | { |
6965 | 85.9k | ptrdiff_t diff = Feptr - mb->start_subject; |
6966 | 85.9k | uint32_t available = (diff > 65535) ? 65535 : ((diff > 0) ? (int)diff : 0); |
6967 | 85.9k | if (Lmin > available) |
6968 | 26.7k | RRETURN(MATCH_NOMATCH); |
6969 | 59.2k | if (Lmax > available) |
6970 | 13.6k | Lmax = available; |
6971 | 59.2k | Feptr -= Lmax; |
6972 | 59.2k | } |
6973 | | |
6974 | | /* Now try matching, moving forward one character on failure, until we |
6975 | | reach the minimum back length. */ |
6976 | | |
6977 | 85.3k | for (;;) |
6978 | 552k | { |
6979 | 552k | RMATCH(Fecode + 1 + 2 * IMM2_SIZE, RM37); |
6980 | 538k | if (rrc != MATCH_NOMATCH) |
6981 | 20.1k | RRETURN(rrc); |
6982 | 518k | if (Lmax-- <= Lmin) |
6983 | 50.6k | RRETURN(MATCH_NOMATCH); |
6984 | 467k | Feptr++; |
6985 | 467k | #ifdef SUPPORT_UNICODE |
6986 | 467k | if (utf) |
6987 | 187k | { |
6988 | 187k | FORWARDCHARTEST(Feptr, mb->end_subject); |
6989 | 187k | } |
6990 | 467k | #endif |
6991 | 467k | } |
6992 | | |
6993 | 85.3k | PCRE2_UNREACHABLE(); // Control never reaches here |
6994 | | |
6995 | 0 | #undef Lmin |
6996 | 0 | #undef Lmax |
6997 | | |
6998 | | |
6999 | | /* ===================================================================== */ |
7000 | | /* An alternation is the end of a branch; scan along to find the end of the |
7001 | | bracketed group. */ |
7002 | | |
7003 | 840k | case OP_ALT: |
7004 | 840k | branch_end = Fecode; |
7005 | 840k | do |
7006 | 7.75M | Fecode += GET(Fecode, 1); |
7007 | 7.75M | while (*Fecode == OP_ALT); |
7008 | 840k | break; |
7009 | | |
7010 | | |
7011 | | /* ===================================================================== */ |
7012 | | /* The end of a parenthesized group. For all but OP_BRA and OP_COND, the |
7013 | | starting frame was added to the chained frames in order to remember the |
7014 | | starting subject position for the group. (Not true for OP_BRA when it's a |
7015 | | whole pattern recursion, but that is handled separately below.)*/ |
7016 | | |
7017 | 3.09M | case OP_KET: |
7018 | 3.11M | case OP_KETRMIN: |
7019 | 3.19M | case OP_KETRMAX: |
7020 | 3.27M | case OP_KETRPOS: |
7021 | | |
7022 | 3.27M | bracode = Fecode - GET(Fecode, 1); |
7023 | | |
7024 | 3.27M | if (branch_end == NULL) |
7025 | 2.43M | branch_end = Fecode; |
7026 | 3.27M | branch_start = bracode; |
7027 | 10.4M | while (branch_start + GET(branch_start, 1) != branch_end) |
7028 | 7.18M | branch_start += GET(branch_start, 1); |
7029 | 3.27M | branch_end = NULL; |
7030 | | |
7031 | | /* Point N to the frame at the start of the most recent group, and P to its |
7032 | | predecessor. Remember the subject pointer at the start of the group. */ |
7033 | | |
7034 | 3.27M | if (*bracode != OP_BRA && *bracode != OP_COND) |
7035 | 1.62M | { |
7036 | 1.62M | N = (heapframe *)((char *)match_data->heapframes + Flast_group_offset); |
7037 | 1.62M | P = (heapframe *)((char *)N - frame_size); |
7038 | 1.62M | Flast_group_offset = P->last_group_offset; |
7039 | | |
7040 | | #ifdef DEBUG_SHOW_RMATCH |
7041 | | fprintf(stderr, "++ KET for frame=%d type=%x prev char offset=%lu\n", N->rdepth, |
7042 | | N->group_frame_type, (char *)P->eptr - (char *)mb->start_subject); |
7043 | | #endif |
7044 | | |
7045 | | /* If we are at the end of an assertion that is a condition, first check |
7046 | | to see if we are at the end of a variable-length branch in a lookbehind. |
7047 | | If this is the case and we have not landed on the current character, |
7048 | | return no match. Compare code below for non-condition lookbehinds. In |
7049 | | other cases, return a match, discarding any intermediate backtracking |
7050 | | points. Copy back the mark setting and the captures into the frame before |
7051 | | N so that they are set on return. Doing this for all assertions, both |
7052 | | positive and negative, seems to match what Perl does. */ |
7053 | | |
7054 | 1.62M | if (N->group_frame_type == GF_CONDASSERT) |
7055 | 23.5k | { |
7056 | 23.5k | if ((*bracode == OP_ASSERTBACK || *bracode == OP_ASSERTBACK_NOT) && |
7057 | 5.48k | branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) |
7058 | 906 | RRETURN(MATCH_NOMATCH); |
7059 | 22.6k | memcpy((char *)P + offsetof(heapframe, ovector), Fovector, |
7060 | 22.6k | Foffset_top * sizeof(PCRE2_SIZE)); |
7061 | 22.6k | P->offset_top = Foffset_top; |
7062 | 22.6k | P->mark = Fmark; |
7063 | 22.6k | Fback_frame = (char *)F - (char *)P; |
7064 | 22.6k | RRETURN(MATCH_MATCH); |
7065 | 22.6k | } |
7066 | 1.62M | } |
7067 | 1.65M | else |
7068 | 1.65M | P = NULL; // Indicates starting frame not recorded |
7069 | | |
7070 | | /* The group was not a conditional assertion. */ |
7071 | | |
7072 | 3.25M | switch (*bracode) |
7073 | 3.25M | { |
7074 | | /* Whole pattern recursion is handled as a recursion into group 0, but |
7075 | | the entire pattern is wrapped in OP_BRA/OP_KET rather than a capturing |
7076 | | group - a design mistake: it should perhaps have been capture group 0. |
7077 | | Anyway, that means the end of such recursion must be handled here. It is |
7078 | | detected by checking for an immediately following OP_END when we are |
7079 | | recursing in group 0. If this is not the end of a whole-pattern |
7080 | | recursion, there is nothing to be done. */ |
7081 | | |
7082 | 1.31M | case OP_BRA: |
7083 | 1.31M | if (Fcurrent_recurse != 0 || Fecode[1 + LINK_SIZE] != OP_END) |
7084 | 1.19M | break; |
7085 | | |
7086 | | /* It is the end of whole-pattern recursion. */ |
7087 | | |
7088 | 118k | offset = Flast_group_offset; |
7089 | | |
7090 | | /* Corrupted heapframes?. Trigger an assert and return an error */ |
7091 | 118k | PCRE2_ASSERT(offset != PCRE2_UNSET); |
7092 | 118k | if (offset == PCRE2_UNSET) |
7093 | 0 | return PCRE2_ERROR_INTERNAL; |
7094 | | |
7095 | 118k | N = (heapframe *)((char *)match_data->heapframes + offset); |
7096 | 118k | P = (heapframe *)((char *)N - frame_size); |
7097 | 118k | Flast_group_offset = P->last_group_offset; |
7098 | | |
7099 | | /* Reinstate the previous set of captures and then carry on after the |
7100 | | recursion call. */ |
7101 | | |
7102 | 118k | Fecode = P->ecode + 1 + LINK_SIZE; |
7103 | | |
7104 | 118k | if (*Fecode != OP_CREF) |
7105 | 107k | { |
7106 | 107k | memcpy(F->ovector, P->ovector, Foffset_top * sizeof(PCRE2_SIZE)); |
7107 | 107k | Foffset_top = P->offset_top; |
7108 | 107k | } |
7109 | 11.3k | else |
7110 | 11.3k | { |
7111 | 11.3k | recurse_update_offsets(F, P); |
7112 | 11.3k | } |
7113 | | |
7114 | 118k | Fcapture_last = P->capture_last; |
7115 | 118k | Fcurrent_recurse = P->current_recurse; |
7116 | 118k | continue; // With next opcode |
7117 | | |
7118 | 337k | case OP_COND: // No need to do anything for these |
7119 | 345k | case OP_SCOND: |
7120 | 345k | break; |
7121 | | |
7122 | | /* Non-atomic positive assertions are like OP_BRA, except that the |
7123 | | subject pointer must be put back to where it was at the start of the |
7124 | | assertion. For a variable lookbehind, check its end point. */ |
7125 | | |
7126 | 44.0k | case OP_ASSERTBACK_NA: |
7127 | 44.0k | if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) |
7128 | 4.23k | RRETURN(MATCH_NOMATCH); |
7129 | 39.7k | PCRE2_FALLTHROUGH /* Fall through */ |
7130 | 39.7k | |
7131 | 191k | case OP_ASSERT_NA: |
7132 | 191k | if (Feptr > mb->last_used_ptr) |
7133 | 3.68k | mb->last_used_ptr = Feptr; |
7134 | 191k | Feptr = P->eptr; |
7135 | 191k | break; |
7136 | | |
7137 | | /* Atomic positive assertions are like OP_ONCE, except that in addition |
7138 | | the subject pointer must be put back to where it was at the start of the |
7139 | | assertion. For a variable lookbehind, check its end point. */ |
7140 | | |
7141 | 33.3k | case OP_ASSERTBACK: |
7142 | 33.3k | if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) |
7143 | 5.47k | RRETURN(MATCH_NOMATCH); |
7144 | 27.8k | PCRE2_FALLTHROUGH /* Fall through */ |
7145 | 27.8k | |
7146 | 110k | case OP_ASSERT: |
7147 | 110k | if (Feptr > mb->last_used_ptr) |
7148 | 3.41k | mb->last_used_ptr = Feptr; |
7149 | 110k | Feptr = P->eptr; |
7150 | 110k | PCRE2_FALLTHROUGH /* Fall through */ |
7151 | | |
7152 | | /* For an atomic group, discard internal backtracking points. We must |
7153 | | also ensure that any remaining branches within the top-level of the group |
7154 | | are not tried. Do this by adjusting the code pointer within the backtrack |
7155 | | frame so that it points to the final branch. */ |
7156 | | |
7157 | 180k | case OP_ONCE: |
7158 | 180k | Fback_frame = ((char *)F - (char *)P); |
7159 | 180k | for (;;) |
7160 | 883k | { |
7161 | 883k | uint32_t y = GET(P->ecode, 1); |
7162 | 883k | if ((P->ecode)[y] != OP_ALT) |
7163 | 180k | break; |
7164 | 703k | P->ecode += y; |
7165 | 703k | } |
7166 | | |
7167 | 180k | break; |
7168 | | |
7169 | | /* A matching negative assertion returns MATCH, which is turned into |
7170 | | NOMATCH at the assertion level. For a variable lookbehind, check its end |
7171 | | point. */ |
7172 | | |
7173 | 23.7k | case OP_ASSERTBACK_NOT: |
7174 | 23.7k | if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) |
7175 | 2.36k | RRETURN(MATCH_NOMATCH); |
7176 | 21.4k | PCRE2_FALLTHROUGH /* Fall through */ |
7177 | 21.4k | |
7178 | 37.8k | case OP_ASSERT_NOT: |
7179 | 37.8k | RRETURN(MATCH_MATCH); |
7180 | | |
7181 | | /* A scan substring group must preserve the current end_subject, |
7182 | | and restore it before the backtracking is performed into its sub |
7183 | | pattern. */ |
7184 | | |
7185 | 4.25k | case OP_ASSERT_SCS: |
7186 | 4.25k | F->fields.op_assert_scs.saved_end_subject = mb->end_subject; |
7187 | 4.25k | mb->end_subject = P->fields.op_assert_scs.saved_end_subject; |
7188 | 4.25k | mb->true_end_subject = mb->end_subject + P->fields.op_assert_scs.true_end_extra; |
7189 | 4.25k | Feptr = P->fields.op_assert_scs.saved_eptr; |
7190 | | |
7191 | 4.25k | RMATCH(Fecode + 1 + LINK_SIZE, RM39); |
7192 | | |
7193 | 3.13k | mb->end_subject = F->fields.op_assert_scs.saved_end_subject; |
7194 | 3.13k | mb->true_end_subject = mb->end_subject; |
7195 | 3.13k | RRETURN(rrc); |
7196 | 0 | break; |
7197 | | |
7198 | | /* At the end of a script run, apply the script-checking rules. This code |
7199 | | will never by exercised if Unicode support it not compiled, because in |
7200 | | that environment script runs cause an error at compile time. */ |
7201 | | |
7202 | 110k | case OP_SCRIPT_RUN: |
7203 | 110k | if (!PRIV(script_run)(P->eptr, Feptr, utf)) |
7204 | 39.6k | RRETURN(MATCH_NOMATCH); |
7205 | 70.4k | break; |
7206 | | |
7207 | | /* Whole-pattern recursion is coded as a recurse into group 0, and is |
7208 | | handled with OP_BRA above. Other recursion is handled here. */ |
7209 | | |
7210 | 933k | case OP_CBRA: |
7211 | 948k | case OP_CBRAPOS: |
7212 | 979k | case OP_SCBRA: |
7213 | 1.03M | case OP_SCBRAPOS: |
7214 | 1.03M | number = GET2(bracode, 1 + LINK_SIZE); |
7215 | | |
7216 | | /* Handle a recursively called group. We reinstate the previous set of |
7217 | | captures and then carry on after the recursion call. */ |
7218 | | |
7219 | 1.03M | if (Fcurrent_recurse == number) |
7220 | 67.5k | { |
7221 | 67.5k | P = (heapframe *)((char *)N - frame_size); |
7222 | 67.5k | Fecode = P->ecode + 1 + LINK_SIZE; |
7223 | | |
7224 | 67.5k | if (*Fecode != OP_CREF) |
7225 | 64.6k | { |
7226 | 64.6k | memcpy(F->ovector, P->ovector, Foffset_top * sizeof(PCRE2_SIZE)); |
7227 | 64.6k | Foffset_top = P->offset_top; |
7228 | 64.6k | } |
7229 | 2.81k | else |
7230 | 2.81k | { |
7231 | 2.81k | recurse_update_offsets(F, P); |
7232 | 2.81k | } |
7233 | | |
7234 | 67.5k | Fcapture_last = P->capture_last; |
7235 | 67.5k | Fcurrent_recurse = P->current_recurse; |
7236 | 67.5k | continue; // With next opcode |
7237 | 67.5k | } |
7238 | | |
7239 | | /* Deal with actual capturing. */ |
7240 | | |
7241 | 964k | offset = (number << 1) - 2; |
7242 | 964k | Fcapture_last = number; |
7243 | 964k | Fovector[offset] = P->eptr - mb->start_subject; |
7244 | 964k | Fovector[offset + 1] = Feptr - mb->start_subject; |
7245 | 964k | if (offset >= Foffset_top) |
7246 | 610k | Foffset_top = offset + 2; |
7247 | 964k | break; |
7248 | 3.25M | } // End actions relating to the starting opcode |
7249 | | |
7250 | | /* OP_KETRPOS is a possessive repeating ket. Remember the current position, |
7251 | | and return the MATCH_KETRPOS. This makes it possible to do the repeats one |
7252 | | at a time from the outer level. This must precede the empty string test - |
7253 | | in this case that test is done at the outer level. */ |
7254 | | |
7255 | 2.97M | if (*Fecode == OP_KETRPOS) |
7256 | 77.6k | { |
7257 | 77.6k | memcpy((char *)P + offsetof(heapframe, eptr), (char *)F + offsetof(heapframe, eptr), |
7258 | 77.6k | frame_copy_size); |
7259 | 77.6k | RRETURN(MATCH_KETRPOS); |
7260 | 77.6k | } |
7261 | | |
7262 | | /* Handle the different kinds of closing brackets. A non-repeating ket |
7263 | | needs no special action, just continuing at this level. This also happens |
7264 | | for the repeating kets if the group matched no characters, in order to |
7265 | | forcibly break infinite loops. Otherwise, the repeating kets try the rest |
7266 | | of the pattern or restart from the preceding bracket, in the appropriate |
7267 | | order. */ |
7268 | | |
7269 | 2.89M | if (Fop != OP_KET && (P == NULL || Feptr != P->eptr)) |
7270 | 55.0k | { |
7271 | 55.0k | if (Fop == OP_KETRMIN) |
7272 | 10.5k | { |
7273 | 10.5k | RMATCH(Fecode + 1 + LINK_SIZE, RM6); |
7274 | 10.0k | if (rrc != MATCH_NOMATCH) |
7275 | 375 | RRETURN(rrc); |
7276 | 9.71k | Fecode -= GET(Fecode, 1); |
7277 | 9.71k | break; // End of ket processing |
7278 | 10.0k | } |
7279 | | |
7280 | | /* Repeat the maximum number of times (KETRMAX) */ |
7281 | | |
7282 | 44.5k | RMATCH(bracode, RM7); |
7283 | 37.7k | if (rrc != MATCH_NOMATCH) |
7284 | 1.95k | RRETURN(rrc); |
7285 | 37.7k | } |
7286 | | |
7287 | | /* Carry on at this level for a non-repeating ket, or after matching an |
7288 | | empty string, or after repeating for a maximum number of times. */ |
7289 | | |
7290 | 2.87M | Fecode += 1 + LINK_SIZE; |
7291 | 2.87M | break; |
7292 | | |
7293 | | |
7294 | | /* ===================================================================== */ |
7295 | | /* Start and end of line assertions, not multiline mode. */ |
7296 | | |
7297 | 629k | case OP_CIRC: // Start of line, unless PCRE2_NOTBOL is set. |
7298 | 629k | if (Feptr != mb->start_subject || (mb->moptions & PCRE2_NOTBOL) != 0) |
7299 | 617k | RRETURN(MATCH_NOMATCH); |
7300 | 12.6k | Fecode++; |
7301 | 12.6k | break; |
7302 | | |
7303 | 61.8k | case OP_SOD: // Unconditional start of subject |
7304 | 61.8k | if (Feptr != mb->start_subject) |
7305 | 57.9k | RRETURN(MATCH_NOMATCH); |
7306 | 3.95k | Fecode++; |
7307 | 3.95k | break; |
7308 | | |
7309 | | /* When PCRE2_NOTEOL is unset, assert before the subject end, or a |
7310 | | terminating newline unless PCRE2_DOLLAR_ENDONLY is set. */ |
7311 | | |
7312 | 274k | case OP_DOLL: |
7313 | 274k | if ((mb->moptions & PCRE2_NOTEOL) != 0) |
7314 | 26.3k | RRETURN(MATCH_NOMATCH); |
7315 | 248k | if ((mb->poptions & PCRE2_DOLLAR_ENDONLY) == 0) |
7316 | 226k | goto ASSERT_NL_OR_EOS; |
7317 | | |
7318 | 22.0k | PCRE2_FALLTHROUGH /* Fall through */ |
7319 | 22.0k | /* Unconditional end of subject assertion (\z). */ |
7320 | 22.0k | |
7321 | 196k | case OP_EOD: |
7322 | 196k | if (Feptr < mb->true_end_subject) |
7323 | 123k | RRETURN(MATCH_NOMATCH); |
7324 | 73.8k | if (mb->partial != 0) |
7325 | 46.1k | { |
7326 | 46.1k | mb->hitend = TRUE; |
7327 | 46.1k | if (mb->partial > 1) |
7328 | 75 | return PCRE2_ERROR_PARTIAL; |
7329 | 46.1k | } |
7330 | | |
7331 | 73.7k | Fecode++; |
7332 | 73.7k | break; |
7333 | | |
7334 | | /* End of subject or ending \n assertion (\Z) */ |
7335 | | |
7336 | 143k | case OP_EODN: |
7337 | 370k | ASSERT_NL_OR_EOS: |
7338 | 370k | if (Feptr < mb->true_end_subject && |
7339 | 261k | (!IS_NEWLINE(Feptr) || Feptr != mb->true_end_subject - mb->nllen)) |
7340 | 261k | { |
7341 | 261k | if (mb->partial != 0 && Feptr + 1 >= mb->end_subject && NLBLOCK->nltype == NLTYPE_FIXED && |
7342 | 6.93k | NLBLOCK->nllen == 2 && *Feptr == NLBLOCK->nl[0]) |
7343 | 0 | { |
7344 | 0 | mb->hitend = TRUE; |
7345 | 0 | if (mb->partial > 1) |
7346 | 0 | return PCRE2_ERROR_PARTIAL; |
7347 | 0 | } |
7348 | | |
7349 | 261k | RRETURN(MATCH_NOMATCH); |
7350 | 261k | } |
7351 | | |
7352 | | /* Either at end of string or \n before end. */ |
7353 | | |
7354 | 109k | if (mb->partial != 0) |
7355 | 67.8k | { |
7356 | 67.8k | mb->hitend = TRUE; |
7357 | 67.8k | if (mb->partial > 1) |
7358 | 159 | return PCRE2_ERROR_PARTIAL; |
7359 | 67.8k | } |
7360 | | |
7361 | 109k | Fecode++; |
7362 | 109k | break; |
7363 | | |
7364 | | |
7365 | | /* ===================================================================== */ |
7366 | | /* Start and end of line assertions, multiline mode. */ |
7367 | | |
7368 | | /* Start of subject unless notbol, or after any newline except for one at |
7369 | | the very end, unless PCRE2_ALT_CIRCUMFLEX is set. */ |
7370 | | |
7371 | 446k | case OP_CIRCM: |
7372 | 446k | if ((mb->moptions & PCRE2_NOTBOL) != 0 && Feptr == mb->start_subject) |
7373 | 2.96k | RRETURN(MATCH_NOMATCH); |
7374 | 443k | if (Feptr != mb->start_subject && |
7375 | 438k | ((Feptr == mb->end_subject && (mb->poptions & PCRE2_ALT_CIRCUMFLEX) == 0) || |
7376 | 436k | !WAS_NEWLINE(Feptr))) |
7377 | 436k | RRETURN(MATCH_NOMATCH); |
7378 | 7.82k | Fecode++; |
7379 | 7.82k | break; |
7380 | | |
7381 | | /* Assert before any newline, or before end of subject unless noteol is |
7382 | | set. */ |
7383 | | |
7384 | 65.2k | case OP_DOLLM: |
7385 | 65.2k | if (Feptr < mb->end_subject) |
7386 | 53.4k | { |
7387 | 53.4k | if (!IS_NEWLINE(Feptr)) |
7388 | 51.9k | { |
7389 | 51.9k | if (mb->partial != 0 && Feptr + 1 >= mb->end_subject && NLBLOCK->nltype == NLTYPE_FIXED && |
7390 | 1.58k | NLBLOCK->nllen == 2 && *Feptr == NLBLOCK->nl[0]) |
7391 | 0 | { |
7392 | 0 | mb->hitend = TRUE; |
7393 | 0 | if (mb->partial > 1) |
7394 | 0 | return PCRE2_ERROR_PARTIAL; |
7395 | 0 | } |
7396 | | |
7397 | 51.9k | RRETURN(MATCH_NOMATCH); |
7398 | 51.9k | } |
7399 | 53.4k | } |
7400 | 11.8k | else |
7401 | 11.8k | { |
7402 | 11.8k | if ((mb->moptions & PCRE2_NOTEOL) != 0) |
7403 | 902 | RRETURN(MATCH_NOMATCH); |
7404 | 10.9k | SCHECK_PARTIAL(); |
7405 | 10.9k | } |
7406 | | |
7407 | 12.4k | Fecode++; |
7408 | 12.4k | break; |
7409 | | |
7410 | | |
7411 | | /* ===================================================================== */ |
7412 | | /* Start of match assertion */ |
7413 | | |
7414 | 18.8k | case OP_SOM: |
7415 | 18.8k | if (Feptr != mb->start_subject + mb->start_offset) |
7416 | 17.2k | RRETURN(MATCH_NOMATCH); |
7417 | 1.58k | Fecode++; |
7418 | 1.58k | break; |
7419 | | |
7420 | | |
7421 | | /* ===================================================================== */ |
7422 | | /* Reset the start of match point */ |
7423 | | |
7424 | 8.25k | case OP_SET_SOM: |
7425 | 8.25k | Fstart_match = Feptr; |
7426 | 8.25k | Fecode++; |
7427 | 8.25k | break; |
7428 | | |
7429 | | |
7430 | | /* ===================================================================== */ |
7431 | | /* Word boundary assertions. Find out if the previous and current |
7432 | | characters are "word" characters. It takes a bit more work in UTF mode. |
7433 | | Characters > 255 are assumed to be "non-word" characters when PCRE2_UCP is |
7434 | | not set. When it is set, use Unicode properties if available, even when not |
7435 | | in UTF mode. Remember the earliest and latest consulted characters. */ |
7436 | | |
7437 | 45.9k | case OP_NOT_WORD_BOUNDARY: |
7438 | 73.4k | case OP_WORD_BOUNDARY: |
7439 | 99.5k | case OP_NOT_UCP_WORD_BOUNDARY: |
7440 | 126k | case OP_UCP_WORD_BOUNDARY: |
7441 | 126k | if (Feptr == mb->check_subject) |
7442 | 9.43k | { |
7443 | 9.43k | prev_is_word = FALSE; |
7444 | 9.43k | } |
7445 | 117k | else |
7446 | 117k | { |
7447 | 117k | PCRE2_SPTR lastptr = Feptr - 1; |
7448 | 117k | #ifdef SUPPORT_UNICODE |
7449 | 117k | if (utf) |
7450 | 45.0k | { |
7451 | 45.0k | BACKCHAR(lastptr); |
7452 | 45.0k | GETCHAR(fc, lastptr); |
7453 | 45.0k | } |
7454 | 72.3k | else |
7455 | 72.3k | #endif /* SUPPORT_UNICODE */ |
7456 | 72.3k | fc = *lastptr; |
7457 | 117k | if (lastptr < mb->start_used_ptr) |
7458 | 14.3k | mb->start_used_ptr = lastptr; |
7459 | 117k | #ifdef SUPPORT_UNICODE |
7460 | 117k | if (Fop == OP_UCP_WORD_BOUNDARY || Fop == OP_NOT_UCP_WORD_BOUNDARY) |
7461 | 50.6k | { |
7462 | 50.6k | int chartype = UCD_CHARTYPE(fc); |
7463 | 50.6k | int category = PRIV(ucp_gentype)[chartype]; |
7464 | 50.6k | prev_is_word = |
7465 | 50.6k | (category == ucp_L || category == ucp_N || chartype == ucp_Mn || chartype == ucp_Pc); |
7466 | 50.6k | } |
7467 | 66.7k | else |
7468 | 66.7k | #endif /* SUPPORT_UNICODE */ |
7469 | 66.7k | prev_is_word = CHMAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0; |
7470 | 117k | } |
7471 | | |
7472 | | /* Get status of next character */ |
7473 | | |
7474 | 126k | if (Feptr >= mb->end_subject) |
7475 | 12.7k | { |
7476 | 12.7k | SCHECK_PARTIAL(); |
7477 | 12.6k | cur_is_word = FALSE; |
7478 | 12.6k | } |
7479 | 114k | else |
7480 | 114k | { |
7481 | 114k | PCRE2_SPTR nextptr = Feptr + 1; |
7482 | 114k | #ifdef SUPPORT_UNICODE |
7483 | 114k | if (utf) |
7484 | 43.4k | { |
7485 | 43.4k | FORWARDCHARTEST(nextptr, mb->end_subject); |
7486 | 43.4k | GETCHAR(fc, Feptr); |
7487 | 43.4k | } |
7488 | 70.6k | else |
7489 | 70.6k | #endif /* SUPPORT_UNICODE */ |
7490 | 70.6k | fc = *Feptr; |
7491 | 114k | if (nextptr > mb->last_used_ptr) |
7492 | 30.0k | mb->last_used_ptr = nextptr; |
7493 | 114k | #ifdef SUPPORT_UNICODE |
7494 | 114k | if (Fop == OP_UCP_WORD_BOUNDARY || Fop == OP_NOT_UCP_WORD_BOUNDARY) |
7495 | 49.3k | { |
7496 | 49.3k | int chartype = UCD_CHARTYPE(fc); |
7497 | 49.3k | int category = PRIV(ucp_gentype)[chartype]; |
7498 | 49.3k | cur_is_word = |
7499 | 49.3k | (category == ucp_L || category == ucp_N || chartype == ucp_Mn || chartype == ucp_Pc); |
7500 | 49.3k | } |
7501 | 64.6k | else |
7502 | 64.6k | #endif /* SUPPORT_UNICODE */ |
7503 | 64.6k | cur_is_word = CHMAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0; |
7504 | 114k | } |
7505 | | |
7506 | | /* Now see if the situation is what we want */ |
7507 | | |
7508 | 126k | if ((*Fecode++ == OP_WORD_BOUNDARY || Fop == OP_UCP_WORD_BOUNDARY) |
7509 | 126k | ? cur_is_word == prev_is_word |
7510 | 126k | : cur_is_word != prev_is_word) |
7511 | 56.7k | RRETURN(MATCH_NOMATCH); |
7512 | 70.0k | break; |
7513 | | |
7514 | | |
7515 | | /* ===================================================================== */ |
7516 | | /* Backtracking (*VERB)s, with and without arguments. Note that if the |
7517 | | pattern is successfully matched, we do not come back from RMATCH. */ |
7518 | | |
7519 | 70.0k | case OP_MARK: |
7520 | 43.3k | Fmark = mb->nomatch_mark = Fecode + 2; |
7521 | 43.3k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM12); |
7522 | | |
7523 | | /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an |
7524 | | argument, and we must check whether that argument matches this MARK's |
7525 | | argument. It is passed back in mb->verb_skip_ptr. If it does match, we |
7526 | | return MATCH_SKIP with mb->verb_skip_ptr now pointing to the subject |
7527 | | position that corresponds to this mark. Otherwise, pass back the return |
7528 | | code unaltered. */ |
7529 | | |
7530 | 40.7k | if (rrc == MATCH_SKIP_ARG && PRIV(strcmp)(Fecode + 2, mb->verb_skip_ptr) == 0) |
7531 | 2.25k | { |
7532 | 2.25k | mb->verb_skip_ptr = Feptr; // Pass back current position |
7533 | 2.25k | RRETURN(MATCH_SKIP); |
7534 | 2.25k | } |
7535 | | |
7536 | 38.4k | RRETURN(rrc); |
7537 | | |
7538 | 5.15k | case OP_FAIL: |
7539 | 5.15k | RRETURN(MATCH_NOMATCH); |
7540 | | |
7541 | | /* Record the current recursing group number in mb->verb_current_recurse |
7542 | | when a backtracking return such as MATCH_COMMIT is given. This enables the |
7543 | | recurse processing to catch verbs from within the recursion. */ |
7544 | | |
7545 | 3.24k | case OP_COMMIT: |
7546 | 3.24k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM13); |
7547 | 1.95k | if (rrc != MATCH_NOMATCH) |
7548 | 426 | RRETURN(rrc); |
7549 | 1.52k | mb->verb_current_recurse = Fcurrent_recurse; |
7550 | 1.52k | RRETURN(MATCH_COMMIT); |
7551 | | |
7552 | 1.08k | case OP_COMMIT_ARG: |
7553 | 1.08k | Fmark = mb->nomatch_mark = Fecode + 2; |
7554 | 1.08k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM36); |
7555 | 573 | if (rrc != MATCH_NOMATCH) |
7556 | 302 | RRETURN(rrc); |
7557 | 271 | mb->verb_current_recurse = Fcurrent_recurse; |
7558 | 271 | RRETURN(MATCH_COMMIT); |
7559 | | |
7560 | 9.12k | case OP_PRUNE: |
7561 | 9.12k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM14); |
7562 | 7.41k | if (rrc != MATCH_NOMATCH) |
7563 | 1.59k | RRETURN(rrc); |
7564 | 5.82k | mb->verb_current_recurse = Fcurrent_recurse; |
7565 | 5.82k | RRETURN(MATCH_PRUNE); |
7566 | | |
7567 | 6.48k | case OP_PRUNE_ARG: |
7568 | 6.48k | Fmark = mb->nomatch_mark = Fecode + 2; |
7569 | 6.48k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM15); |
7570 | 6.21k | if (rrc != MATCH_NOMATCH) |
7571 | 3.92k | RRETURN(rrc); |
7572 | 2.28k | mb->verb_current_recurse = Fcurrent_recurse; |
7573 | 2.28k | RRETURN(MATCH_PRUNE); |
7574 | | |
7575 | 11.5k | case OP_SKIP: |
7576 | 11.5k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM16); |
7577 | 8.14k | if (rrc != MATCH_NOMATCH) |
7578 | 2.07k | RRETURN(rrc); |
7579 | 6.07k | mb->verb_skip_ptr = Feptr; // Pass back current position |
7580 | 6.07k | mb->verb_current_recurse = Fcurrent_recurse; |
7581 | 6.07k | RRETURN(MATCH_SKIP); |
7582 | | |
7583 | | /* Note that, for Perl compatibility, SKIP with an argument does NOT set |
7584 | | nomatch_mark. When a pattern match ends with a SKIP_ARG for which there was |
7585 | | not a matching mark, we have to re-run the match, ignoring the SKIP_ARG |
7586 | | that failed and any that precede it (either they also failed, or were not |
7587 | | triggered). To do this, we maintain a count of executed SKIP_ARGs. If a |
7588 | | SKIP_ARG gets to top level, the match is re-run with mb->ignore_skip_arg |
7589 | | set to the count of the one that failed. */ |
7590 | | |
7591 | 492k | case OP_SKIP_ARG: |
7592 | 492k | mb->skip_arg_count++; |
7593 | 492k | if (mb->skip_arg_count <= mb->ignore_skip_arg) |
7594 | 369k | { |
7595 | 369k | Fecode += PRIV(OP_lengths)[*Fecode] + Fecode[1]; |
7596 | 369k | break; |
7597 | 369k | } |
7598 | | |
7599 | 123k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM17); |
7600 | 122k | if (rrc != MATCH_NOMATCH) |
7601 | 63.7k | RRETURN(rrc); |
7602 | | |
7603 | | /* Pass back the current skip name and return the special MATCH_SKIP_ARG |
7604 | | return code. This will either be caught by a matching MARK, or get to the |
7605 | | top, where it causes a rematch with mb->ignore_skip_arg set to the value of |
7606 | | mb->skip_arg_count. */ |
7607 | | |
7608 | 58.4k | mb->verb_skip_ptr = Fecode + 2; |
7609 | 58.4k | mb->verb_current_recurse = Fcurrent_recurse; |
7610 | 58.4k | RRETURN(MATCH_SKIP_ARG); |
7611 | | |
7612 | | /* For THEN (and THEN_ARG) we pass back the address of the opcode, so that |
7613 | | the branch in which it occurs can be determined. */ |
7614 | | |
7615 | 41.9k | case OP_THEN: |
7616 | 41.9k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM18); |
7617 | 36.0k | if (rrc != MATCH_NOMATCH) |
7618 | 14.7k | RRETURN(rrc); |
7619 | 21.3k | mb->verb_ecode_ptr = Fecode; |
7620 | 21.3k | mb->verb_current_recurse = Fcurrent_recurse; |
7621 | 21.3k | RRETURN(MATCH_THEN); |
7622 | | |
7623 | 8.60k | case OP_THEN_ARG: |
7624 | 8.60k | Fmark = mb->nomatch_mark = Fecode + 2; |
7625 | 8.60k | RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM19); |
7626 | 6.42k | if (rrc != MATCH_NOMATCH) |
7627 | 4.04k | RRETURN(rrc); |
7628 | 2.37k | mb->verb_ecode_ptr = Fecode; |
7629 | 2.37k | mb->verb_current_recurse = Fcurrent_recurse; |
7630 | 2.37k | RRETURN(MATCH_THEN); |
7631 | | |
7632 | | |
7633 | | /* ===================================================================== */ |
7634 | | /* There's been some horrible disaster. Arrival here can only mean there is |
7635 | | something seriously wrong in the code above or the OP_xxx definitions. */ |
7636 | | |
7637 | | /* LCOV_EXCL_START */ |
7638 | 18 | default: |
7639 | 18 | PCRE2_DEBUG_UNREACHABLE(); |
7640 | 18 | return PCRE2_ERROR_INTERNAL; |
7641 | | /* LCOV_EXCL_STOP */ |
7642 | 40.3M | } |
7643 | | |
7644 | | /* Do not insert any code in here without much thought; it is assumed |
7645 | | that "continue" in the code above comes out to here to repeat the main |
7646 | | loop. */ |
7647 | | |
7648 | 40.3M | } // End of main loop |
7649 | | |
7650 | 0 | PCRE2_DEBUG_UNREACHABLE(); // Control should never reach here |
7651 | | |
7652 | | /* ========================================================================= */ |
7653 | | /* The RRETURN() macro jumps here. The number that is saved in Freturn_id |
7654 | | indicates which label we actually want to return to. The value in Frdepth is |
7655 | | the index number of the frame in the vector. The return value has been placed |
7656 | | in rrc. */ |
7657 | |
|
7658 | 0 | #define LBL(val) \ |
7659 | 18.2M | case val: \ |
7660 | 18.2M | goto L_RM##val; |
7661 | |
|
7662 | 20.6M | RETURN_SWITCH: |
7663 | 20.6M | if (Feptr > mb->last_used_ptr) |
7664 | 2.92M | mb->last_used_ptr = Feptr; |
7665 | 20.6M | if (Frdepth == 0) |
7666 | 2.36M | return rrc; // Exit from the top level |
7667 | 18.2M | F = (heapframe *)((char *)F - Fback_frame); // Backtrack |
7668 | 18.2M | mb->cb->callout_flags |= PCRE2_CALLOUT_BACKTRACK; // Note for callouts |
7669 | | |
7670 | | #ifdef DEBUG_SHOW_RMATCH |
7671 | | fprintf(stderr, "++ RETURN %d to RM%d\n", rrc, Freturn_id); |
7672 | | #endif |
7673 | | |
7674 | | // clang-format off |
7675 | 18.2M | switch (Freturn_id) |
7676 | 18.2M | { |
7677 | 9.39M | LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8) |
7678 | 290k | LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(16) |
7679 | 140k | LBL(17) LBL(18) LBL(19) LBL(20) LBL(21) LBL(22) LBL(23) LBL(24) |
7680 | 341k | LBL(25) LBL(26) LBL(27) LBL(28) LBL(29) LBL(30) LBL(31) LBL(32) |
7681 | 1.47M | LBL(33) LBL(34) LBL(35) LBL(36) LBL(37) LBL(38) LBL(39) |
7682 | | |
7683 | 0 | #ifdef SUPPORT_WIDE_CHARS |
7684 | 181k | LBL(100) LBL(101) LBL(102) LBL(103) |
7685 | 0 | #endif |
7686 | | |
7687 | 0 | #ifdef SUPPORT_UNICODE |
7688 | 40.0k | LBL(200) LBL(201) LBL(202) LBL(203) LBL(204) LBL(205) LBL(206) |
7689 | 191k | LBL(207) LBL(208) LBL(209) LBL(210) LBL(211) LBL(212) LBL(213) |
7690 | 511k | LBL(214) LBL(215) LBL(216) LBL(217) LBL(218) LBL(219) LBL(220) |
7691 | 414k | LBL(221) LBL(222) LBL(223) LBL(224) |
7692 | 0 | #endif |
7693 | | |
7694 | | /* LCOV_EXCL_START */ |
7695 | 0 | default: |
7696 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
7697 | 0 | return PCRE2_ERROR_INTERNAL; |
7698 | | /* LCOV_EXCL_STOP */ |
7699 | 18.2M | } |
7700 | | // clang-format on |
7701 | 18.2M | #undef LBL |
7702 | 18.2M | } |
7703 | | |
7704 | | |
7705 | | /************************************************* |
7706 | | * Match a Regular Expression * |
7707 | | *************************************************/ |
7708 | | |
7709 | | /* This function applies a compiled pattern to a subject string and picks out |
7710 | | portions of the string if it matches. Two elements in the vector are set for |
7711 | | each substring: the offsets to the start and end of the substring. |
7712 | | |
7713 | | Arguments: |
7714 | | code points to the compiled expression |
7715 | | subject points to the subject string |
7716 | | length length of subject string (may contain binary zeros) |
7717 | | start_offset where to start in the subject string |
7718 | | options option bits |
7719 | | match_data points to a match_data block |
7720 | | mcontext points a PCRE2 context |
7721 | | |
7722 | | Returns: > 0 => success; value is the number of ovector pairs filled |
7723 | | = 0 => success, but ovector is not big enough |
7724 | | = -1 => failed to match (PCRE2_ERROR_NOMATCH) |
7725 | | = -2 => partial match (PCRE2_ERROR_PARTIAL) |
7726 | | < -2 => some kind of unexpected problem |
7727 | | */ |
7728 | | |
7729 | | PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION |
7730 | | pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE start_offset, |
7731 | | uint32_t options, pcre2_match_data *match_data, pcre2_match_context *mcontext) |
7732 | 257k | { |
7733 | 257k | int rc; |
7734 | 257k | const uint8_t *start_bits = NULL; |
7735 | 257k | const pcre2_real_code *re = (const pcre2_real_code *)code; |
7736 | 257k | uint32_t original_options = options; |
7737 | | |
7738 | 257k | BOOL anchored; |
7739 | 257k | BOOL firstline; |
7740 | 257k | BOOL has_first_cu = FALSE; |
7741 | 257k | BOOL has_req_cu = FALSE; |
7742 | 257k | BOOL startline; |
7743 | | |
7744 | | #if PCRE2_CODE_UNIT_WIDTH == 8 |
7745 | | PCRE2_SPTR memchr_found_first_cu; |
7746 | | PCRE2_SPTR memchr_found_first_cu2; |
7747 | | #endif |
7748 | | |
7749 | 257k | PCRE2_UCHAR first_cu = 0; |
7750 | 257k | PCRE2_UCHAR first_cu2 = 0; |
7751 | 257k | PCRE2_UCHAR req_cu = 0; |
7752 | 257k | PCRE2_UCHAR req_cu2 = 0; |
7753 | | |
7754 | 257k | PCRE2_UCHAR null_str[1] = { 0xcd }; |
7755 | 257k | PCRE2_SPTR original_subject = subject; |
7756 | 257k | PCRE2_SPTR bumpalong_limit; |
7757 | 257k | PCRE2_SPTR end_subject; |
7758 | 257k | PCRE2_SPTR true_end_subject; |
7759 | 257k | PCRE2_SPTR start_match; |
7760 | 257k | PCRE2_SPTR req_cu_ptr; |
7761 | 257k | PCRE2_SPTR start_partial; |
7762 | 257k | PCRE2_SPTR match_partial; |
7763 | | |
7764 | | /* This flag is needed even when Unicode is not supported for convenience |
7765 | | (it is used by the IS_NEWLINE macro). */ |
7766 | | |
7767 | 257k | BOOL utf = FALSE; |
7768 | | |
7769 | 257k | #ifdef SUPPORT_UNICODE |
7770 | 257k | BOOL ucp = FALSE; |
7771 | 257k | BOOL allow_invalid; |
7772 | 257k | uint32_t fragment_options = 0; |
7773 | 257k | #endif /* SUPPORT_UNICODE */ |
7774 | | |
7775 | 257k | PCRE2_SIZE frame_size; |
7776 | 257k | PCRE2_SIZE heapframes_size; |
7777 | | |
7778 | | /* We need to have mb as a pointer to a match block, because the IS_NEWLINE |
7779 | | macro is used below, and it expects NLBLOCK to be defined as a pointer. */ |
7780 | | |
7781 | 257k | pcre2_callout_block cb; |
7782 | 257k | match_block actual_match_block; |
7783 | 257k | match_block *mb = &actual_match_block; |
7784 | | |
7785 | | /* Recognize NULL, length 0 as an empty string. */ |
7786 | | |
7787 | 257k | if (subject == NULL && length == 0) |
7788 | 0 | subject = null_str; |
7789 | | |
7790 | | /* Plausibility checks */ |
7791 | | |
7792 | 257k | if (match_data == NULL) |
7793 | 0 | return PCRE2_ERROR_NULL; |
7794 | 257k | if (code == NULL || subject == NULL) |
7795 | 0 | return match_data->rc = PCRE2_ERROR_NULL; |
7796 | 257k | if ((options & ~PUBLIC_MATCH_OPTIONS) != 0) |
7797 | 0 | return match_data->rc = PCRE2_ERROR_BADOPTION; |
7798 | | |
7799 | 257k | start_match = subject + start_offset; |
7800 | 257k | req_cu_ptr = start_match - 1; |
7801 | 257k | if (length == PCRE2_ZERO_TERMINATED) |
7802 | 0 | { |
7803 | 0 | length = PRIV(strlen)(subject); |
7804 | 0 | } |
7805 | | |
7806 | 257k | true_end_subject = end_subject = subject + length; |
7807 | | |
7808 | 257k | if (start_offset > length) |
7809 | 0 | return match_data->rc = PCRE2_ERROR_BADOFFSET; |
7810 | 257k | if (mcontext != NULL && mcontext->offset_limit != PCRE2_UNSET && |
7811 | 0 | mcontext->offset_limit > length) |
7812 | 0 | return match_data->rc = PCRE2_ERROR_BADOFFSETLIMITVALUE; |
7813 | | |
7814 | | /* Check that the first field in the block is the magic number. */ |
7815 | | |
7816 | 257k | if (re->magic_number != MAGIC_NUMBER) |
7817 | 0 | return match_data->rc = PCRE2_ERROR_BADMAGIC; |
7818 | | |
7819 | | /* Check the code unit width. */ |
7820 | | |
7821 | 257k | if ((re->flags & PCRE2_MODE_MASK) != PCRE2_CODE_UNIT_WIDTH / 8) |
7822 | 0 | return match_data->rc = PCRE2_ERROR_BADMODE; |
7823 | | |
7824 | | /* PCRE2_NOTEMPTY and PCRE2_NOTEMPTY_ATSTART are match-time flags in the |
7825 | | options variable for this function. Users of PCRE2 who are not calling the |
7826 | | function directly would like to have a way of setting these flags, in the same |
7827 | | way that they can set pcre2_compile() flags like PCRE2_NO_AUTO_POSSESS with |
7828 | | constructions like (*NO_AUTOPOSSESS). To enable this, (*NOTEMPTY) and |
7829 | | (*NOTEMPTY_ATSTART) set bits in the pattern's "flag" function which we now |
7830 | | transfer to the options for this function. The bits are guaranteed to be |
7831 | | adjacent, but do not have the same values. This bit of Boolean trickery assumes |
7832 | | that the match-time bits are not more significant than the flag bits. If by |
7833 | | accident this is not the case, a compile-time division by zero error will |
7834 | | occur. */ |
7835 | | |
7836 | 771k | #define FF (PCRE2_NOTEMPTY_SET | PCRE2_NE_ATST_SET) |
7837 | 514k | #define OO (PCRE2_NOTEMPTY | PCRE2_NOTEMPTY_ATSTART) |
7838 | 257k | options |= (re->flags & FF) / ((FF & (~FF + 1)) / (OO & (~OO + 1))); |
7839 | 257k | #undef FF |
7840 | 257k | #undef OO |
7841 | | |
7842 | | /* Initialize UTF/UCP parameters. */ |
7843 | | |
7844 | 257k | #ifdef SUPPORT_UNICODE |
7845 | 257k | utf = (re->overall_options & PCRE2_UTF) != 0; |
7846 | 257k | allow_invalid = (re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0; |
7847 | 257k | ucp = (re->overall_options & PCRE2_UCP) != 0; |
7848 | 257k | #endif /* SUPPORT_UNICODE */ |
7849 | | |
7850 | | /* Convert the partial matching flags into an integer. */ |
7851 | | |
7852 | 257k | mb->partial = ((options & PCRE2_PARTIAL_HARD) != 0) ? 2 |
7853 | 257k | : ((options & PCRE2_PARTIAL_SOFT) != 0) ? 1 |
7854 | 232k | : 0; |
7855 | | |
7856 | | /* Partial matching and PCRE2_ENDANCHORED are currently not allowed at the same |
7857 | | time. */ |
7858 | | |
7859 | 257k | if (mb->partial != 0 && ((re->overall_options | options) & PCRE2_ENDANCHORED) != 0) |
7860 | 0 | return match_data->rc = PCRE2_ERROR_BADOPTION; |
7861 | | |
7862 | | /* It is an error to set an offset limit without setting the flag at compile |
7863 | | time. */ |
7864 | | |
7865 | 257k | if (mcontext != NULL && mcontext->offset_limit != PCRE2_UNSET && |
7866 | 0 | (re->overall_options & PCRE2_USE_OFFSET_LIMIT) == 0) |
7867 | 0 | return match_data->rc = PCRE2_ERROR_BADOFFSETLIMIT; |
7868 | | |
7869 | | /* If the match data block was previously used with PCRE2_COPY_MATCHED_SUBJECT, |
7870 | | free the memory that was obtained. Set the field to NULL for match error |
7871 | | cases. */ |
7872 | | |
7873 | 257k | if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0) |
7874 | 0 | { |
7875 | 0 | match_data->memctl.free((void *)match_data->subject, match_data->memctl.memory_data); |
7876 | 0 | match_data->flags &= ~PCRE2_MD_COPIED_SUBJECT; |
7877 | 0 | } |
7878 | | |
7879 | 257k | match_data->subject = NULL; |
7880 | 257k | match_data->subject_length = 0; |
7881 | | |
7882 | | /* Zero the error offset in case the first code unit is invalid UTF. */ |
7883 | | |
7884 | 257k | match_data->startchar = 0; |
7885 | | |
7886 | | |
7887 | | /* ============================= JIT matching ============================== */ |
7888 | | |
7889 | | /* If the pattern was successfully studied with JIT support, we will run the |
7890 | | JIT executable instead of the rest of this function. Most options must be set |
7891 | | at compile time for the JIT code to be usable. */ |
7892 | | |
7893 | 257k | #ifdef SUPPORT_JIT |
7894 | 257k | if (re->executable_jit != NULL && (options & ~PUBLIC_JIT_MATCH_OPTIONS) == 0 && |
7895 | 0 | PRIV(jit_check_exec)(re->executable_jit, options)) |
7896 | 0 | { |
7897 | | /* Prepare for JIT matching. Check a UTF string for validity unless no check |
7898 | | is requested or invalid UTF can be handled. We check only the portion of the |
7899 | | subject that might be be inspected during matching - from the offset minus |
7900 | | the maximum lookbehind to the given length. This saves time when a small part |
7901 | | of a large subject is being matched by the use of a starting offset. Note that |
7902 | | the maximum lookbehind is a number of characters, not code units. */ |
7903 | |
|
7904 | 0 | #ifdef SUPPORT_UNICODE |
7905 | 0 | if (utf && (options & PCRE2_NO_UTF_CHECK) == 0 && !allow_invalid) |
7906 | 0 | { |
7907 | | /* For 8-bit and 16-bit UTF, check that the first code unit is a valid |
7908 | | character start. */ |
7909 | |
|
7910 | 0 | #if PCRE2_CODE_UNIT_WIDTH != 32 |
7911 | 0 | if (start_match < end_subject && NOT_FIRSTCU(*start_match)) |
7912 | 0 | { |
7913 | 0 | if (start_offset > 0) |
7914 | 0 | return match_data->rc = PCRE2_ERROR_BADUTFOFFSET; |
7915 | | #if PCRE2_CODE_UNIT_WIDTH == 8 |
7916 | | return match_data->rc = PCRE2_ERROR_UTF8_ERR20; // Isolated 0x80 byte |
7917 | | #else |
7918 | 0 | return match_data->rc = PCRE2_ERROR_UTF16_ERR3; // Isolated low surrogate |
7919 | 0 | #endif |
7920 | 0 | } |
7921 | 0 | #endif /* WIDTH != 32 */ |
7922 | | |
7923 | | /* Move back by the maximum lookbehind, just in case it happens at the very |
7924 | | start of matching. */ |
7925 | | |
7926 | 0 | #if PCRE2_CODE_UNIT_WIDTH != 32 |
7927 | 0 | for (unsigned int i = re->max_lookbehind; i > 0 && start_match > subject; i--) |
7928 | 0 | { |
7929 | 0 | start_match--; |
7930 | 0 | while (start_match > subject && |
7931 | | #if PCRE2_CODE_UNIT_WIDTH == 8 |
7932 | | (*start_match & 0xc0) == 0x80) |
7933 | | #else /* 16-bit */ |
7934 | 0 | (*start_match & 0xfc00) == 0xdc00) |
7935 | 0 | #endif |
7936 | 0 | start_match--; |
7937 | 0 | } |
7938 | | #else /* PCRE2_CODE_UNIT_WIDTH != 32 */ |
7939 | | |
7940 | | /* In the 32-bit library, one code unit equals one character. However, |
7941 | | we cannot just subtract the lookbehind and then compare pointers, because |
7942 | | a very large lookbehind could create an invalid pointer. */ |
7943 | | |
7944 | | if (start_offset >= re->max_lookbehind) |
7945 | | start_match -= re->max_lookbehind; |
7946 | | else |
7947 | | start_match = subject; |
7948 | | #endif /* PCRE2_CODE_UNIT_WIDTH != 32 */ |
7949 | | |
7950 | | /* Validate the relevant portion of the subject. Adjust the offset of an |
7951 | | invalid code point to be an absolute offset in the whole string. */ |
7952 | |
|
7953 | 0 | rc = PRIV(valid_utf)(start_match, length - (start_match - subject), &(match_data->startchar)); |
7954 | 0 | if (rc != 0) |
7955 | 0 | { |
7956 | 0 | match_data->startchar += start_match - subject; |
7957 | 0 | return match_data->rc = rc; |
7958 | 0 | } |
7959 | 0 | } |
7960 | 0 | #endif /* SUPPORT_UNICODE */ |
7961 | | |
7962 | 0 | rc = pcre2_jit_match(code, subject, length, start_offset, options, match_data, mcontext); |
7963 | | /* JIT must be able to perform the match. */ |
7964 | 0 | PCRE2_ASSERT(rc != PCRE2_ERROR_JIT_BADOPTION); |
7965 | |
|
7966 | 0 | match_data->options = original_options; |
7967 | 0 | if (rc >= 0 && (options & PCRE2_COPY_MATCHED_SUBJECT) != 0) |
7968 | 0 | { |
7969 | 0 | match_data->subject = |
7970 | 0 | match_data->memctl.malloc(CU2BYTES(length + 1), match_data->memctl.memory_data); |
7971 | 0 | if (match_data->subject == NULL) |
7972 | 0 | { |
7973 | 0 | match_data->subject_length = 0; |
7974 | 0 | return match_data->rc = PCRE2_ERROR_NOMEMORY; |
7975 | 0 | } |
7976 | | |
7977 | 0 | memcpy((void *)match_data->subject, subject, CU2BYTES(length)); |
7978 | 0 | ((PCRE2_UCHAR *)match_data->subject)[length] = 0; |
7979 | |
|
7980 | 0 | match_data->flags |= PCRE2_MD_COPIED_SUBJECT; |
7981 | 0 | } |
7982 | 0 | else |
7983 | 0 | { |
7984 | | /* When pcre2_jit_match sets the subject, it doesn't know what the |
7985 | | original passed-in pointer was. */ |
7986 | 0 | if (match_data->subject != NULL) |
7987 | 0 | match_data->subject = original_subject; |
7988 | 0 | } |
7989 | | |
7990 | 0 | return rc; |
7991 | 0 | } |
7992 | 257k | #endif /* SUPPORT_JIT */ |
7993 | | |
7994 | | /* ========================= End of JIT matching ========================== */ |
7995 | | |
7996 | | |
7997 | | /* Proceed with non-JIT matching. The default is to allow lookbehinds to the |
7998 | | start of the subject. A UTF check when there is a non-zero offset may change |
7999 | | this. */ |
8000 | | |
8001 | 257k | mb->check_subject = subject; |
8002 | | |
8003 | | /* Check the validity of UTF subject strings. The check happens only when |
8004 | | PCRE2_NO_CHECK_UTF is unset. |
8005 | | |
8006 | | We check only the portion of the subject that might be be inspected during |
8007 | | matching - from the offset minus the maximum lookbehind to the given length. |
8008 | | This saves time when a small part of a large subject is being matched by the |
8009 | | use of a starting offset. Note that the maximum lookbehind is a number of |
8010 | | characters, not code units. |
8011 | | |
8012 | | Note also that support for invalid UTF forces a check, overriding the setting |
8013 | | of PCRE2_NO_CHECK_UTF. */ |
8014 | | |
8015 | 257k | #ifdef SUPPORT_UNICODE |
8016 | 257k | if (utf && ((options & PCRE2_NO_UTF_CHECK) == 0 || allow_invalid)) |
8017 | 72.8k | { |
8018 | 72.8k | #if PCRE2_CODE_UNIT_WIDTH != 32 |
8019 | 72.8k | BOOL skipped_bad_start = FALSE; |
8020 | 72.8k | #endif |
8021 | | |
8022 | | /* For 8-bit and 16-bit UTF, check that the first code unit is a valid |
8023 | | character start. If we are handling invalid UTF, just skip over such code |
8024 | | units. Otherwise, give an appropriate error. */ |
8025 | | |
8026 | 72.8k | #if PCRE2_CODE_UNIT_WIDTH != 32 |
8027 | 72.8k | if (allow_invalid) |
8028 | 0 | { |
8029 | 0 | while (start_match < end_subject && NOT_FIRSTCU(*start_match)) |
8030 | 0 | { |
8031 | 0 | start_match++; |
8032 | 0 | skipped_bad_start = TRUE; |
8033 | 0 | } |
8034 | 0 | } |
8035 | 72.8k | else if (start_match < end_subject && NOT_FIRSTCU(*start_match)) |
8036 | 0 | { |
8037 | 0 | if (start_offset > 0) |
8038 | 0 | return match_data->rc = PCRE2_ERROR_BADUTFOFFSET; |
8039 | | #if PCRE2_CODE_UNIT_WIDTH == 8 |
8040 | | return match_data->rc = PCRE2_ERROR_UTF8_ERR20; // Isolated 0x80 byte |
8041 | | #else |
8042 | 0 | return match_data->rc = PCRE2_ERROR_UTF16_ERR3; // Isolated low surrogate |
8043 | 0 | #endif |
8044 | 0 | } |
8045 | 72.8k | #endif /* WIDTH != 32 */ |
8046 | | |
8047 | | /* The mb->check_subject field points to the start of UTF checking; |
8048 | | lookbehinds can go back no further than this. */ |
8049 | | |
8050 | 72.8k | mb->check_subject = start_match; |
8051 | | |
8052 | | /* Move back by the maximum lookbehind, just in case it happens at the very |
8053 | | start of matching, but don't do this if we skipped bad 8-bit or 16-bit code |
8054 | | units above. */ |
8055 | | |
8056 | 72.8k | #if PCRE2_CODE_UNIT_WIDTH != 32 |
8057 | 72.8k | if (!skipped_bad_start) |
8058 | 72.8k | { |
8059 | 72.8k | unsigned int i; |
8060 | 72.8k | for (i = re->max_lookbehind; i > 0 && mb->check_subject > subject; i--) |
8061 | 0 | { |
8062 | 0 | mb->check_subject--; |
8063 | 0 | while (mb->check_subject > subject && |
8064 | | #if PCRE2_CODE_UNIT_WIDTH == 8 |
8065 | | (*mb->check_subject & 0xc0) == 0x80) |
8066 | | #else /* 16-bit */ |
8067 | 0 | (*mb->check_subject & 0xfc00) == 0xdc00) |
8068 | 0 | #endif |
8069 | 0 | mb->check_subject--; |
8070 | 0 | } |
8071 | 72.8k | } |
8072 | | #else /* PCRE2_CODE_UNIT_WIDTH != 32 */ |
8073 | | |
8074 | | /* In the 32-bit library, one code unit equals one character. However, |
8075 | | we cannot just subtract the lookbehind and then compare pointers, because |
8076 | | a very large lookbehind could create an invalid pointer. */ |
8077 | | |
8078 | | if (start_offset >= re->max_lookbehind) |
8079 | | mb->check_subject -= re->max_lookbehind; |
8080 | | else |
8081 | | mb->check_subject = subject; |
8082 | | #endif /* PCRE2_CODE_UNIT_WIDTH != 32 */ |
8083 | | |
8084 | | /* Validate the relevant portion of the subject. There's a loop in case we |
8085 | | encounter bad UTF in the characters preceding start_match which we are |
8086 | | scanning because of a lookbehind. */ |
8087 | | |
8088 | 72.8k | for (;;) |
8089 | 72.8k | { |
8090 | 72.8k | rc = PRIV(valid_utf)(mb->check_subject, length - (mb->check_subject - subject), |
8091 | 72.8k | &(match_data->startchar)); |
8092 | | |
8093 | 72.8k | if (rc == 0) |
8094 | 72.8k | break; // Valid UTF string |
8095 | | |
8096 | | /* Invalid UTF string. Adjust the offset to be an absolute offset in the |
8097 | | whole string. If we are handling invalid UTF strings, set end_subject to |
8098 | | stop before the bad code unit, and set the options to "not end of line". |
8099 | | Otherwise return the error. */ |
8100 | | |
8101 | 13 | match_data->startchar += mb->check_subject - subject; |
8102 | 13 | if (!allow_invalid || rc > 0) |
8103 | 13 | return match_data->rc = rc; |
8104 | 0 | end_subject = subject + match_data->startchar; |
8105 | | |
8106 | | /* If the end precedes start_match, it means there is invalid UTF in the |
8107 | | extra code units we reversed over because of a lookbehind. Advance past the |
8108 | | first bad code unit, and then skip invalid character starting code units in |
8109 | | 8-bit and 16-bit modes, and try again with the original end point. */ |
8110 | |
|
8111 | 0 | if (end_subject < start_match) |
8112 | 0 | { |
8113 | 0 | mb->check_subject = end_subject + 1; |
8114 | 0 | #if PCRE2_CODE_UNIT_WIDTH != 32 |
8115 | 0 | while (mb->check_subject < start_match && NOT_FIRSTCU(*mb->check_subject)) |
8116 | 0 | mb->check_subject++; |
8117 | 0 | #endif |
8118 | 0 | end_subject = true_end_subject; |
8119 | 0 | } |
8120 | | |
8121 | | /* Otherwise, set the not end of line option, and do the match. */ |
8122 | | |
8123 | 0 | else |
8124 | 0 | { |
8125 | 0 | fragment_options = PCRE2_NOTEOL; |
8126 | 0 | break; |
8127 | 0 | } |
8128 | 0 | } |
8129 | 72.8k | } |
8130 | 256k | #endif /* SUPPORT_UNICODE */ |
8131 | | |
8132 | | /* A NULL match context means "use a default context", but we take the memory |
8133 | | control functions from the pattern. */ |
8134 | | |
8135 | 256k | if (mcontext == NULL) |
8136 | 0 | { |
8137 | 0 | mcontext = (pcre2_match_context *)(&PRIV(default_match_context)); |
8138 | 0 | mb->memctl = re->memctl; |
8139 | 0 | } |
8140 | 256k | else |
8141 | 256k | { |
8142 | 256k | mb->memctl = mcontext->memctl; |
8143 | 256k | } |
8144 | | |
8145 | 256k | anchored = ((re->overall_options | options) & PCRE2_ANCHORED) != 0; |
8146 | 256k | firstline = !anchored && (re->overall_options & PCRE2_FIRSTLINE) != 0; |
8147 | 256k | startline = (re->flags & PCRE2_STARTLINE) != 0; |
8148 | 256k | bumpalong_limit = |
8149 | 256k | (mcontext->offset_limit == PCRE2_UNSET) ? true_end_subject : subject + mcontext->offset_limit; |
8150 | | |
8151 | | /* Initialize and set up the fixed fields in the callout block, with a pointer |
8152 | | in the match block. */ |
8153 | | |
8154 | 256k | mb->cb = &cb; |
8155 | 256k | cb.version = 2; |
8156 | 256k | cb.subject = subject; |
8157 | 256k | cb.subject_length = (PCRE2_SIZE)(end_subject - subject); |
8158 | 256k | cb.callout_flags = 0; |
8159 | | |
8160 | | /* Fill in the remaining fields in the match block, except for moptions, which |
8161 | | gets set later. */ |
8162 | | |
8163 | 256k | mb->callout = mcontext->callout; |
8164 | 256k | mb->callout_data = mcontext->callout_data; |
8165 | | |
8166 | 256k | mb->start_subject = subject; |
8167 | 256k | mb->start_offset = start_offset; |
8168 | 256k | mb->end_subject = end_subject; |
8169 | 256k | mb->true_end_subject = true_end_subject; |
8170 | 256k | mb->hasthen = (re->flags & PCRE2_HASTHEN) != 0; |
8171 | 256k | mb->hasbsk = (re->flags & PCRE2_HASBSK) != 0; |
8172 | 256k | mb->allowemptypartial = (re->max_lookbehind > 0) || (re->flags & PCRE2_MATCH_EMPTY) != 0; |
8173 | 256k | mb->allowlookaroundbsk = (re->extra_options & PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) != 0; |
8174 | 256k | mb->poptions = re->overall_options; // Pattern options |
8175 | 256k | mb->ignore_skip_arg = 0; |
8176 | 256k | mb->mark = mb->nomatch_mark = NULL; // In case never set |
8177 | | |
8178 | | /* The name table is needed for finding all the numbers associated with a |
8179 | | given name, for condition testing. The code follows the name table. */ |
8180 | | |
8181 | 256k | mb->name_table = (PCRE2_SPTR)((const uint8_t *)re + sizeof(pcre2_real_code)); |
8182 | 256k | mb->name_count = re->name_count; |
8183 | 256k | mb->name_entry_size = re->name_entry_size; |
8184 | 256k | mb->start_code = (PCRE2_SPTR)((const uint8_t *)re + re->code_start); |
8185 | | |
8186 | | /* Process the \R and newline settings. */ |
8187 | | |
8188 | 256k | mb->bsr_convention = re->bsr_convention; |
8189 | 256k | mb->nltype = NLTYPE_FIXED; |
8190 | 256k | switch (re->newline_convention) |
8191 | 256k | { |
8192 | 84 | case PCRE2_NEWLINE_CR: |
8193 | 84 | mb->nllen = 1; |
8194 | 84 | mb->nl[0] = CHAR_CR; |
8195 | 84 | break; |
8196 | | |
8197 | 256k | case PCRE2_NEWLINE_LF: |
8198 | 256k | mb->nllen = 1; |
8199 | 256k | mb->nl[0] = CHAR_NL; |
8200 | 256k | break; |
8201 | | |
8202 | 0 | case PCRE2_NEWLINE_NUL: |
8203 | 0 | mb->nllen = 1; |
8204 | 0 | mb->nl[0] = CHAR_NUL; |
8205 | 0 | break; |
8206 | | |
8207 | 0 | case PCRE2_NEWLINE_CRLF: |
8208 | 0 | mb->nllen = 2; |
8209 | 0 | mb->nl[0] = CHAR_CR; |
8210 | 0 | mb->nl[1] = CHAR_NL; |
8211 | 0 | break; |
8212 | | |
8213 | 0 | case PCRE2_NEWLINE_ANY: |
8214 | 0 | mb->nltype = NLTYPE_ANY; |
8215 | 0 | break; |
8216 | | |
8217 | 0 | case PCRE2_NEWLINE_ANYCRLF: |
8218 | 0 | mb->nltype = NLTYPE_ANYCRLF; |
8219 | 0 | break; |
8220 | | |
8221 | | /* LCOV_EXCL_START */ |
8222 | 0 | default: |
8223 | 0 | PCRE2_DEBUG_UNREACHABLE(); |
8224 | 0 | return match_data->rc = PCRE2_ERROR_INTERNAL; |
8225 | | /* LCOV_EXCL_STOP */ |
8226 | 256k | } |
8227 | | |
8228 | | /* The backtracking frames have fixed data at the front, and a PCRE2_SIZE |
8229 | | vector at the end, whose size depends on the number of capturing parentheses in |
8230 | | the pattern. It is not used at all if there are no capturing parentheses. |
8231 | | |
8232 | | frame_size is the total size of each frame |
8233 | | match_data->heapframes is the pointer to the frames vector |
8234 | | match_data->heapframes_size is the allocated size of the vector |
8235 | | |
8236 | | We must pad the frame_size for alignment to ensure subsequent frames are as |
8237 | | aligned as heapframe. Whilst ovector is word-aligned due to being a PCRE2_SIZE |
8238 | | array, that does not guarantee it is suitably aligned for pointers, as some |
8239 | | architectures have pointers that are larger than a size_t. */ |
8240 | | |
8241 | 256k | frame_size = (offsetof(heapframe, ovector) + re->top_bracket * 2 * sizeof(PCRE2_SIZE) + |
8242 | 256k | HEAPFRAME_ALIGNMENT - 1) & |
8243 | 256k | ~(HEAPFRAME_ALIGNMENT - 1); |
8244 | | |
8245 | | /* Limits set in the pattern override the match context only if they are |
8246 | | smaller. */ |
8247 | | |
8248 | 256k | mb->heap_limit = |
8249 | 256k | ((mcontext->heap_limit < re->limit_heap) ? mcontext->heap_limit : re->limit_heap); |
8250 | | |
8251 | 256k | mb->match_limit = |
8252 | 256k | (mcontext->match_limit < re->limit_match) ? mcontext->match_limit : re->limit_match; |
8253 | | |
8254 | 256k | mb->match_limit_depth = |
8255 | 256k | (mcontext->depth_limit < re->limit_depth) ? mcontext->depth_limit : re->limit_depth; |
8256 | | |
8257 | | /* If a pattern has very many capturing parentheses, the frame size may be very |
8258 | | large. Set the initial frame vector size to ensure that there are at least 10 |
8259 | | available frames, but enforce a minimum of START_FRAMES_SIZE. If this is |
8260 | | greater than the heap limit, get as large a vector as possible. */ |
8261 | | |
8262 | 256k | heapframes_size = frame_size * START_FRAMES_COUNT; |
8263 | 256k | if (heapframes_size < START_FRAMES_SIZE) |
8264 | 256k | heapframes_size = START_FRAMES_SIZE; |
8265 | 256k | if (heapframes_size / 1024 > mb->heap_limit) |
8266 | 0 | { |
8267 | 0 | PCRE2_SIZE max_size = 1024 * mb->heap_limit; |
8268 | 0 | if (max_size < frame_size) |
8269 | 0 | return match_data->rc = PCRE2_ERROR_HEAPLIMIT; |
8270 | 0 | heapframes_size = max_size; |
8271 | 0 | } |
8272 | | |
8273 | | /* If an existing frame vector in the match_data block is large enough, we can |
8274 | | use it. Otherwise, free any pre-existing vector and get a new one. */ |
8275 | | |
8276 | 256k | if (match_data->heapframes_size < heapframes_size) |
8277 | 72.6k | { |
8278 | 72.6k | match_data->memctl.free(match_data->heapframes, match_data->memctl.memory_data); |
8279 | 72.6k | match_data->heapframes = |
8280 | 72.6k | match_data->memctl.malloc(heapframes_size, match_data->memctl.memory_data); |
8281 | 72.6k | if (match_data->heapframes == NULL) |
8282 | 0 | { |
8283 | 0 | match_data->heapframes_size = 0; |
8284 | 0 | return match_data->rc = PCRE2_ERROR_NOMEMORY; |
8285 | 0 | } |
8286 | | |
8287 | 72.6k | match_data->heapframes_size = heapframes_size; |
8288 | 72.6k | } |
8289 | | |
8290 | | /* Write to the ovector within the first frame to mark every capture unset and |
8291 | | to avoid uninitialized memory read errors when it is copied to a new frame. */ |
8292 | | |
8293 | 256k | memset((char *)(match_data->heapframes) + offsetof(heapframe, ovector), 0xff, |
8294 | 256k | frame_size - offsetof(heapframe, ovector)); |
8295 | | |
8296 | | /* Pointers to the individual character tables */ |
8297 | | |
8298 | 256k | mb->lcc = re->tables + lcc_offset; |
8299 | 256k | mb->fcc = re->tables + fcc_offset; |
8300 | 256k | mb->ctypes = re->tables + ctypes_offset; |
8301 | | |
8302 | | /* Set up the first code unit to match, if available. If there's no first code |
8303 | | unit there may be a bitmap of possible first characters. */ |
8304 | | |
8305 | 256k | if ((re->flags & PCRE2_FIRSTSET) != 0) |
8306 | 60.7k | { |
8307 | 60.7k | has_first_cu = TRUE; |
8308 | 60.7k | first_cu = first_cu2 = (PCRE2_UCHAR)(re->first_codeunit); |
8309 | 60.7k | if ((re->flags & PCRE2_FIRSTCASELESS) != 0) |
8310 | 2.58k | { |
8311 | 2.58k | first_cu2 = TABLE_GET(first_cu, mb->fcc, first_cu); |
8312 | 2.58k | #ifdef SUPPORT_UNICODE |
8313 | | #if PCRE2_CODE_UNIT_WIDTH == 8 |
8314 | | if (first_cu > 127 && ucp && !utf) |
8315 | | first_cu2 = UCD_OTHERCASE(first_cu); |
8316 | | #else |
8317 | 2.58k | if (first_cu > 127 && (utf || ucp)) |
8318 | 978 | first_cu2 = UCD_OTHERCASE(first_cu); |
8319 | 2.58k | #endif |
8320 | 2.58k | #endif /* SUPPORT_UNICODE */ |
8321 | 2.58k | } |
8322 | 60.7k | } |
8323 | 196k | else if (!startline && (re->flags & PCRE2_FIRSTMAPSET) != 0) |
8324 | 45.7k | start_bits = re->start_bitmap; |
8325 | | |
8326 | | /* There may also be a "last known required character" set. */ |
8327 | | |
8328 | 256k | if ((re->flags & PCRE2_LASTSET) != 0) |
8329 | 106k | { |
8330 | 106k | has_req_cu = TRUE; |
8331 | 106k | req_cu = req_cu2 = (PCRE2_UCHAR)(re->last_codeunit); |
8332 | 106k | if ((re->flags & PCRE2_LASTCASELESS) != 0) |
8333 | 2.94k | { |
8334 | 2.94k | req_cu2 = TABLE_GET(req_cu, mb->fcc, req_cu); |
8335 | 2.94k | #ifdef SUPPORT_UNICODE |
8336 | | #if PCRE2_CODE_UNIT_WIDTH == 8 |
8337 | | if (req_cu > 127 && ucp && !utf) |
8338 | | req_cu2 = UCD_OTHERCASE(req_cu); |
8339 | | #else |
8340 | 2.94k | if (req_cu > 127 && (utf || ucp)) |
8341 | 1.63k | req_cu2 = UCD_OTHERCASE(req_cu); |
8342 | 2.94k | #endif |
8343 | 2.94k | #endif /* SUPPORT_UNICODE */ |
8344 | 2.94k | } |
8345 | 106k | } |
8346 | | |
8347 | | |
8348 | | /* ==========================================================================*/ |
8349 | | |
8350 | | /* Loop for handling unanchored repeated matching attempts; for anchored regexs |
8351 | | the loop runs just once. */ |
8352 | | |
8353 | 256k | #ifdef SUPPORT_UNICODE |
8354 | 256k | FRAGMENT_RESTART: |
8355 | 256k | #endif |
8356 | | |
8357 | 256k | start_partial = match_partial = NULL; |
8358 | 256k | mb->hitend = FALSE; |
8359 | | |
8360 | | #if PCRE2_CODE_UNIT_WIDTH == 8 |
8361 | | memchr_found_first_cu = NULL; |
8362 | | memchr_found_first_cu2 = NULL; |
8363 | | #endif |
8364 | | |
8365 | 256k | for (;;) |
8366 | 2.54M | { |
8367 | 2.54M | PCRE2_SPTR new_start_match; |
8368 | | |
8369 | | /* ----------------- Start of match optimizations ---------------- */ |
8370 | | |
8371 | | /* There are some optimizations that avoid running the match if a known |
8372 | | starting point is not found, or if a known later code unit is not present. |
8373 | | However, there is an option (settable at compile time) that disables these, |
8374 | | for testing and for ensuring that all callouts do actually occur. */ |
8375 | | |
8376 | 2.54M | if ((re->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0) |
8377 | 1.55M | { |
8378 | | /* If firstline is TRUE, the start of the match is constrained to the first |
8379 | | line of a multiline string. That is, the match must be before or at the |
8380 | | first newline following the start of matching. Temporarily adjust |
8381 | | end_subject so that we stop the scans for a first code unit at a newline. |
8382 | | If the match fails at the newline, later code breaks the loop. */ |
8383 | | |
8384 | 1.55M | if (firstline) |
8385 | 166k | { |
8386 | 166k | PCRE2_SPTR t = start_match; |
8387 | 166k | #ifdef SUPPORT_UNICODE |
8388 | 166k | if (utf) |
8389 | 74.7k | { |
8390 | 8.98M | while (t < end_subject && !IS_NEWLINE(t)) |
8391 | 8.91M | { |
8392 | 8.91M | t++; |
8393 | 8.91M | ACROSSCHAR(t < end_subject, t, t++); |
8394 | 8.91M | } |
8395 | 74.7k | } |
8396 | 92.0k | else |
8397 | 92.0k | #endif |
8398 | 11.6M | while (t < end_subject && !IS_NEWLINE(t)) |
8399 | 11.5M | t++; |
8400 | 166k | end_subject = t; |
8401 | 166k | } |
8402 | | |
8403 | | /* Anchored: check the first code unit if one is recorded. This may seem |
8404 | | pointless but it can help in detecting a no match case without scanning for |
8405 | | the required code unit. */ |
8406 | | |
8407 | 1.55M | if (anchored) |
8408 | 30.3k | { |
8409 | 30.3k | if (has_first_cu || start_bits != NULL) |
8410 | 17.5k | { |
8411 | 17.5k | BOOL ok = start_match < end_subject; |
8412 | 17.5k | if (ok) |
8413 | 17.5k | { |
8414 | 17.5k | PCRE2_UCHAR c = *start_match; |
8415 | 17.5k | ok = has_first_cu && (c == first_cu || c == first_cu2); |
8416 | 17.5k | if (!ok && start_bits != NULL) |
8417 | 6.00k | { |
8418 | 6.00k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
8419 | 6.00k | if (c > 255) |
8420 | 749 | c = 255; |
8421 | 6.00k | #endif |
8422 | 6.00k | ok = (start_bits[c / 8] & (1u << (c & 7))) != 0; |
8423 | 6.00k | } |
8424 | 17.5k | } |
8425 | | |
8426 | 17.5k | if (!ok) |
8427 | 9.21k | { |
8428 | 9.21k | rc = MATCH_NOMATCH; |
8429 | 9.21k | break; |
8430 | 9.21k | } |
8431 | 17.5k | } |
8432 | 30.3k | } |
8433 | | |
8434 | | /* Not anchored. Advance to a unique first code unit if there is one. */ |
8435 | | |
8436 | 1.52M | else |
8437 | 1.52M | { |
8438 | 1.52M | if (has_first_cu) |
8439 | 131k | { |
8440 | 131k | if (first_cu != first_cu2) // Caseless |
8441 | 6.63k | { |
8442 | | /* In 16-bit and 32_bit modes we have to do our own search, so can |
8443 | | look for both cases at once. */ |
8444 | | |
8445 | 6.63k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
8446 | 6.63k | PCRE2_UCHAR smc; |
8447 | 44.9k | while (start_match < end_subject && (smc = *start_match) != first_cu && |
8448 | 39.2k | smc != first_cu2) |
8449 | 38.2k | start_match++; |
8450 | | #else |
8451 | | /* In 8-bit mode, the use of memchr() gives a big speed up, even |
8452 | | though we have to call it twice in order to find the earliest |
8453 | | occurrence of the code unit in either of its cases. Caching is used |
8454 | | to remember the positions of previously found code units. This can |
8455 | | make a huge difference when the strings are very long and only one |
8456 | | case is actually present. */ |
8457 | | |
8458 | | PCRE2_SPTR pp1 = NULL; |
8459 | | PCRE2_SPTR pp2 = NULL; |
8460 | | PCRE2_SIZE searchlength = end_subject - start_match; |
8461 | | |
8462 | | /* If we haven't got a previously found position for first_cu, or if |
8463 | | the current starting position is later, we need to do a search. If |
8464 | | the code unit is not found, set it to the end. */ |
8465 | | |
8466 | | if (memchr_found_first_cu == NULL || start_match > memchr_found_first_cu) |
8467 | | { |
8468 | | pp1 = memchr(start_match, first_cu, searchlength); |
8469 | | memchr_found_first_cu = (pp1 == NULL) ? end_subject : pp1; |
8470 | | } |
8471 | | |
8472 | | /* If the start is before a previously found position, use the |
8473 | | previous position, or NULL if a previous search failed. */ |
8474 | | |
8475 | | else |
8476 | | pp1 = (memchr_found_first_cu == end_subject) ? NULL : memchr_found_first_cu; |
8477 | | |
8478 | | /* Do the same thing for the other case. */ |
8479 | | |
8480 | | if (memchr_found_first_cu2 == NULL || start_match > memchr_found_first_cu2) |
8481 | | { |
8482 | | pp2 = memchr(start_match, first_cu2, searchlength); |
8483 | | memchr_found_first_cu2 = (pp2 == NULL) ? end_subject : pp2; |
8484 | | } |
8485 | | |
8486 | | else |
8487 | | { |
8488 | | pp2 = (memchr_found_first_cu2 == end_subject) ? NULL : memchr_found_first_cu2; |
8489 | | } |
8490 | | |
8491 | | /* Set the start to the end of the subject if neither case was found. |
8492 | | Otherwise, use the earlier found point. */ |
8493 | | |
8494 | | if (pp1 == NULL) |
8495 | | start_match = (pp2 == NULL) ? end_subject : pp2; |
8496 | | else |
8497 | | start_match = (pp2 == NULL || pp1 < pp2) ? pp1 : pp2; |
8498 | | |
8499 | | #endif /* 8-bit handling */ |
8500 | 6.63k | } |
8501 | | |
8502 | | /* The caseful case is much simpler. */ |
8503 | | |
8504 | 125k | else |
8505 | 125k | { |
8506 | 125k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
8507 | 1.96M | while (start_match < end_subject && *start_match != first_cu) |
8508 | 1.83M | start_match++; |
8509 | | #else |
8510 | | start_match = memchr(start_match, first_cu, end_subject - start_match); |
8511 | | if (start_match == NULL) |
8512 | | start_match = end_subject; |
8513 | | #endif |
8514 | 125k | } |
8515 | | |
8516 | | /* If we can't find the required first code unit, having reached the |
8517 | | true end of the subject, break the bumpalong loop, to force a match |
8518 | | failure, except when doing partial matching, when we let the next cycle |
8519 | | run at the end of the subject. To see why, consider the pattern |
8520 | | /(?<=abc)def/, which partially matches "abc", even though the string |
8521 | | does not contain the starting character "d". If we have not reached the |
8522 | | true end of the subject (PCRE2_FIRSTLINE caused end_subject to be |
8523 | | temporarily modified) we also let the cycle run, because the matching |
8524 | | string is legitimately allowed to start with the first code unit of a |
8525 | | newline. */ |
8526 | | |
8527 | 131k | if (mb->partial == 0 && start_match >= mb->end_subject) |
8528 | 20.2k | { |
8529 | 20.2k | rc = MATCH_NOMATCH; |
8530 | 20.2k | break; |
8531 | 20.2k | } |
8532 | 131k | } |
8533 | | |
8534 | | /* If there's no first code unit, advance to just after a linebreak for a |
8535 | | multiline match if required. */ |
8536 | | |
8537 | 1.39M | else if (startline) |
8538 | 4.55k | { |
8539 | 4.55k | if (start_match > mb->start_subject + start_offset) |
8540 | 2.58k | { |
8541 | 2.58k | #ifdef SUPPORT_UNICODE |
8542 | 2.58k | if (utf) |
8543 | 812 | { |
8544 | 5.69k | while (start_match < end_subject && !WAS_NEWLINE(start_match)) |
8545 | 4.88k | { |
8546 | 4.88k | start_match++; |
8547 | 4.88k | ACROSSCHAR(start_match < end_subject, start_match, start_match++); |
8548 | 4.88k | } |
8549 | 812 | } |
8550 | 1.77k | else |
8551 | 1.77k | #endif |
8552 | 11.8k | while (start_match < end_subject && !WAS_NEWLINE(start_match)) |
8553 | 10.0k | start_match++; |
8554 | | |
8555 | | /* If we have just passed a CR and the newline option is ANY or |
8556 | | ANYCRLF, and we are now at a LF, advance the match position by one |
8557 | | more code unit. */ |
8558 | | |
8559 | 2.58k | if (start_match[-1] == CHAR_CR && |
8560 | 536 | (mb->nltype == NLTYPE_ANY || mb->nltype == NLTYPE_ANYCRLF) && |
8561 | 0 | start_match < end_subject && *start_match == CHAR_NL) |
8562 | 0 | start_match++; |
8563 | 2.58k | } |
8564 | 4.55k | } |
8565 | | |
8566 | | /* If there's no first code unit or a requirement for a multiline line |
8567 | | start, advance to a non-unique first code unit if any have been |
8568 | | identified. The bitmap contains only 256 bits. When code units are 16 or |
8569 | | 32 bits wide, all code units greater than 254 set the 255 bit. */ |
8570 | | |
8571 | 1.38M | else if (start_bits != NULL) |
8572 | 448k | { |
8573 | 862k | while (start_match < end_subject) |
8574 | 850k | { |
8575 | 850k | uint32_t c = *start_match; |
8576 | 850k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
8577 | 850k | if (c > 255) |
8578 | 291k | c = 255; |
8579 | 850k | #endif |
8580 | 850k | if ((start_bits[c / 8] & (1u << (c & 7))) != 0) |
8581 | 437k | break; |
8582 | 413k | start_match++; |
8583 | 413k | } |
8584 | | |
8585 | | /* See comment above in first_cu checking about the next few lines. */ |
8586 | | |
8587 | 448k | if (mb->partial == 0 && start_match >= mb->end_subject) |
8588 | 5.88k | { |
8589 | 5.88k | rc = MATCH_NOMATCH; |
8590 | 5.88k | break; |
8591 | 5.88k | } |
8592 | 448k | } |
8593 | 1.52M | } // End first code unit handling |
8594 | | |
8595 | | /* Restore fudged end_subject */ |
8596 | | |
8597 | 1.51M | end_subject = mb->end_subject; |
8598 | | |
8599 | | /* The following two optimizations must be disabled for partial matching. */ |
8600 | | |
8601 | 1.51M | if (mb->partial == 0) |
8602 | 1.06M | { |
8603 | 1.06M | PCRE2_SPTR p; |
8604 | | |
8605 | | /* The minimum matching length is a lower bound; no string of that length |
8606 | | may actually match the pattern. Although the value is, strictly, in |
8607 | | characters, we treat it as code units to avoid spending too much time in |
8608 | | this optimization. */ |
8609 | | |
8610 | 1.06M | if (end_subject - start_match < re->minlength) |
8611 | 37.6k | { |
8612 | 37.6k | rc = MATCH_NOMATCH; |
8613 | 37.6k | break; |
8614 | 37.6k | } |
8615 | | |
8616 | | /* If req_cu is set, we know that that code unit must appear in the |
8617 | | subject for the (non-partial) match to succeed. If the first code unit is |
8618 | | set, req_cu must be later in the subject; otherwise the test starts at |
8619 | | the match point. This optimization can save a huge amount of backtracking |
8620 | | in patterns with nested unlimited repeats that aren't going to match. |
8621 | | Writing separate code for caseful/caseless versions makes it go faster, |
8622 | | as does using an autoincrement and backing off on a match. As in the case |
8623 | | of the first code unit, using memchr() in the 8-bit library gives a big |
8624 | | speed up. Unlike the first_cu check above, we do not need to call |
8625 | | memchr() twice in the caseless case because we only need to check for the |
8626 | | presence of the character in either case, not find the first occurrence. |
8627 | | |
8628 | | The search can be skipped if the code unit was found later than the |
8629 | | current starting point in a previous iteration of the bumpalong loop. |
8630 | | |
8631 | | HOWEVER: when the subject string is very, very long, searching to its end |
8632 | | can take a long time, and give bad performance on quite ordinary |
8633 | | anchored patterns. This showed up when somebody was matching something |
8634 | | like /^\d+C/ on a 32-megabyte string... so we don't do this when the |
8635 | | string is sufficiently long, but it's worth searching a lot more for |
8636 | | unanchored patterns. */ |
8637 | | |
8638 | 1.03M | p = start_match + (has_first_cu ? 1 : 0); |
8639 | 1.03M | if (has_req_cu && p > req_cu_ptr) |
8640 | 79.6k | { |
8641 | 79.6k | PCRE2_SIZE check_length = end_subject - start_match; |
8642 | | |
8643 | 79.6k | if (check_length < REQ_CU_MAX || (!anchored && check_length < REQ_CU_MAX * 1000)) |
8644 | 79.6k | { |
8645 | 79.6k | if (req_cu != req_cu2) // Caseless |
8646 | 3.21k | { |
8647 | 3.21k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
8648 | 64.4k | while (p < end_subject) |
8649 | 64.3k | { |
8650 | 64.3k | uint32_t pp = *p++; |
8651 | 64.3k | if (pp == req_cu || pp == req_cu2) |
8652 | 3.09k | { |
8653 | 3.09k | p--; |
8654 | 3.09k | break; |
8655 | 3.09k | } |
8656 | 64.3k | } |
8657 | | #else /* 8-bit code units */ |
8658 | | PCRE2_SPTR pp = p; |
8659 | | p = memchr(pp, req_cu, end_subject - pp); |
8660 | | if (p == NULL) |
8661 | | { |
8662 | | p = memchr(pp, req_cu2, end_subject - pp); |
8663 | | if (p == NULL) |
8664 | | p = end_subject; |
8665 | | } |
8666 | | #endif /* PCRE2_CODE_UNIT_WIDTH != 8 */ |
8667 | 3.21k | } |
8668 | | |
8669 | | /* The caseful case */ |
8670 | | |
8671 | 76.3k | else |
8672 | 76.3k | { |
8673 | 76.3k | #if PCRE2_CODE_UNIT_WIDTH != 8 |
8674 | 1.96M | while (p < end_subject) |
8675 | 1.96M | { |
8676 | 1.96M | if (*p++ == req_cu) |
8677 | 73.7k | { |
8678 | 73.7k | p--; |
8679 | 73.7k | break; |
8680 | 73.7k | } |
8681 | 1.96M | } |
8682 | | |
8683 | | #else /* 8-bit code units */ |
8684 | | p = memchr(p, req_cu, end_subject - p); |
8685 | | if (p == NULL) |
8686 | | p = end_subject; |
8687 | | #endif |
8688 | 76.3k | } |
8689 | | |
8690 | | /* If we can't find the required code unit, break the bumpalong loop, |
8691 | | forcing a match failure. */ |
8692 | | |
8693 | 79.6k | if (p >= end_subject) |
8694 | 2.78k | { |
8695 | 2.78k | rc = MATCH_NOMATCH; |
8696 | 2.78k | break; |
8697 | 2.78k | } |
8698 | | |
8699 | | /* If we have found the required code unit, save the point where we |
8700 | | found it, so that we don't search again next time round the bumpalong |
8701 | | loop if the start hasn't yet passed this code unit. */ |
8702 | | |
8703 | 76.8k | req_cu_ptr = p; |
8704 | 76.8k | } |
8705 | 79.6k | } |
8706 | 1.03M | } |
8707 | 1.51M | } |
8708 | | |
8709 | | /* ------------ End of start of match optimizations ------------ */ |
8710 | | |
8711 | | /* Give no match if we have passed the bumpalong limit. */ |
8712 | | |
8713 | 2.47M | if (start_match > bumpalong_limit) |
8714 | 0 | { |
8715 | 0 | rc = MATCH_NOMATCH; |
8716 | 0 | break; |
8717 | 0 | } |
8718 | | |
8719 | | /* OK, we can now run the match. If "hitend" is set afterwards, remember the |
8720 | | first starting point for which a partial match was found. */ |
8721 | | |
8722 | 2.47M | cb.start_match = (PCRE2_SIZE)(start_match - subject); |
8723 | 2.47M | cb.callout_flags |= PCRE2_CALLOUT_STARTMATCH; |
8724 | | |
8725 | 2.47M | mb->start_used_ptr = start_match; |
8726 | 2.47M | mb->last_used_ptr = start_match; |
8727 | 2.47M | #ifdef SUPPORT_UNICODE |
8728 | 2.47M | mb->moptions = options | fragment_options; |
8729 | | #else |
8730 | | mb->moptions = options; |
8731 | | #endif |
8732 | 2.47M | mb->match_call_count = 0; |
8733 | 2.47M | mb->end_offset_top = 0; |
8734 | 2.47M | mb->skip_arg_count = 0; |
8735 | | |
8736 | | #ifdef DEBUG_SHOW_OPS |
8737 | | fprintf(stderr, "++ Calling match()\n"); |
8738 | | #endif |
8739 | | |
8740 | 2.47M | rc = match(start_match, mb->start_code, re->top_bracket, frame_size, match_data, mb); |
8741 | | |
8742 | | #ifdef DEBUG_SHOW_OPS |
8743 | | fprintf(stderr, "++ match() returned %d\n\n", rc); |
8744 | | #endif |
8745 | | |
8746 | 2.47M | if (mb->hitend && start_partial == NULL) |
8747 | 24.7k | { |
8748 | 24.7k | start_partial = mb->start_used_ptr; |
8749 | 24.7k | match_partial = start_match; |
8750 | 24.7k | } |
8751 | | |
8752 | 2.47M | switch (rc) |
8753 | 2.47M | { |
8754 | | /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched |
8755 | | the SKIP's arg was not found. In this circumstance, Perl ignores the SKIP |
8756 | | entirely. The only way we can do that is to re-do the match at the same |
8757 | | point, with a flag to force SKIP with an argument to be ignored. Just |
8758 | | treating this case as NOMATCH does not work because it does not check other |
8759 | | alternatives in patterns such as A(*SKIP:A)B|AC when the subject is AC. */ |
8760 | | |
8761 | 56.2k | case MATCH_SKIP_ARG: |
8762 | 56.2k | new_start_match = start_match; |
8763 | 56.2k | mb->ignore_skip_arg = mb->skip_arg_count; |
8764 | 56.2k | break; |
8765 | | |
8766 | | /* SKIP passes back the next starting point explicitly, but if it is no |
8767 | | greater than the match we have just done, treat it as NOMATCH. */ |
8768 | | |
8769 | 6.72k | case MATCH_SKIP: |
8770 | 6.72k | if (mb->verb_skip_ptr > start_match) |
8771 | 1.71k | { |
8772 | 1.71k | new_start_match = mb->verb_skip_ptr; |
8773 | 1.71k | break; |
8774 | 1.71k | } |
8775 | | |
8776 | 5.00k | PCRE2_FALLTHROUGH /* Fall through */ |
8777 | 5.00k | |
8778 | 5.00k | /* NOMATCH and PRUNE advance by one character. THEN at this level acts |
8779 | 5.00k | exactly like PRUNE. Unset ignore SKIP-with-argument. */ |
8780 | 5.00k | |
8781 | 2.29M | case MATCH_NOMATCH: |
8782 | 2.29M | case MATCH_PRUNE: |
8783 | 2.30M | case MATCH_THEN: |
8784 | 2.30M | mb->ignore_skip_arg = 0; |
8785 | 2.30M | new_start_match = start_match + 1; |
8786 | 2.30M | #ifdef SUPPORT_UNICODE |
8787 | 2.30M | if (utf) |
8788 | 715k | ACROSSCHAR(new_start_match < end_subject, new_start_match, new_start_match++); |
8789 | 2.30M | #endif |
8790 | 2.30M | break; |
8791 | | |
8792 | | /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */ |
8793 | | |
8794 | 389 | case MATCH_COMMIT: |
8795 | 389 | rc = MATCH_NOMATCH; |
8796 | 389 | goto ENDLOOP; |
8797 | | |
8798 | | /* Any other return is either a match, or some kind of error. */ |
8799 | | |
8800 | 106k | default: |
8801 | 106k | goto ENDLOOP; |
8802 | 2.47M | } |
8803 | | |
8804 | | /* Control reaches here for the various types of "no match at this point" |
8805 | | result. Reset the code to MATCH_NOMATCH for subsequent checking. */ |
8806 | | |
8807 | 2.36M | rc = MATCH_NOMATCH; |
8808 | | |
8809 | | /* If PCRE2_FIRSTLINE is set, the match must happen before or at the first |
8810 | | newline in the subject (though it may continue over the newline). Therefore, |
8811 | | if we have just failed to match, starting at a newline, do not continue. */ |
8812 | | |
8813 | 2.36M | if (firstline && IS_NEWLINE(start_match)) |
8814 | 506 | break; |
8815 | | |
8816 | | /* Advance to new matching position */ |
8817 | | |
8818 | 2.36M | start_match = new_start_match; |
8819 | | |
8820 | | /* Break the loop if the pattern is anchored or if we have passed the end of |
8821 | | the subject. */ |
8822 | | |
8823 | 2.36M | if (anchored || start_match > end_subject) |
8824 | 73.7k | break; |
8825 | | |
8826 | | /* If we have just passed a CR and we are now at a LF, and the pattern does |
8827 | | not contain any explicit matches for \r or \n, and the newline option is CRLF |
8828 | | or ANY or ANYCRLF, advance the match position by one more code unit. In |
8829 | | normal matching start_match will aways be greater than the first position at |
8830 | | this stage, but a failed *SKIP can cause a return at the same point, which is |
8831 | | why the first test exists. */ |
8832 | | |
8833 | 2.29M | if (start_match > subject + start_offset && start_match[-1] == CHAR_CR && |
8834 | 4.35k | start_match < end_subject && *start_match == CHAR_NL && |
8835 | 1.36k | (re->flags & PCRE2_HASCRORLF) == 0 && |
8836 | 579 | (mb->nltype == NLTYPE_ANY || mb->nltype == NLTYPE_ANYCRLF || mb->nllen == 2)) |
8837 | 0 | start_match++; |
8838 | | |
8839 | 2.29M | mb->mark = NULL; // Reset for start of next match attempt |
8840 | 2.29M | } // End of for (;;) "bumpalong" loop |
8841 | | |
8842 | | /* ==========================================================================*/ |
8843 | | |
8844 | | /* When we reach here, one of the following stopping conditions is true: |
8845 | | |
8846 | | (1) The match succeeded, either completely, or partially; |
8847 | | |
8848 | | (2) The pattern is anchored or the match was failed after (*COMMIT); |
8849 | | |
8850 | | (3) We are past the end of the subject or the bumpalong limit; |
8851 | | |
8852 | | (4) PCRE2_FIRSTLINE is set and we have failed to match at a newline, because |
8853 | | this option requests that a match occur at or before the first newline in |
8854 | | the subject. |
8855 | | |
8856 | | (5) Some kind of error occurred. |
8857 | | |
8858 | | */ |
8859 | | |
8860 | 256k | ENDLOOP: |
8861 | | |
8862 | | /* If end_subject != true_end_subject, it means we are handling invalid UTF, |
8863 | | and have just processed a non-terminal fragment. If this resulted in no match |
8864 | | or a partial match we must carry on to the next fragment (a partial match is |
8865 | | returned to the caller only at the very end of the subject). A loop is used to |
8866 | | avoid trying to match against empty fragments; if the pattern can match an |
8867 | | empty string it would have done so already. */ |
8868 | | |
8869 | 256k | #ifdef SUPPORT_UNICODE |
8870 | 256k | if (utf && end_subject != true_end_subject && (rc == MATCH_NOMATCH || rc == PCRE2_ERROR_PARTIAL)) |
8871 | 0 | { |
8872 | 0 | for (;;) |
8873 | 0 | { |
8874 | | /* Advance past the first bad code unit, and then skip invalid character |
8875 | | starting code units in 8-bit and 16-bit modes. */ |
8876 | |
|
8877 | 0 | start_match = end_subject + 1; |
8878 | |
|
8879 | 0 | #if PCRE2_CODE_UNIT_WIDTH != 32 |
8880 | 0 | while (start_match < true_end_subject && NOT_FIRSTCU(*start_match)) |
8881 | 0 | start_match++; |
8882 | 0 | #endif |
8883 | | |
8884 | | /* If we have hit the end of the subject, there isn't another non-empty |
8885 | | fragment, so give up. */ |
8886 | |
|
8887 | 0 | if (start_match >= true_end_subject) |
8888 | 0 | { |
8889 | 0 | rc = MATCH_NOMATCH; // In case it was partial |
8890 | 0 | match_partial = NULL; |
8891 | 0 | break; |
8892 | 0 | } |
8893 | | |
8894 | | /* Check the rest of the subject */ |
8895 | | |
8896 | 0 | mb->check_subject = start_match; |
8897 | 0 | rc = PRIV(valid_utf)(start_match, length - (start_match - subject), &(match_data->startchar)); |
8898 | | |
8899 | | /* The rest of the subject is valid UTF. */ |
8900 | |
|
8901 | 0 | if (rc == 0) |
8902 | 0 | { |
8903 | 0 | mb->end_subject = end_subject = true_end_subject; |
8904 | 0 | fragment_options = PCRE2_NOTBOL; |
8905 | 0 | goto FRAGMENT_RESTART; |
8906 | 0 | } |
8907 | | |
8908 | | /* A subsequent UTF error has been found; if the next fragment is |
8909 | | non-empty, set up to process it. Otherwise, let the loop advance. */ |
8910 | | |
8911 | 0 | else if (rc < 0) |
8912 | 0 | { |
8913 | 0 | mb->end_subject = end_subject = start_match + match_data->startchar; |
8914 | 0 | if (end_subject > start_match) |
8915 | 0 | { |
8916 | 0 | fragment_options = PCRE2_NOTBOL | PCRE2_NOTEOL; |
8917 | 0 | goto FRAGMENT_RESTART; |
8918 | 0 | } |
8919 | 0 | } |
8920 | 0 | } |
8921 | 0 | } |
8922 | 256k | #endif /* SUPPORT_UNICODE */ |
8923 | | |
8924 | | /* Fill in fields that are always returned in the match data. */ |
8925 | | |
8926 | 256k | match_data->code = re; |
8927 | 256k | match_data->mark = mb->mark; |
8928 | 256k | match_data->matchedby = PCRE2_MATCHEDBY_INTERPRETER; |
8929 | 256k | match_data->options = original_options; |
8930 | | |
8931 | | /* Handle a fully successful match. Set the return code to the number of |
8932 | | captured strings, or 0 if there were too many to fit into the ovector, and then |
8933 | | set the remaining returned values before returning. Make a copy of the subject |
8934 | | string if requested. */ |
8935 | | |
8936 | 256k | if (rc == MATCH_MATCH) |
8937 | 72.2k | { |
8938 | 72.2k | match_data->rc = ((int)mb->end_offset_top >= 2 * match_data->oveccount) |
8939 | 72.2k | ? 0 |
8940 | 72.2k | : (int)mb->end_offset_top / 2 + 1; |
8941 | 72.2k | match_data->subject_length = length; |
8942 | 72.2k | match_data->start_offset = start_offset; |
8943 | 72.2k | match_data->startchar = start_match - subject; |
8944 | 72.2k | match_data->leftchar = mb->start_used_ptr - subject; |
8945 | 72.2k | match_data->rightchar = |
8946 | 72.2k | ((mb->last_used_ptr > mb->end_match_ptr) ? mb->last_used_ptr : mb->end_match_ptr) - subject; |
8947 | 72.2k | if ((options & PCRE2_COPY_MATCHED_SUBJECT) != 0) |
8948 | 0 | { |
8949 | 0 | match_data->subject = |
8950 | 0 | match_data->memctl.malloc(CU2BYTES(length + 1), match_data->memctl.memory_data); |
8951 | 0 | if (match_data->subject == NULL) |
8952 | 0 | { |
8953 | 0 | match_data->subject_length = 0; |
8954 | 0 | return match_data->rc = PCRE2_ERROR_NOMEMORY; |
8955 | 0 | } |
8956 | | |
8957 | | /* PCRE2 does not require the copied subject to be zero-terminated. However, |
8958 | | it is exposed to clients through pcre2_get_subject, who might appreciate this. */ |
8959 | 0 | memcpy((void *)match_data->subject, subject, CU2BYTES(length)); |
8960 | 0 | ((PCRE2_UCHAR *)match_data->subject)[length] = 0; |
8961 | |
|
8962 | 0 | match_data->flags |= PCRE2_MD_COPIED_SUBJECT; |
8963 | 0 | } |
8964 | 72.2k | else |
8965 | 72.2k | { |
8966 | 72.2k | match_data->subject = original_subject; |
8967 | 72.2k | } |
8968 | | |
8969 | 72.2k | return match_data->rc; |
8970 | 72.2k | } |
8971 | | |
8972 | | /* Control gets here if there has been a partial match, an error, or if the |
8973 | | overall match attempt has failed at all permitted starting positions. Any mark |
8974 | | data is in the nomatch_mark field. */ |
8975 | | |
8976 | 184k | match_data->mark = mb->nomatch_mark; |
8977 | | |
8978 | | /* For anything other than nomatch or partial match, just return the code. */ |
8979 | | |
8980 | 184k | if (rc != MATCH_NOMATCH && rc != PCRE2_ERROR_PARTIAL) |
8981 | 26.3k | match_data->rc = rc; |
8982 | | |
8983 | | /* Handle a partial match. If a "soft" partial match was requested, searching |
8984 | | for a complete match will have continued, and the value of rc at this point |
8985 | | will be MATCH_NOMATCH. For a "hard" partial match, it will already be |
8986 | | PCRE2_ERROR_PARTIAL. */ |
8987 | | |
8988 | 158k | else if (match_partial != NULL) |
8989 | 21.1k | { |
8990 | 21.1k | match_data->subject = original_subject; |
8991 | 21.1k | match_data->subject_length = length; |
8992 | 21.1k | match_data->start_offset = start_offset; |
8993 | 21.1k | match_data->ovector[0] = match_partial - subject; |
8994 | 21.1k | match_data->ovector[1] = end_subject - subject; |
8995 | 21.1k | match_data->startchar = match_partial - subject; |
8996 | 21.1k | match_data->leftchar = start_partial - subject; |
8997 | 21.1k | match_data->rightchar = end_subject - subject; |
8998 | 21.1k | match_data->rc = PCRE2_ERROR_PARTIAL; |
8999 | 21.1k | } |
9000 | | |
9001 | | /* Else this is the classic nomatch case. */ |
9002 | | |
9003 | 137k | else |
9004 | 137k | { |
9005 | 137k | match_data->subject = original_subject; |
9006 | 137k | match_data->subject_length = length; |
9007 | 137k | match_data->start_offset = start_offset; |
9008 | 137k | match_data->rc = PCRE2_ERROR_NOMATCH; |
9009 | 137k | } |
9010 | | |
9011 | 184k | return match_data->rc; |
9012 | 256k | } |
9013 | | |
9014 | | /* These #undefs are here to enable unity builds with CMake. */ |
9015 | | |
9016 | | #undef NLBLOCK /* Block containing newline information */ |
9017 | | #undef PSSTART /* Field containing processed string start */ |
9018 | | #undef PSEND /* Field containing processed string end */ |
9019 | | |
9020 | | /* End of pcre2_match.c */ |