Coverage Report

Created: 2026-09-03 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
866M
#define NLBLOCK mb              /* Block containing newline information */
64
240k
#define PSSTART start_subject   /* Field containing processed string start */
65
216M
#define PSEND   end_subject     /* Field containing processed string end */
66
67
5.62M
#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
169k
  (PCRE2_ANCHORED|PCRE2_ENDANCHORED|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY| \
73
169k
   PCRE2_NOTEMPTY_ATSTART|PCRE2_NO_UTF_CHECK|PCRE2_PARTIAL_HARD| \
74
169k
   PCRE2_PARTIAL_SOFT|PCRE2_NO_JIT|PCRE2_COPY_MATCHED_SUBJECT| \
75
169k
   PCRE2_DISABLE_RECURSELOOP_CHECK)
76
77
#define PUBLIC_JIT_MATCH_OPTIONS \
78
158k
   (PCRE2_NO_UTF_CHECK|PCRE2_NOTBOL|PCRE2_NOTEOL|PCRE2_NOTEMPTY|\
79
158k
    PCRE2_NOTEMPTY_ATSTART|PCRE2_PARTIAL_SOFT|PCRE2_PARTIAL_HARD|\
80
158k
    PCRE2_COPY_MATCHED_SUBJECT)
81
82
/* Non-error returns from and within the match() function. Error returns are
83
externally defined PCRE2_ERROR_xxx codes, which are all negative. */
84
85
258k
#define MATCH_MATCH        1
86
69.8M
#define MATCH_NOMATCH      0
87
88
/* Special internal returns used in the match() function. Make them
89
sufficiently negative to avoid the external error codes. */
90
91
951k
#define MATCH_ACCEPT       (-999)
92
184k
#define MATCH_KETRPOS      (-998)
93
/* The next 5 must be kept together and in sequence so that a test that checks
94
for any one of them can use a range. */
95
961k
#define MATCH_COMMIT       (-997)
96
4.56M
#define MATCH_PRUNE        (-996)
97
72.9k
#define MATCH_SKIP         (-995)
98
681k
#define MATCH_SKIP_ARG     (-994)
99
39.0M
#define MATCH_THEN         (-993)
100
477k
#define MATCH_BACKTRACK_MAX MATCH_THEN
101
479k
#define MATCH_BACKTRACK_MIN MATCH_COMMIT
102
103
/* Group frame type values. Zero means the frame is not a group frame. The
104
lower 16 bits are used for data (e.g. the capture number). Group frames are
105
used for most groups so that information about the start is easily available at
106
the end without having to scan back through intermediate frames (backtrack
107
points). */
108
109
1.89M
#define GF_CAPTURE     0x00010000u
110
2.20M
#define GF_NOCAPTURE   0x00020000u
111
4.04M
#define GF_CONDASSERT  0x00030000u
112
8.12M
#define GF_RECURSE     0x00040000u
113
114
/* Masks for the identity and data parts of the group frame type. */
115
116
7.41M
#define GF_IDMASK(a)   ((a) & 0xffff0000u)
117
656k
#define GF_DATAMASK(a) ((a) & 0x0000ffffu)
118
119
/* Repetition types */
120
121
enum { REPTYPE_MIN, REPTYPE_MAX, REPTYPE_POS };
122
123
/* Min and max values for the common repeats; a maximum of UINT32_MAX =>
124
infinity. */
125
126
static const uint32_t rep_min[] = {
127
  0, 0,       /* * and *? */
128
  1, 1,       /* + and +? */
129
  0, 0,       /* ? and ?? */
130
  0, 0,       /* dummy placefillers for OP_CR[MIN]RANGE */
131
  0, 1, 0 };  /* OP_CRPOS{STAR, PLUS, QUERY} */
132
133
static const uint32_t rep_max[] = {
134
  UINT32_MAX, UINT32_MAX,      /* * and *? */
135
  UINT32_MAX, UINT32_MAX,      /* + and +? */
136
  1, 1,                        /* ? and ?? */
137
  0, 0,                        /* dummy placefillers for OP_CR[MIN]RANGE */
138
  UINT32_MAX, UINT32_MAX, 1 }; /* OP_CRPOS{STAR, PLUS, QUERY} */
139
140
/* Repetition types - must include OP_CRPOSRANGE (not needed above) */
141
142
static const uint32_t rep_typ[] = {
143
  REPTYPE_MAX, REPTYPE_MIN,    /* * and *? */
144
  REPTYPE_MAX, REPTYPE_MIN,    /* + and +? */
145
  REPTYPE_MAX, REPTYPE_MIN,    /* ? and ?? */
146
  REPTYPE_MAX, REPTYPE_MIN,    /* OP_CRRANGE and OP_CRMINRANGE */
147
  REPTYPE_POS, REPTYPE_POS,    /* OP_CRPOSSTAR, OP_CRPOSPLUS */
148
  REPTYPE_POS, REPTYPE_POS };  /* OP_CRPOSQUERY, OP_CRPOSRANGE */
149
150
/* Numbers for RMATCH calls at backtracking points. When these lists are
151
changed, the code at RETURN_SWITCH below must be updated in sync.  */
152
153
enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
154
       RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
155
       RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
156
       RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39 };
157
158
#ifdef SUPPORT_WIDE_CHARS
159
enum { RM100=100, RM101, RM102, RM103 };
160
#endif
161
162
#ifdef SUPPORT_UNICODE
163
enum { RM200=200, RM201, RM202, RM203, RM204, RM205, RM206, RM207,
164
       RM208,     RM209, RM210, RM211, RM212, RM213, RM214, RM215,
165
       RM216,     RM217, RM218, RM219, RM220, RM221, RM222, RM223,
166
       RM224 };
167
#endif
168
169
/* Define short names for general fields in the current backtrack frame, which
170
is always pointed to by the F variable. Occasional references to fields in
171
other frames are written out explicitly. There are also some fields in the
172
current frame that are used for short-term, localised backtracking memory.
173
These are members of the fields union and #defined with Lxxx names at the
174
point of use and undefined afterwards. */
175
176
124M
#define Fback_frame        F->back_frame
177
8.63M
#define Fcapture_last      F->capture_last
178
18.2M
#define Fcurrent_recurse   F->current_recurse
179
553M
#define Fecode             F->ecode
180
754M
#define Feptr              F->eptr
181
65.0M
#define Fgroup_frame_type  F->group_frame_type
182
18.7M
#define Flast_group_offset F->last_group_offset
183
5.30M
#define Fmark              F->mark
184
205M
#define Frdepth            F->rdepth
185
9.05M
#define Fstart_match       F->start_match
186
15.2M
#define Foffset_top        F->offset_top
187
297M
#define Fop                F->op
188
9.87M
#define Fovector           F->ovector
189
119M
#define Freturn_id         F->return_id
190
191
192
#ifdef DEBUG_FRAMES_DISPLAY
193
/*************************************************
194
*      Display current frames and contents       *
195
*************************************************/
196
197
/* This debugging function displays the current set of frames and their
198
contents. It is not called automatically from anywhere, the intention being
199
that calls can be inserted where necessary when debugging frame-related
200
problems.
201
202
Arguments:
203
  f           the file to write to
204
  F           the current top frame
205
  P           a previous frame of interest
206
  frame_size  the frame size
207
  mb          points to the match block
208
  match_data  points to the match data block
209
  s           identification text
210
211
Returns:    nothing
212
*/
213
214
static void
215
display_frames(FILE *f, heapframe *F, heapframe *P, PCRE2_SIZE frame_size,
216
  match_block *mb, pcre2_match_data *match_data, const char *s, ...)
217
{
218
uint32_t i;
219
heapframe *Q;
220
va_list ap;
221
va_start(ap, s);
222
223
fprintf(f, "FRAMES ");
224
vfprintf(f, s, ap);
225
va_end(ap);
226
227
if (P != NULL) fprintf(f, " P=%lu",
228
  ((char *)P - (char *)(match_data->heapframes))/frame_size);
229
fprintf(f, "\n");
230
231
for (i = 0, Q = match_data->heapframes;
232
     Q <= F;
233
     i++, Q = (heapframe *)((char *)Q + frame_size))
234
  {
235
  fprintf(f, "Frame %d type=%x subj=%lu code=%d back=%lu id=%d",
236
    i, Q->group_frame_type, Q->eptr - mb->start_subject, *(Q->ecode),
237
    Q->back_frame, Q->return_id);
238
239
  if (Q->last_group_offset == PCRE2_UNSET)
240
    fprintf(f, " lgoffset=unset\n");
241
  else
242
    fprintf(f, " lgoffset=%lu\n",  Q->last_group_offset/frame_size);
243
  }
244
}
245
246
#endif
247
248
249
250
/*************************************************
251
*                Process a callout               *
252
*************************************************/
253
254
/* This function is called for all callouts, whether "standalone" or at the
255
start of a conditional group. Feptr will be pointing to either OP_CALLOUT or
256
OP_CALLOUT_STR. A callout block is allocated in pcre2_match() and initialized
257
with fixed values.
258
259
Arguments:
260
  F          points to the current backtracking frame
261
  mb         points to the match block
262
  lengthptr  where to return the length of the callout item
263
264
Returns:     the return from the callout
265
             or 0 if no callout function exists
266
*/
267
268
static int
269
do_callout(heapframe *F, match_block *mb, PCRE2_SIZE *lengthptr)
270
1.03M
{
271
1.03M
int rc;
272
1.03M
PCRE2_SIZE save0, save1;
273
1.03M
PCRE2_SIZE *callout_ovector;
274
1.03M
pcre2_callout_block *cb;
275
276
1.03M
*lengthptr = (*Fecode == OP_CALLOUT)?
277
1.02M
  PRIV(OP_lengths)[OP_CALLOUT] : GET(Fecode, 1 + 2*LINK_SIZE);
278
279
1.03M
if (mb->callout == NULL) return 0;   /* No callout function provided */
280
281
/* The original matching code (pre 10.30) worked directly with the ovector
282
passed by the user, and this was passed to callouts. Now that the working
283
ovector is in the backtracking frame, it no longer needs to reserve space for
284
the overall match offsets (which would waste space in the frame). For backward
285
compatibility, however, we pass capture_top and offset_vector to the callout as
286
if for the extended ovector, and we ensure that the first two slots are unset
287
by preserving and restoring their current contents. Picky compilers complain if
288
references such as Fovector[-2] are use directly, so we set up a separate
289
pointer. */
290
291
1.03M
callout_ovector = (PCRE2_SIZE *)(Fovector) - 2;
292
293
/* The cb->version, cb->subject, cb->subject_length, and cb->start_match fields
294
are set externally. The first 3 never change; the last is updated for each
295
bumpalong. */
296
297
1.03M
cb = mb->cb;
298
1.03M
cb->capture_top      = (uint32_t)Foffset_top/2 + 1;
299
1.03M
cb->capture_last     = Fcapture_last;
300
1.03M
cb->offset_vector    = callout_ovector;
301
1.03M
cb->mark             = mb->nomatch_mark;
302
1.03M
cb->current_position = (PCRE2_SIZE)(Feptr - mb->start_subject);
303
1.03M
cb->pattern_position = GET(Fecode, 1);
304
1.03M
cb->next_item_length = GET(Fecode, 1 + LINK_SIZE);
305
306
1.03M
if (*Fecode == OP_CALLOUT)  /* Numerical callout */
307
1.02M
  {
308
1.02M
  cb->callout_number = Fecode[1 + 2*LINK_SIZE];
309
1.02M
  cb->callout_string_offset = 0;
310
1.02M
  cb->callout_string = NULL;
311
1.02M
  cb->callout_string_length = 0;
312
1.02M
  }
313
9.06k
else  /* String callout */
314
9.06k
  {
315
9.06k
  cb->callout_number = 0;
316
9.06k
  cb->callout_string_offset = GET(Fecode, 1 + 3*LINK_SIZE);
317
9.06k
  cb->callout_string = Fecode + (1 + 4*LINK_SIZE) + 1;
318
9.06k
  cb->callout_string_length =
319
9.06k
    *lengthptr - (1 + 4*LINK_SIZE) - 2;
320
9.06k
  }
321
322
1.03M
save0 = callout_ovector[0];
323
1.03M
save1 = callout_ovector[1];
324
1.03M
callout_ovector[0] = callout_ovector[1] = PCRE2_UNSET;
325
1.03M
rc = mb->callout(cb, mb->callout_data);
326
1.03M
callout_ovector[0] = save0;
327
1.03M
callout_ovector[1] = save1;
328
1.03M
cb->callout_flags = 0;
329
1.03M
return rc;
330
1.03M
}
331
332
333
334
/*************************************************
335
*          Match a back-reference                *
336
*************************************************/
337
338
/* This function is called only when it is known that the offset lies within
339
the offsets that have so far been used in the match. Note that in caseless
340
UTF-8 mode, the number of subject bytes matched may be different to the number
341
of reference bytes. (In theory this could also happen in UTF-16 mode, but it
342
seems unlikely.)
343
344
Arguments:
345
  offset      index into the offset vector
346
  caseless    TRUE if caseless
347
  caseopts    bitmask of REFI_FLAG_XYZ values
348
  F           the current backtracking frame pointer
349
  mb          points to match block
350
  lengthptr   pointer for returning the length matched
351
352
Returns:      = 0 sucessful match; number of code units matched is set
353
              < 0 no match
354
              > 0 partial match
355
*/
356
357
static int
358
match_ref(PCRE2_SIZE offset, BOOL caseless, int caseopts, heapframe *F,
359
  match_block *mb, PCRE2_SIZE *lengthptr)
360
1.10M
{
361
1.10M
PCRE2_SPTR p;
362
1.10M
PCRE2_SIZE length;
363
1.10M
PCRE2_SPTR eptr;
364
1.10M
PCRE2_SPTR eptr_start;
365
366
#ifndef SUPPORT_UNICODE
367
(void)caseopts; /* Avoid compiler warning. */
368
#endif
369
370
/* Deal with an unset group. The default is no match, but there is an option to
371
match an empty string. */
372
373
1.10M
if (offset >= Foffset_top || Fovector[offset] == PCRE2_UNSET)
374
437k
  {
375
437k
  if ((mb->poptions & PCRE2_MATCH_UNSET_BACKREF) != 0)
376
17.4k
    {
377
17.4k
    *lengthptr = 0;
378
17.4k
    return 0;      /* Match */
379
17.4k
    }
380
420k
  else return -1;  /* No match */
381
437k
  }
382
383
/* Separate the caseless and UTF cases for speed. */
384
385
669k
eptr = eptr_start = Feptr;
386
669k
p = mb->start_subject + Fovector[offset];
387
669k
length = Fovector[offset+1] - Fovector[offset];
388
669k
PCRE2_ASSERT(eptr <= mb->end_subject);
389
390
669k
if (caseless)
391
263k
  {
392
263k
#if defined SUPPORT_UNICODE
393
263k
  BOOL utf = (mb->poptions & PCRE2_UTF) != 0;
394
263k
  BOOL caseless_restrict = (caseopts & REFI_FLAG_CASELESS_RESTRICT) != 0;
395
263k
  BOOL turkish_casing = !caseless_restrict && (caseopts & REFI_FLAG_TURKISH_CASING) != 0;
396
397
263k
  if (utf || (mb->poptions & PCRE2_UCP) != 0)
398
235k
    {
399
235k
    PCRE2_SPTR endptr = p + length;
400
401
    /* Match characters up to the end of the reference. NOTE: the number of
402
    code units matched may differ, because in UTF-8 there are some characters
403
    whose upper and lower case codes have different numbers of bytes. For
404
    example, U+023A (2 bytes in UTF-8) is the upper case version of U+2C65 (3
405
    bytes in UTF-8); a sequence of 3 of the former uses 6 bytes, as does a
406
    sequence of two of the latter. It is important, therefore, to check the
407
    length along the reference, not along the subject (earlier code did this
408
    wrong). UCP uses Unicode properties but without UTF encoding. */
409
410
387k
    while (p < endptr)
411
257k
      {
412
257k
      uint32_t c, d;
413
257k
      const ucd_record *ur;
414
257k
      if (eptr >= mb->end_subject) return 1;   /* Partial match */
415
416
250k
      if (utf)
417
220k
        {
418
220k
        GETCHARINC(c, eptr);
419
220k
        GETCHARINC(d, p);
420
220k
        }
421
29.9k
      else
422
29.9k
        {
423
29.9k
        c = *eptr++;
424
29.9k
        d = *p++;
425
29.9k
        }
426
427
250k
      if (turkish_casing && UCD_ANY_I(d))
428
0
        {
429
0
        c = UCD_FOLD_I_TURKISH(c);
430
0
        d = UCD_FOLD_I_TURKISH(d);
431
0
        if (c != d) return -1;  /* No match */
432
0
        }
433
250k
      else if (c != d && c != (uint32_t)((int)d + (ur = GET_UCD(d))->other_case))
434
103k
        {
435
103k
        const uint32_t *pp = PRIV(ucd_caseless_sets) + ur->caseset;
436
437
        /* When PCRE2_EXTRA_CASELESS_RESTRICT is set, ignore any caseless sets
438
        that start with an ASCII character. */
439
103k
        if (caseless_restrict && *pp < 128) return -1;  /* No match */
440
441
103k
        for (;;)
442
125k
          {
443
125k
          if (c < *pp) return -1;  /* No match */
444
26.9k
          if (c == *pp++) break;
445
26.9k
          }
446
103k
        }
447
250k
      }
448
235k
    }
449
28.3k
  else
450
28.3k
#endif
451
452
  /* Not in UTF or UCP mode */
453
28.3k
    {
454
35.5k
    for (; length > 0; length--)
455
33.5k
      {
456
33.5k
      uint32_t cc, cp;
457
33.5k
      if (eptr >= mb->end_subject) return 1;   /* Partial match */
458
32.3k
      cc = *eptr;
459
32.3k
      cp = *p;
460
32.3k
      if (TABLE_GET(cp, mb->lcc, cp) != TABLE_GET(cc, mb->lcc, cc))
461
25.1k
        return -1;  /* No match */
462
7.19k
      p++;
463
7.19k
      eptr++;
464
7.19k
      }
465
28.3k
    }
466
263k
  }
467
468
/* In the caseful case, we can just compare the code units, whether or not we
469
are in UTF and/or UCP mode. When partial matching, we have to do this unit by
470
unit. */
471
472
405k
else
473
405k
  {
474
405k
  if (mb->partial != 0)
475
32.0k
    {
476
42.1k
    for (; length > 0; length--)
477
31.6k
      {
478
31.6k
      if (eptr >= mb->end_subject) return 1;   /* Partial match */
479
30.0k
      if (*p++ != *eptr++) return -1;  /* No match */
480
30.0k
      }
481
32.0k
    }
482
483
  /* Not partial matching */
484
485
373k
  else
486
373k
    {
487
373k
    if ((PCRE2_SIZE)(mb->end_subject - eptr) < length ||
488
261k
        memcmp(p, eptr, CU2BYTES(length)) != 0) return -1;  /* No match */
489
138k
    eptr += length;
490
138k
    }
491
405k
  }
492
493
280k
*lengthptr = eptr - eptr_start;
494
280k
return 0;  /* Match */
495
669k
}
496
497
498
499
/*************************************************
500
*     Restore offsets after a recurse            *
501
*************************************************/
502
503
/* This function restores the ovector values when
504
a recursive block reaches its end, and the triggering
505
recurse has and argument list.
506
507
Arguments:
508
  F           the current backtracking frame pointer
509
  P           the previous backtracking frame pointer
510
*/
511
512
static void
513
recurse_update_offsets(heapframe *F, heapframe *P)
514
16.7k
{
515
16.7k
PCRE2_SIZE *dst = F->ovector;
516
16.7k
PCRE2_SIZE *src = P->ovector;
517
/* The first bracket has offset 2, because
518
offset 0 is reserved for the full match. */
519
16.7k
PCRE2_SIZE offset = 2;
520
16.7k
PCRE2_SIZE offset_top = Foffset_top + 2;
521
16.7k
PCRE2_SIZE diff;
522
16.7k
PCRE2_SPTR ecode = Fecode;
523
524
16.7k
do
525
21.1k
  {
526
21.1k
  diff = (GET2(ecode, 1) << 1) - offset;
527
21.1k
  ecode += 1 + IMM2_SIZE;
528
529
21.1k
  if (offset + diff >= offset_top)
530
11.4k
    {
531
    /* Some OP_CREF opcodes are not
532
    processed, they must be skipped. */
533
26.1k
    while (*ecode == OP_CREF) ecode += 1 + IMM2_SIZE;
534
11.4k
    break;
535
11.4k
    }
536
537
9.67k
  if (diff == 2)
538
4.69k
    {
539
4.69k
    dst[0] = src[0];
540
4.69k
    dst[1] = src[1];
541
4.69k
    }
542
4.98k
  else if (diff >= 4)
543
3.37k
    memcpy(dst, src, diff * sizeof(PCRE2_SIZE));
544
545
  /* Skip the unmodified entry. */
546
9.67k
  diff += 2;
547
9.67k
  offset += diff;
548
9.67k
  dst += diff;
549
9.67k
  src += diff;
550
9.67k
  }
551
16.7k
while (*ecode == OP_CREF);
552
553
16.7k
diff = offset_top - offset;
554
16.7k
if (diff == 2)
555
1.12k
  {
556
1.12k
  dst[0] = src[0];
557
1.12k
  dst[1] = src[1];
558
1.12k
  }
559
15.6k
else if (diff >= 4)
560
1.33k
  memcpy(dst, src, diff * sizeof(PCRE2_SIZE));
561
562
16.7k
Fecode = ecode;
563
16.7k
Foffset_top = (offset <= P->offset_top) ? P->offset_top : (offset - 2);
564
16.7k
}
565
566
567
568
/******************************************************************************
569
*******************************************************************************
570
                   "Recursion" in the match() function
571
572
The original match() function was highly recursive, but this proved to be the
573
source of a number of problems over the years, mostly because of the relatively
574
small system stacks that are commonly found. As new features were added to
575
patterns, various kludges were invented to reduce the amount of stack used,
576
making the code hard to understand in places.
577
578
A version did exist that used individual frames on the heap instead of calling
579
match() recursively, but this ran substantially slower. The current version is
580
a refactoring that uses a vector of frames to remember backtracking points.
581
This runs no slower, and possibly even a bit faster than the original recursive
582
implementation.
583
584
At first, an initial vector of size START_FRAMES_SIZE (enough for maybe 50
585
frames) was allocated on the system stack. If this was not big enough, the heap
586
was used for a larger vector. However, it turns out that there are environments
587
where taking as little as 20KiB from the system stack is an embarrassment.
588
After another refactoring, the heap is used exclusively, but a pointer the
589
frames vector and its size are cached in the match_data block, so that there is
590
no new memory allocation if the same match_data block is used for multiple
591
matches (unless the frames vector has to be extended).
592
*******************************************************************************
593
******************************************************************************/
594
595
596
597
598
/*************************************************
599
*       Macros for the match() function          *
600
*************************************************/
601
602
/* These macros pack up tests that are used for partial matching several times
603
in the code. The second one is used when we already know we are past the end of
604
the subject. We set the "hit end" flag if the pointer is at the end of the
605
subject and either (a) the pointer is past the earliest inspected character
606
(i.e. something has been matched, even if not part of the actual matched
607
string), or (b) the pattern contains a lookbehind. These are the conditions for
608
which adding more characters may allow the current match to continue.
609
610
For hard partial matching, we immediately return a partial match. Otherwise,
611
carrying on means that a complete match on the current subject will be sought.
612
A partial match is returned only if no complete match can be found. */
613
614
#define CHECK_PARTIAL() \
615
2.78M
  do { \
616
2.78M
     if (Feptr >= mb->end_subject) \
617
2.78M
       { \
618
141k
       SCHECK_PARTIAL(); \
619
141k
       } \
620
2.78M
     } \
621
2.78M
  while (0)
622
623
#define SCHECK_PARTIAL() \
624
2.84M
  do { \
625
2.84M
     if (mb->partial != 0 && \
626
2.84M
         (Feptr > mb->start_used_ptr || mb->allowemptypartial)) \
627
2.84M
       { \
628
806k
       mb->hitend = TRUE; \
629
806k
       if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; \
630
806k
       } \
631
2.84M
     } \
632
2.84M
  while (0)
633
634
635
/* These macros are used to implement backtracking. They simulate a recursive
636
call to the match() function by means of a local vector of frames which
637
remember the backtracking points. */
638
639
#define RMATCH(ra,rb) \
640
59.9M
  do { \
641
59.9M
     start_ecode = ra; \
642
59.9M
     Freturn_id = rb; \
643
59.9M
     goto MATCH_RECURSE; \
644
59.9M
     L_##rb:; \
645
59.3M
     } \
646
59.9M
  while (0)
647
648
#define RRETURN(ra) \
649
64.3M
  do { \
650
64.3M
     rrc = ra; \
651
64.3M
     goto RETURN_SWITCH; \
652
64.3M
     } \
653
64.3M
  while (0)
654
655
656
657
/*************************************************
658
*         Match from current position            *
659
*************************************************/
660
661
/* This function is called to run one match attempt at a single starting point
662
in the subject.
663
664
Performance note: It might be tempting to extract commonly used fields from the
665
mb structure (e.g. end_subject) into individual variables to improve
666
performance. Tests using gcc on a SPARC disproved this; in the first case, it
667
made performance worse.
668
669
Arguments:
670
   start_eptr   starting character in subject
671
   start_ecode  starting position in compiled code
672
   top_bracket  number of capturing parentheses in the pattern
673
   frame_size   size of each backtracking frame
674
   match_data   pointer to the match_data block
675
   mb           pointer to "static" variables block
676
677
Returns:        MATCH_MATCH if matched            )  these values are >= 0
678
                MATCH_NOMATCH if failed to match  )
679
                negative MATCH_xxx value for PRUNE, SKIP, etc
680
                negative PCRE2_ERROR_xxx value if aborted by an error condition
681
                (e.g. stopped by repeated call or depth limit)
682
*/
683
684
static int
685
match(PCRE2_SPTR start_eptr, PCRE2_SPTR start_ecode, uint16_t top_bracket,
686
  PCRE2_SIZE frame_size, pcre2_match_data *match_data, match_block *mb)
687
5.07M
{
688
/* Frame-handling variables */
689
690
5.07M
heapframe *F;           /* Current frame pointer */
691
5.07M
heapframe *N = NULL;    /* Temporary frame pointers */
692
5.07M
heapframe *P = NULL;
693
694
5.07M
heapframe *frames_top;  /* End of frames vector */
695
5.07M
heapframe *assert_accept_frame = NULL;  /* For passing back a frame with captures */
696
5.07M
PCRE2_SIZE frame_copy_size;   /* Amount to copy when creating a new frame */
697
698
/* Local variables that do not need to be preserved over calls to RMATCH(). */
699
700
5.07M
PCRE2_SPTR branch_end = NULL;
701
5.07M
PCRE2_SPTR branch_start;
702
5.07M
PCRE2_SPTR bracode;     /* Temp pointer to start of group */
703
5.07M
PCRE2_SIZE offset;      /* Used for group offsets */
704
5.07M
PCRE2_SIZE length;      /* Used for various length calculations */
705
706
5.07M
int rrc;                /* Return from functions & backtracking "recursions" */
707
5.07M
#ifdef SUPPORT_UNICODE
708
5.07M
int proptype;           /* Type of character property */
709
5.07M
#endif
710
711
5.07M
uint32_t i;             /* Used for local loops */
712
5.07M
uint32_t fc;            /* Character values */
713
5.07M
uint32_t number;        /* Used for group and other numbers */
714
5.07M
uint32_t reptype = 0;   /* Type of repetition (0 to avoid compiler warning) */
715
5.07M
uint32_t group_frame_type;  /* Specifies type for new group frames */
716
717
5.07M
BOOL condition;         /* Used in conditional groups */
718
5.07M
BOOL cur_is_word;       /* Used in "word" tests */
719
5.07M
BOOL prev_is_word;      /* Used in "word" tests */
720
721
/* UTF and UCP flags */
722
723
5.07M
#ifdef SUPPORT_UNICODE
724
5.07M
BOOL utf = (mb->poptions & PCRE2_UTF) != 0;
725
5.07M
BOOL ucp = (mb->poptions & PCRE2_UCP) != 0;
726
#else
727
BOOL utf = FALSE;  /* Required for convenience even when no Unicode support */
728
#endif
729
730
/* This is the length of the last part of a backtracking frame that must be
731
copied when a new frame is created. */
732
733
5.07M
frame_copy_size = frame_size - offsetof(heapframe, eptr);
734
735
/* Set up the first frame and the end of the frames vector. */
736
737
5.07M
F = match_data->heapframes;
738
5.07M
frames_top = (heapframe *)((char *)F + match_data->heapframes_size);
739
740
5.07M
Frdepth = 0;                        /* "Recursion" depth */
741
5.07M
Fcapture_last = 0;                  /* Number of most recent capture */
742
5.07M
Fcurrent_recurse = RECURSE_UNSET;   /* Not pattern recursing. */
743
5.07M
Fstart_match = Feptr = start_eptr;  /* Current data pointer and start match */
744
5.07M
Fmark = NULL;                       /* Most recent mark */
745
5.07M
Foffset_top = 0;                    /* End of captures within the frame */
746
5.07M
Flast_group_offset = PCRE2_UNSET;   /* Saved frame of most recent group */
747
5.07M
group_frame_type = 0;               /* Not a start of group frame */
748
5.07M
goto NEW_FRAME;                     /* Start processing with this frame */
749
750
/* Come back here when we want to create a new frame for remembering a
751
backtracking point. */
752
753
59.9M
MATCH_RECURSE:
754
755
/* Set up a new backtracking frame. If the vector is full, get a new one,
756
doubling the size, but constrained by the heap limit (which is in KiB). */
757
758
59.9M
N = (heapframe *)((char *)F + frame_size);
759
59.9M
if ((heapframe *)((char *)N + frame_size) >= frames_top)
760
278
  {
761
278
  heapframe *new;
762
278
  PCRE2_SIZE newsize;
763
278
  PCRE2_SIZE usedsize = (char *)N - (char *)(match_data->heapframes);
764
765
278
  if (match_data->heapframes_size >= PCRE2_SIZE_MAX / 2)
766
0
    {
767
0
    if (match_data->heapframes_size == PCRE2_SIZE_MAX - 1)
768
0
      return PCRE2_ERROR_NOMEMORY;
769
0
    newsize = PCRE2_SIZE_MAX - 1;
770
0
    }
771
278
  else
772
278
    newsize = match_data->heapframes_size * 2;
773
774
278
  if (newsize / 1024 >= mb->heap_limit)
775
0
    {
776
0
    PCRE2_SIZE old_size = match_data->heapframes_size / 1024;
777
0
    if (mb->heap_limit <= old_size)
778
0
      return PCRE2_ERROR_HEAPLIMIT;
779
0
    else
780
0
      {
781
0
      PCRE2_SIZE max_delta = 1024 * (mb->heap_limit - old_size);
782
0
      int over_bytes = match_data->heapframes_size % 1024;
783
0
      if (over_bytes) max_delta -= (1024 - over_bytes);
784
0
      newsize = match_data->heapframes_size + max_delta;
785
0
      }
786
0
    }
787
788
  /* With a heap limit set, the permitted additional size may not be enough for
789
  another frame, so do a final check. */
790
791
278
  if (newsize - usedsize < frame_size) return PCRE2_ERROR_HEAPLIMIT;
792
278
  new = match_data->memctl.malloc(newsize, match_data->memctl.memory_data);
793
278
  if (new == NULL) return PCRE2_ERROR_NOMEMORY;
794
278
  memcpy(new, match_data->heapframes, usedsize);
795
796
278
  N = (heapframe *)((char *)new + usedsize);
797
278
  F = (heapframe *)((char *)N - frame_size);
798
799
278
  match_data->memctl.free(match_data->heapframes, match_data->memctl.memory_data);
800
278
  match_data->heapframes = new;
801
278
  match_data->heapframes_size = newsize;
802
278
  frames_top = (heapframe *)((char *)new + newsize);
803
278
  }
804
805
#ifdef DEBUG_SHOW_RMATCH
806
fprintf(stderr, "++ RMATCH %d frame=%d", Freturn_id, Frdepth + 1);
807
if (group_frame_type != 0)
808
  {
809
  fprintf(stderr, " type=%x ", group_frame_type);
810
  switch (GF_IDMASK(group_frame_type))
811
    {
812
    case GF_CAPTURE:
813
    fprintf(stderr, "capture=%d", GF_DATAMASK(group_frame_type));
814
    break;
815
816
    case GF_NOCAPTURE:
817
    fprintf(stderr, "nocapture op=%d", Fop);
818
    break;
819
820
    case GF_CONDASSERT:
821
    fprintf(stderr, "condassert op=%d", Fop);
822
    break;
823
824
    case GF_RECURSE:
825
    fprintf(stderr, "recurse=%d", GF_DATAMASK(group_frame_type));
826
    break;
827
828
    default:
829
    fprintf(stderr, "*** unknown ***");
830
    break;
831
    }
832
  }
833
fprintf(stderr, "\n");
834
#endif
835
836
/* Copy those fields that must be copied into the new frame, increase the
837
"recursion" depth (i.e. the new frame's index) and then make the new frame
838
current. */
839
840
59.9M
memcpy((char *)N + offsetof(heapframe, eptr),
841
59.9M
       (char *)F + offsetof(heapframe, eptr),
842
59.9M
       frame_copy_size);
843
844
59.9M
N->rdepth = Frdepth + 1;
845
59.9M
F = N;
846
847
/* Carry on processing with a new frame. */
848
849
65.0M
NEW_FRAME:
850
65.0M
Fgroup_frame_type = group_frame_type;
851
65.0M
Fecode = start_ecode;      /* Starting code pointer */
852
65.0M
Fback_frame = frame_size;  /* Default is go back one frame */
853
854
/* If this is a special type of group frame, remember its offset for quick
855
access at the end of the group. If this is a recursion, set a new current
856
recursion value. */
857
858
65.0M
if (group_frame_type != 0)
859
7.41M
  {
860
7.41M
  Flast_group_offset = (char *)F - (char *)match_data->heapframes;
861
7.41M
  if (GF_IDMASK(group_frame_type) == GF_RECURSE)
862
656k
    Fcurrent_recurse = GF_DATAMASK(group_frame_type);
863
7.41M
  group_frame_type = 0;
864
7.41M
  }
865
866
867
/* ========================================================================= */
868
/* This is the main processing loop. First check that we haven't recorded too
869
many backtracks (search tree is too large), or that we haven't exceeded the
870
recursive depth limit (used too many backtracking frames). If not, process the
871
opcodes. */
872
873
65.0M
if (mb->match_call_count++ >= mb->match_limit) return PCRE2_ERROR_MATCHLIMIT;
874
65.0M
if (Frdepth >= mb->match_limit_depth) return PCRE2_ERROR_DEPTHLIMIT;
875
876
#ifdef DEBUG_SHOW_OPS
877
fprintf(stderr, "\n++ New frame: type=0x%x subject offset %ld\n",
878
  GF_IDMASK(Fgroup_frame_type), Feptr - mb->start_subject);
879
#endif
880
881
65.0M
for (;;)
882
130M
  {
883
#ifdef DEBUG_SHOW_OPS
884
fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode,
885
  OP_names[*Fecode]);
886
#endif
887
888
130M
  Fop = (uint8_t)(*Fecode);  /* Cast needed for 16-bit and 32-bit modes */
889
130M
  switch(Fop)
890
130M
    {
891
    /* ===================================================================== */
892
    /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes, to close
893
    any currently open capturing brackets. Unlike reaching the end of a group,
894
    where we know the starting frame is at the top of the chained frames, in
895
    this case we have to search back for the relevant frame in case other types
896
    of group that use chained frames have intervened. Multiple OP_CLOSEs always
897
    come innermost first, which matches the chain order. We can ignore this in
898
    a recursion, because captures are not passed out of recursions. */
899
900
16.1k
    case OP_CLOSE:
901
16.1k
    if (Fcurrent_recurse == RECURSE_UNSET)
902
15.6k
      {
903
15.6k
      number = GET2(Fecode, 1);
904
15.6k
      offset = Flast_group_offset;
905
15.6k
      for(;;)
906
146k
        {
907
        /* Corrupted heapframes?. Trigger an assert and return an error */
908
146k
        PCRE2_ASSERT(offset != PCRE2_UNSET);
909
146k
        if (offset == PCRE2_UNSET) return PCRE2_ERROR_INTERNAL;
910
911
146k
        N = (heapframe *)((char *)match_data->heapframes + offset);
912
146k
        P = (heapframe *)((char *)N - frame_size);
913
146k
        if (N->group_frame_type == (GF_CAPTURE | number)) break;
914
131k
        offset = P->last_group_offset;
915
131k
        }
916
15.6k
      offset = (number << 1) - 2;
917
15.6k
      Fcapture_last = number;
918
15.6k
      Fovector[offset] = P->eptr - mb->start_subject;
919
15.6k
      Fovector[offset+1] = Feptr - mb->start_subject;
920
15.6k
      if (offset >= Foffset_top) Foffset_top = offset + 2;
921
15.6k
      }
922
16.1k
    Fecode += PRIV(OP_lengths)[*Fecode];
923
16.1k
    break;
924
925
926
    /* ===================================================================== */
927
    /* Real or forced end of the pattern, assertion, or recursion. In an
928
    assertion ACCEPT, update the last used pointer and remember the current
929
    frame so that the captures and mark can be fished out of it. */
930
931
6.66k
    case OP_ASSERT_ACCEPT:
932
6.66k
    if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr;
933
6.66k
    assert_accept_frame = F;
934
6.66k
    RRETURN(MATCH_ACCEPT);
935
936
    /* For ACCEPT within a recursion, we have to find the most recent
937
    recursion. If not in a recursion, fall through to code that is common with
938
    OP_END. */
939
940
81.5k
    case OP_ACCEPT:
941
81.5k
    if (Fcurrent_recurse != RECURSE_UNSET)
942
417
      {
943
#ifdef DEBUG_SHOW_OPS
944
      fprintf(stderr, "++ Accept within recursion\n");
945
#endif
946
417
      offset = Flast_group_offset;
947
417
      for(;;)
948
817
        {
949
        /* Corrupted heapframes?. Trigger an assert and return an error */
950
817
        PCRE2_ASSERT(offset != PCRE2_UNSET);
951
817
        if (offset == PCRE2_UNSET) return PCRE2_ERROR_INTERNAL;
952
953
817
        N = (heapframe *)((char *)match_data->heapframes + offset);
954
817
        P = (heapframe *)((char *)N - frame_size);
955
817
        if (GF_IDMASK(N->group_frame_type) == GF_RECURSE) break;
956
400
        offset = P->last_group_offset;
957
400
        }
958
959
      /* N is now the frame of the recursion; the previous frame is at the
960
      OP_RECURSE position. Go back there, copying the current subject position
961
      and mark, and the start_match position (\K might have changed it), and
962
      then move on past the OP_RECURSE. */
963
964
417
      P->eptr = Feptr;
965
417
      P->mark = Fmark;
966
417
      P->start_match = Fstart_match;
967
417
      F = P;
968
417
      Fecode += 1 + LINK_SIZE;
969
417
      continue;
970
417
      }
971
81.1k
    PCRE2_FALLTHROUGH /* Fall through */
972
81.1k
973
81.1k
    /* OP_END itself can never be reached within a recursion because that is
974
81.1k
    picked up when the OP_KET that always precedes OP_END is reached. */
975
81.1k
976
1.77M
    case OP_END:
977
978
    /* Fail for an empty string match if either PCRE2_NOTEMPTY is set, or if
979
    PCRE2_NOTEMPTY_ATSTART is set and we have matched at the start of the
980
    subject. In both cases, backtracking will then try other alternatives, if
981
    any. */
982
983
1.77M
    if (Feptr == Fstart_match &&
984
1.31M
         ((mb->moptions & PCRE2_NOTEMPTY) != 0 ||
985
682k
           ((mb->moptions & PCRE2_NOTEMPTY_ATSTART) != 0 &&
986
300k
             Fstart_match == mb->start_subject + mb->start_offset)))
987
643k
      {
988
#ifdef DEBUG_SHOW_OPS
989
      fprintf(stderr, "++ Backtrack because empty string\n");
990
#endif
991
643k
      RRETURN(MATCH_NOMATCH);
992
643k
      }
993
994
    /* Fail if PCRE2_ENDANCHORED is set and the end of the match is not
995
    the end of the subject. After (*ACCEPT) we fail the entire match (at this
996
    position) but backtrack if we've reached the end of the pattern. This
997
    applies whether or not we are in a recursion. */
998
999
1.12M
    if (Feptr < mb->end_subject &&
1000
1.11M
        ((mb->moptions | mb->poptions) & PCRE2_ENDANCHORED) != 0)
1001
1.08M
      {
1002
1.08M
      if (Fop == OP_END)
1003
1.07M
        {
1004
#ifdef DEBUG_SHOW_OPS
1005
        fprintf(stderr, "++ Backtrack because not at end (endanchored set)\n");
1006
#endif
1007
1.07M
        RRETURN(MATCH_NOMATCH);
1008
1.07M
        }
1009
1010
#ifdef DEBUG_SHOW_OPS
1011
      fprintf(stderr, "++ Failed ACCEPT not at end (endanchored set)\n");
1012
#endif
1013
6.72k
      return MATCH_NOMATCH;   /* (*ACCEPT) */
1014
1.08M
      }
1015
1016
    /* Fail if we detect that the start position was moved to be either after
1017
    the end position (\K in lookahead) or before the start offset (\K in
1018
    lookbehind). If this occurs, the pattern must have used \K in a somewhat
1019
    sneaky way (e.g. by pattern recursion), because if the \K is actually
1020
    syntactically inside the lookaround, it's blocked at compile-time. */
1021
1022
42.7k
    if (Fstart_match < mb->start_subject + mb->start_offset ||
1023
42.7k
        Fstart_match > Feptr)
1024
0
      {
1025
      /* The \K expression is fairly rare. We assert it was used so that we
1026
      catch any unexpected invalid data in start_match. */
1027
0
      PCRE2_ASSERT(mb->hasbsk);
1028
1029
0
      if (!mb->allowlookaroundbsk)
1030
0
        return PCRE2_ERROR_BAD_BACKSLASH_K;
1031
0
      }
1032
1033
    /* We have a successful match of the whole pattern. Record the result and
1034
    then do a direct return from the function. If there is space in the offset
1035
    vector, set any pairs that follow the highest-numbered captured string but
1036
    are less than the number of capturing groups in the pattern to PCRE2_UNSET.
1037
    It is documented that this happens. "Gaps" are set to PCRE2_UNSET
1038
    dynamically. It is only those at the end that need setting here. */
1039
1040
42.7k
    mb->end_match_ptr = Feptr;           /* Record where we ended */
1041
42.7k
    mb->end_offset_top = Foffset_top;    /* and how many extracts were taken */
1042
42.7k
    mb->mark = Fmark;                    /* and the last success mark */
1043
42.7k
    if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr;
1044
1045
42.7k
    match_data->ovector[0] = Fstart_match - mb->start_subject;
1046
42.7k
    match_data->ovector[1] = Feptr - mb->start_subject;
1047
1048
    /* Set i to the smaller of the sizes of the external and frame ovectors. */
1049
1050
42.7k
    i = 2 * ((top_bracket + 1 > match_data->oveccount)?
1051
42.4k
      match_data->oveccount : top_bracket + 1);
1052
42.7k
    memcpy(match_data->ovector + 2, Fovector, (i - 2) * sizeof(PCRE2_SIZE));
1053
98.1k
    while (--i >= Foffset_top + 2) match_data->ovector[i] = PCRE2_UNSET;
1054
42.7k
    return MATCH_MATCH;  /* Note: NOT RRETURN */
1055
1056
1057
    /*===================================================================== */
1058
    /* Match any single character type except newline; have to take care with
1059
    CRLF newlines and partial matching. */
1060
1061
1.52M
    case OP_ANY:
1062
1.52M
    if (IS_NEWLINE(Feptr)) RRETURN(MATCH_NOMATCH);
1063
1.51M
    if (mb->partial != 0 &&
1064
424k
        Feptr == mb->end_subject - 1 &&
1065
3.29k
        NLBLOCK->nltype == NLTYPE_FIXED &&
1066
3.29k
        NLBLOCK->nllen == 2 &&
1067
0
        *Feptr == NLBLOCK->nl[0])
1068
0
      {
1069
0
      mb->hitend = TRUE;
1070
0
      if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
1071
0
      }
1072
1.51M
    PCRE2_FALLTHROUGH /* Fall through */
1073
1.51M
1074
1.51M
    /* Match any single character whatsoever. */
1075
1.51M
1076
1.74M
    case OP_ALLANY:
1077
1.74M
    if (Feptr >= mb->end_subject)  /* DO NOT merge the Feptr++ here; it must */
1078
26.3k
      {                            /* not be updated before SCHECK_PARTIAL. */
1079
26.3k
      SCHECK_PARTIAL();
1080
26.3k
      RRETURN(MATCH_NOMATCH);
1081
26.3k
      }
1082
1.71M
    Feptr++;
1083
1.71M
#ifdef SUPPORT_UNICODE
1084
1.71M
    if (utf) ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++);
1085
1.71M
#endif
1086
1.71M
    Fecode++;
1087
1.71M
    break;
1088
1089
1090
    /* ===================================================================== */
1091
    /* Match a single code unit, even in UTF mode. This opcode really does
1092
    match any code unit, even newline. (It really should be called ANYCODEUNIT,
1093
    of course - the byte name is from pre-16 bit days.) */
1094
1095
0
    case OP_ANYBYTE:
1096
0
    if (Feptr >= mb->end_subject)   /* DO NOT merge the Feptr++ here; it must */
1097
0
      {                             /* not be updated before SCHECK_PARTIAL. */
1098
0
      SCHECK_PARTIAL();
1099
0
      RRETURN(MATCH_NOMATCH);
1100
0
      }
1101
0
    Feptr++;
1102
0
    Fecode++;
1103
0
    break;
1104
1105
1106
    /* ===================================================================== */
1107
    /* Match a single character, casefully */
1108
1109
34.5M
    case OP_CHAR:
1110
34.5M
#ifdef SUPPORT_UNICODE
1111
34.5M
    if (utf)
1112
5.03M
      {
1113
5.03M
      length = 1;
1114
5.03M
      Fecode++;
1115
5.03M
      GETCHARLEN(fc, Fecode, length);
1116
5.03M
      if (length > (PCRE2_SIZE)(mb->end_subject - Feptr))
1117
93.8k
        {
1118
93.8k
        CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
1119
93.4k
        RRETURN(MATCH_NOMATCH);
1120
93.4k
        }
1121
5.88M
      for (; length > 0; length--)
1122
5.14M
        {
1123
5.14M
        if (*Fecode++ != *Feptr++) RRETURN(MATCH_NOMATCH);
1124
5.14M
        }
1125
4.94M
      }
1126
29.5M
    else
1127
29.5M
#endif
1128
1129
    /* Not UTF mode */
1130
29.5M
      {
1131
29.5M
      if (mb->end_subject - Feptr < 1)
1132
458k
        {
1133
458k
        SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
1134
457k
        RRETURN(MATCH_NOMATCH);
1135
457k
        }
1136
29.0M
      if (Fecode[1] != *Feptr++) RRETURN(MATCH_NOMATCH);
1137
11.1M
      Fecode += 2;
1138
11.1M
      }
1139
11.9M
    break;
1140
1141
1142
    /* ===================================================================== */
1143
    /* Match a single character, caselessly. If we are at the end of the
1144
    subject, give up immediately. We get here only when the pattern character
1145
    has at most one other case. Characters with more than two cases are coded
1146
    as OP_PROP with the pseudo-property PT_CLIST. */
1147
1148
13.9M
    case OP_CHARI:
1149
13.9M
    if (Feptr >= mb->end_subject)
1150
160k
      {
1151
160k
      SCHECK_PARTIAL();
1152
160k
      RRETURN(MATCH_NOMATCH);
1153
160k
      }
1154
1155
13.7M
#ifdef SUPPORT_UNICODE
1156
13.7M
    if (utf)
1157
3.84M
      {
1158
3.84M
      length = 1;
1159
3.84M
      Fecode++;
1160
3.84M
      GETCHARLEN(fc, Fecode, length);
1161
1162
      /* If the pattern character's value is < 128, we know that its other case
1163
      (if any) is also < 128 (and therefore only one code unit long in all
1164
      code-unit widths), so we can use the fast lookup table. We checked above
1165
      that there is at least one character left in the subject. */
1166
1167
3.84M
      if (fc < 128)
1168
3.55M
        {
1169
3.55M
        uint32_t cc = *Feptr;
1170
3.55M
        if (mb->lcc[fc] != TABLE_GET(cc, mb->lcc, cc)) RRETURN(MATCH_NOMATCH);
1171
1.23M
        Fecode++;
1172
1.23M
        Feptr++;
1173
1.23M
        }
1174
1175
      /* Otherwise we must pick up the subject character and use Unicode
1176
      property support to test its other case. Note that we cannot use the
1177
      value of "length" to check for sufficient bytes left, because the other
1178
      case of the character may have more or fewer code units. */
1179
1180
290k
      else
1181
290k
        {
1182
290k
        uint32_t dc;
1183
290k
        GETCHARINC(dc, Feptr);
1184
290k
        Fecode += length;
1185
290k
        if (dc != fc && dc != UCD_OTHERCASE(fc)) RRETURN(MATCH_NOMATCH);
1186
290k
        }
1187
3.84M
      }
1188
1189
    /* If UCP is set without UTF we must do the same as above, but with one
1190
    character per code unit. */
1191
1192
9.94M
    else if (ucp)
1193
7.04M
      {
1194
7.04M
      uint32_t cc = *Feptr;
1195
7.04M
      fc = Fecode[1];
1196
7.04M
      if (fc < 128)
1197
5.61M
        {
1198
5.61M
        if (mb->lcc[fc] != TABLE_GET(cc, mb->lcc, cc)) RRETURN(MATCH_NOMATCH);
1199
5.61M
        }
1200
1.43M
      else
1201
1.43M
        {
1202
1.43M
        if (cc != fc && cc != UCD_OTHERCASE(fc)) RRETURN(MATCH_NOMATCH);
1203
1.43M
        }
1204
1.12M
      Feptr++;
1205
1.12M
      Fecode += 2;
1206
1.12M
      }
1207
1208
2.90M
    else
1209
2.90M
#endif   /* SUPPORT_UNICODE */
1210
1211
    /* Not UTF or UCP mode; use the table for characters < 256. */
1212
2.90M
      {
1213
2.90M
      if (TABLE_GET(Fecode[1], mb->lcc, Fecode[1])
1214
2.90M
          != TABLE_GET(*Feptr, mb->lcc, *Feptr)) RRETURN(MATCH_NOMATCH);
1215
835k
      Feptr++;
1216
835k
      Fecode += 2;
1217
835k
      }
1218
3.22M
    break;
1219
1220
1221
    /* ===================================================================== */
1222
    /* Match not a single character. */
1223
1224
3.22M
    case OP_NOT:
1225
510k
    case OP_NOTI:
1226
510k
    if (Feptr >= mb->end_subject)
1227
17.2k
      {
1228
17.2k
      SCHECK_PARTIAL();
1229
17.2k
      RRETURN(MATCH_NOMATCH);
1230
17.2k
      }
1231
1232
493k
#ifdef SUPPORT_UNICODE
1233
493k
    if (utf)
1234
157k
      {
1235
157k
      uint32_t ch;
1236
157k
      Fecode++;
1237
157k
      GETCHARINC(ch, Fecode);
1238
157k
      GETCHARINC(fc, Feptr);
1239
157k
      if (ch == fc)
1240
12.7k
        {
1241
12.7k
        RRETURN(MATCH_NOMATCH);  /* Caseful match */
1242
12.7k
        }
1243
145k
      else if (Fop == OP_NOTI)   /* If caseless */
1244
66.1k
        {
1245
66.1k
        if (ch > 127)
1246
3.27k
          ch = UCD_OTHERCASE(ch);
1247
62.8k
        else
1248
62.8k
          ch = (mb->fcc)[ch];
1249
66.1k
        if (ch == fc) RRETURN(MATCH_NOMATCH);
1250
66.1k
        }
1251
157k
      }
1252
1253
    /* UCP without UTF is as above, but with one character per code unit. */
1254
1255
335k
    else if (ucp)
1256
47.4k
      {
1257
47.4k
      uint32_t ch;
1258
47.4k
      fc = *Feptr++;
1259
47.4k
      ch = Fecode[1];
1260
47.4k
      Fecode += 2;
1261
1262
47.4k
      if (ch == fc)
1263
3.05k
        {
1264
3.05k
        RRETURN(MATCH_NOMATCH);  /* Caseful match */
1265
3.05k
        }
1266
44.3k
      else if (Fop == OP_NOTI)   /* If caseless */
1267
38.9k
        {
1268
38.9k
        if (ch > 127)
1269
2.94k
          ch = UCD_OTHERCASE(ch);
1270
35.9k
        else
1271
35.9k
          ch = (mb->fcc)[ch];
1272
38.9k
        if (ch == fc) RRETURN(MATCH_NOMATCH);
1273
38.9k
        }
1274
47.4k
      }
1275
1276
288k
    else
1277
288k
#endif  /* SUPPORT_UNICODE */
1278
1279
    /* Neither UTF nor UCP is set */
1280
1281
288k
      {
1282
288k
      uint32_t ch = Fecode[1];
1283
288k
      fc = *Feptr++;
1284
288k
      if (ch == fc || (Fop == OP_NOTI && TABLE_GET(ch, mb->fcc, ch) == fc))
1285
21.4k
        RRETURN(MATCH_NOMATCH);
1286
266k
      Fecode += 2;
1287
266k
      }
1288
451k
    break;
1289
1290
1291
    /* ===================================================================== */
1292
    /* Match a single character repeatedly. */
1293
1294
2.39M
#define Llength      F->byte1
1295
3.25M
#define Loclength    F->byte2
1296
5.36M
#define Lstart_eptr  F->fields.char_repeat.start_eptr
1297
2.68M
#define Lcharptr     F->fields.char_repeat.charptr
1298
20.4M
#define Lmin         F->fields.char_repeat.min
1299
14.7M
#define Lmax         F->fields.char_repeat.max
1300
12.6M
#define Lc           F->fields.char_repeat.c
1301
2.86M
#define Loc          F->fields.char_repeat.oc.oc
1302
1.17M
#define Loccu        F->fields.char_repeat.oc.occu
1303
1304
451k
    case OP_EXACT:
1305
305k
    case OP_EXACTI:
1306
305k
    Lmin = Lmax = GET2(Fecode, 1);
1307
305k
    Fecode += 1 + IMM2_SIZE;
1308
305k
    goto REPEATCHAR;
1309
1310
238k
    case OP_POSUPTO:
1311
283k
    case OP_POSUPTOI:
1312
283k
    reptype = REPTYPE_POS;
1313
283k
    Lmin = 0;
1314
283k
    Lmax = GET2(Fecode, 1);
1315
283k
    Fecode += 1 + IMM2_SIZE;
1316
283k
    goto REPEATCHAR;
1317
1318
12.3k
    case OP_UPTO:
1319
21.4k
    case OP_UPTOI:
1320
21.4k
    reptype = REPTYPE_MAX;
1321
21.4k
    Lmin = 0;
1322
21.4k
    Lmax = GET2(Fecode, 1);
1323
21.4k
    Fecode += 1 + IMM2_SIZE;
1324
21.4k
    goto REPEATCHAR;
1325
1326
5.03k
    case OP_MINUPTO:
1327
33.1k
    case OP_MINUPTOI:
1328
33.1k
    reptype = REPTYPE_MIN;
1329
33.1k
    Lmin = 0;
1330
33.1k
    Lmax = GET2(Fecode, 1);
1331
33.1k
    Fecode += 1 + IMM2_SIZE;
1332
33.1k
    goto REPEATCHAR;
1333
1334
726k
    case OP_POSSTAR:
1335
888k
    case OP_POSSTARI:
1336
888k
    reptype = REPTYPE_POS;
1337
888k
    Lmin = 0;
1338
888k
    Lmax = UINT32_MAX;
1339
888k
    Fecode++;
1340
888k
    goto REPEATCHAR;
1341
1342
662k
    case OP_POSPLUS:
1343
761k
    case OP_POSPLUSI:
1344
761k
    reptype = REPTYPE_POS;
1345
761k
    Lmin = 1;
1346
761k
    Lmax = UINT32_MAX;
1347
761k
    Fecode++;
1348
761k
    goto REPEATCHAR;
1349
1350
515k
    case OP_POSQUERY:
1351
667k
    case OP_POSQUERYI:
1352
667k
    reptype = REPTYPE_POS;
1353
667k
    Lmin = 0;
1354
667k
    Lmax = 1;
1355
667k
    Fecode++;
1356
667k
    goto REPEATCHAR;
1357
1358
310k
    case OP_STAR:
1359
423k
    case OP_STARI:
1360
603k
    case OP_MINSTAR:
1361
736k
    case OP_MINSTARI:
1362
867k
    case OP_PLUS:
1363
1.48M
    case OP_PLUSI:
1364
1.53M
    case OP_MINPLUS:
1365
1.60M
    case OP_MINPLUSI:
1366
2.27M
    case OP_QUERY:
1367
2.71M
    case OP_QUERYI:
1368
2.79M
    case OP_MINQUERY:
1369
2.93M
    case OP_MINQUERYI:
1370
2.93M
    fc = *Fecode++ - ((Fop < OP_STARI)? OP_STAR : OP_STARI);
1371
2.93M
    Lmin = rep_min[fc];
1372
2.93M
    Lmax = rep_max[fc];
1373
2.93M
    reptype = rep_typ[fc];
1374
1375
    /* Common code for all repeated single-character matches. We first check
1376
    for the minimum number of characters. If the minimum equals the maximum, we
1377
    are done. Otherwise, if minimizing, check the rest of the pattern for a
1378
    match; if there isn't one, advance up to the maximum, one character at a
1379
    time.
1380
1381
    If maximizing, advance up to the maximum number of matching characters,
1382
    until Feptr is past the end of the maximum run. If possessive, we are
1383
    then done (no backing up). Otherwise, match at this position; anything
1384
    other than no match is immediately returned. For nomatch, back up one
1385
    character, unless we are matching \R and the last thing matched was
1386
    \r\n, in which case, back up two code units until we reach the first
1387
    optional character position.
1388
1389
    The various UTF/non-UTF and caseful/caseless cases are handled separately,
1390
    for speed. */
1391
1392
5.89M
    REPEATCHAR:
1393
5.89M
#ifdef SUPPORT_UNICODE
1394
5.89M
    if (utf)
1395
1.73M
      {
1396
1.73M
      length = 1;
1397
1.73M
      Lcharptr = Fecode;
1398
1.73M
      GETCHARLEN(fc, Fecode, length);
1399
1.73M
      Fecode += length;
1400
1.73M
      Llength = (uint8_t)length;
1401
1402
      /* Handle multi-code-unit character matching, caseful and caseless. */
1403
1404
1.73M
      if (length > 1)
1405
895k
        {
1406
895k
        uint32_t othercase;
1407
1408
895k
        if (Fop >= OP_STARI &&     /* Caseless */
1409
702k
            (othercase = UCD_OTHERCASE(fc)) != fc)
1410
590k
          Loclength = (uint8_t)PRIV(ord2utf)(othercase, Loccu);
1411
305k
        else Loclength = 0;
1412
1413
957k
        for (i = 1; i <= Lmin; i++)
1414
648k
          {
1415
648k
          if (Feptr <= mb->end_subject - length &&
1416
640k
            memcmp(Feptr, Lcharptr, CU2BYTES(length)) == 0) Feptr += length;
1417
586k
          else if (Loclength > 0 &&
1418
533k
                   Feptr <= mb->end_subject - Loclength &&
1419
531k
                   memcmp(Feptr, Loccu, CU2BYTES(Loclength)) == 0)
1420
616
            Feptr += Loclength;
1421
586k
          else
1422
586k
            {
1423
586k
            CHECK_PARTIAL();
1424
586k
            RRETURN(MATCH_NOMATCH);
1425
586k
            }
1426
648k
          }
1427
1428
309k
        if (Lmin == Lmax) continue;
1429
1430
309k
        if (reptype == REPTYPE_MIN)
1431
83.8k
          {
1432
83.8k
          for (;;)
1433
90.4k
            {
1434
90.4k
            RMATCH(Fecode, RM202);
1435
90.1k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1436
88.5k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
1437
84.6k
            if (Feptr <= mb->end_subject - Llength &&
1438
80.7k
              memcmp(Feptr, Lcharptr, CU2BYTES(Llength)) == 0) Feptr += Llength;
1439
78.1k
            else if (Loclength > 0 &&
1440
8.30k
                     Feptr <= mb->end_subject - Loclength &&
1441
7.41k
                     memcmp(Feptr, Loccu, CU2BYTES(Loclength)) == 0)
1442
113
              Feptr += Loclength;
1443
78.0k
            else
1444
78.0k
              {
1445
78.0k
              CHECK_PARTIAL();
1446
78.0k
              RRETURN(MATCH_NOMATCH);
1447
78.0k
              }
1448
84.6k
            }
1449
83.8k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
1450
83.8k
          }
1451
225k
        else  /* Maximize */
1452
225k
          {
1453
225k
          Lstart_eptr = Feptr;
1454
238k
          for (i = Lmin; i < Lmax; i++)
1455
233k
            {
1456
233k
            if (Feptr <= mb->end_subject - Llength &&
1457
226k
                memcmp(Feptr, Lcharptr, CU2BYTES(Llength)) == 0)
1458
12.6k
              Feptr += Llength;
1459
220k
            else if (Loclength > 0 &&
1460
49.4k
                     Feptr <= mb->end_subject - Loclength &&
1461
47.7k
                     memcmp(Feptr, Loccu, CU2BYTES(Loclength)) == 0)
1462
258
              Feptr += Loclength;
1463
220k
            else
1464
220k
              {
1465
220k
              CHECK_PARTIAL();
1466
220k
              break;
1467
220k
              }
1468
233k
            }
1469
1470
          /* After \C in UTF mode, Lstart_eptr might be in the middle of a
1471
          Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't
1472
          go too far. */
1473
1474
225k
          if (reptype != REPTYPE_POS) for(;;)
1475
141k
            {
1476
141k
            if (Feptr <= Lstart_eptr) break;
1477
6.44k
            RMATCH(Fecode, RM203);
1478
6.40k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1479
6.01k
            Feptr--;
1480
6.01k
            BACKCHAR(Feptr);
1481
6.01k
            }
1482
225k
          }
1483
224k
        break;   /* End of repeated wide character handling */
1484
309k
        }
1485
1486
      /* Length of UTF character is 1. Put it into the preserved variable and
1487
      fall through to the non-UTF code. */
1488
1489
841k
      Lc = fc;
1490
841k
      }
1491
4.16M
    else
1492
4.16M
#endif  /* SUPPORT_UNICODE */
1493
1494
    /* When not in UTF mode, load a single-code-unit character. Then proceed as
1495
    above, using Unicode casing if either UTF or UCP is set. */
1496
1497
4.16M
    Lc = *Fecode++;
1498
1499
    /* Caseless comparison */
1500
1501
5.00M
    if (Fop >= OP_STARI)
1502
1.47M
      {
1503
1.47M
#if PCRE2_CODE_UNIT_WIDTH == 8
1504
1.47M
#ifdef SUPPORT_UNICODE
1505
1.47M
      if (ucp && !utf && Lc > 127) Loc = UCD_OTHERCASE(Lc);
1506
1.34M
      else
1507
1.34M
#endif  /* SUPPORT_UNICODE */
1508
      /* Lc will be < 128 in UTF-8 mode. */
1509
1.34M
      Loc = mb->fcc[Lc];
1510
#else /* 16-bit & 32-bit */
1511
#ifdef SUPPORT_UNICODE
1512
      if ((utf || ucp) && Lc > 127) Loc = UCD_OTHERCASE(Lc);
1513
      else
1514
#endif  /* SUPPORT_UNICODE */
1515
      Loc = TABLE_GET(Lc, mb->fcc, Lc);
1516
#endif  /* PCRE2_CODE_UNIT_WIDTH == 8 */
1517
1518
1.49M
      for (i = 1; i <= Lmin; i++)
1519
341k
        {
1520
341k
        uint32_t cc;                 /* Faster than PCRE2_UCHAR */
1521
341k
        if (Feptr >= mb->end_subject)
1522
6.33k
          {
1523
6.33k
          SCHECK_PARTIAL();
1524
6.31k
          RRETURN(MATCH_NOMATCH);
1525
6.31k
          }
1526
334k
        cc = *Feptr;
1527
334k
        if (Lc != cc && Loc != cc) RRETURN(MATCH_NOMATCH);
1528
27.8k
        Feptr++;
1529
27.8k
        }
1530
1.15M
      if (Lmin == Lmax) continue;
1531
1532
1.15M
      if (reptype == REPTYPE_MIN)
1533
255k
        {
1534
255k
        for (;;)
1535
282k
          {
1536
282k
          uint32_t cc;               /* Faster than PCRE2_UCHAR */
1537
282k
          RMATCH(Fecode, RM25);
1538
280k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1539
263k
          if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
1540
259k
          if (Feptr >= mb->end_subject)
1541
5.51k
            {
1542
5.51k
            SCHECK_PARTIAL();
1543
5.50k
            RRETURN(MATCH_NOMATCH);
1544
5.50k
            }
1545
253k
          cc = *Feptr;
1546
253k
          if (Lc != cc && Loc != cc) RRETURN(MATCH_NOMATCH);
1547
26.9k
          Feptr++;
1548
26.9k
          }
1549
255k
        PCRE2_UNREACHABLE(); /* Control never reaches here */
1550
255k
        }
1551
1552
902k
      else  /* Maximize */
1553
902k
        {
1554
902k
        Lstart_eptr = Feptr;
1555
997k
        for (i = Lmin; i < Lmax; i++)
1556
959k
          {
1557
959k
          uint32_t cc;               /* Faster than PCRE2_UCHAR */
1558
959k
          if (Feptr >= mb->end_subject)
1559
10.9k
            {
1560
10.9k
            SCHECK_PARTIAL();
1561
10.9k
            break;
1562
10.9k
            }
1563
948k
          cc = *Feptr;
1564
948k
          if (Lc != cc && Loc != cc) break;
1565
94.3k
          Feptr++;
1566
94.3k
          }
1567
902k
        if (reptype != REPTYPE_POS) for (;;)
1568
616k
          {
1569
616k
          if (Feptr == Lstart_eptr) break;
1570
50.4k
          RMATCH(Fecode, RM26);
1571
50.1k
          Feptr--;
1572
50.1k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1573
50.1k
          }
1574
902k
        }
1575
1.15M
      }
1576
1577
    /* Caseful comparisons (includes all multi-byte characters) */
1578
1579
3.53M
    else
1580
3.53M
      {
1581
3.67M
      for (i = 1; i <= Lmin; i++)
1582
961k
        {
1583
961k
        if (Feptr >= mb->end_subject)
1584
18.6k
          {
1585
18.6k
          SCHECK_PARTIAL();
1586
18.6k
          RRETURN(MATCH_NOMATCH);
1587
18.6k
          }
1588
943k
        if (Lc != *Feptr++) RRETURN(MATCH_NOMATCH);
1589
943k
        }
1590
1591
2.70M
      if (Lmin == Lmax) continue;
1592
1593
2.70M
      if (reptype == REPTYPE_MIN)
1594
240k
        {
1595
240k
        for (;;)
1596
260k
          {
1597
260k
          RMATCH(Fecode, RM27);
1598
256k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1599
254k
          if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
1600
250k
          if (Feptr >= mb->end_subject)
1601
3.81k
            {
1602
3.81k
            SCHECK_PARTIAL();
1603
3.79k
            RRETURN(MATCH_NOMATCH);
1604
3.79k
            }
1605
246k
          if (Lc != *Feptr++) RRETURN(MATCH_NOMATCH);
1606
246k
          }
1607
240k
        PCRE2_UNREACHABLE(); /* Control never reaches here */
1608
240k
        }
1609
2.46M
      else  /* Maximize */
1610
2.46M
        {
1611
2.46M
        Lstart_eptr = Feptr;
1612
2.85M
        for (i = Lmin; i < Lmax; i++)
1613
2.77M
          {
1614
2.77M
          if (Feptr >= mb->end_subject)
1615
49.5k
            {
1616
49.5k
            SCHECK_PARTIAL();
1617
49.4k
            break;
1618
49.5k
            }
1619
1620
2.72M
          if (Lc != *Feptr) break;
1621
390k
          Feptr++;
1622
390k
          }
1623
1624
2.46M
        if (reptype != REPTYPE_POS) for (;;)
1625
1.00M
          {
1626
1.00M
          if (Feptr <= Lstart_eptr) break;
1627
86.3k
          RMATCH(Fecode, RM28);
1628
84.8k
          Feptr--;
1629
84.8k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1630
84.8k
          }
1631
2.46M
        }
1632
2.70M
      }
1633
3.36M
    break;
1634
1635
3.36M
#undef Llength
1636
3.36M
#undef Loclength
1637
3.36M
#undef Lstart_eptr
1638
3.36M
#undef Lcharptr
1639
3.36M
#undef Lmin
1640
3.36M
#undef Lmax
1641
3.36M
#undef Lc
1642
3.36M
#undef Loc
1643
3.36M
#undef Loccu
1644
1645
1646
    /* ===================================================================== */
1647
    /* Match a negated single one-byte character repeatedly. This is almost a
1648
    repeat of the code for a repeated single character, but I haven't found a
1649
    nice way of commoning these up that doesn't require a test of the
1650
    positive/negative option for each character match. Maybe that wouldn't add
1651
    very much to the time taken, but character matching *is* what this is all
1652
    about... */
1653
1654
3.39M
#define Lstart_eptr  F->fields.charnot_repeat.start_eptr
1655
11.2M
#define Lmin         F->fields.charnot_repeat.min
1656
52.2M
#define Lmax         F->fields.charnot_repeat.max
1657
50.0M
#define Lc           F->fields.charnot_repeat.c
1658
8.01M
#define Loc          F->fields.charnot_repeat.oc
1659
1660
3.36M
    case OP_NOTEXACT:
1661
272k
    case OP_NOTEXACTI:
1662
272k
    Lmin = Lmax = GET2(Fecode, 1);
1663
272k
    Fecode += 1 + IMM2_SIZE;
1664
272k
    goto REPEATNOTCHAR;
1665
1666
256k
    case OP_NOTUPTO:
1667
330k
    case OP_NOTUPTOI:
1668
330k
    Lmin = 0;
1669
330k
    Lmax = GET2(Fecode, 1);
1670
330k
    reptype = REPTYPE_MAX;
1671
330k
    Fecode += 1 + IMM2_SIZE;
1672
330k
    goto REPEATNOTCHAR;
1673
1674
52.4k
    case OP_NOTMINUPTO:
1675
125k
    case OP_NOTMINUPTOI:
1676
125k
    Lmin = 0;
1677
125k
    Lmax = GET2(Fecode, 1);
1678
125k
    reptype = REPTYPE_MIN;
1679
125k
    Fecode += 1 + IMM2_SIZE;
1680
125k
    goto REPEATNOTCHAR;
1681
1682
782k
    case OP_NOTPOSSTAR:
1683
995k
    case OP_NOTPOSSTARI:
1684
995k
    reptype = REPTYPE_POS;
1685
995k
    Lmin = 0;
1686
995k
    Lmax = UINT32_MAX;
1687
995k
    Fecode++;
1688
995k
    goto REPEATNOTCHAR;
1689
1690
184k
    case OP_NOTPOSPLUS:
1691
272k
    case OP_NOTPOSPLUSI:
1692
272k
    reptype = REPTYPE_POS;
1693
272k
    Lmin = 1;
1694
272k
    Lmax = UINT32_MAX;
1695
272k
    Fecode++;
1696
272k
    goto REPEATNOTCHAR;
1697
1698
26.5k
    case OP_NOTPOSQUERY:
1699
27.0k
    case OP_NOTPOSQUERYI:
1700
27.0k
    reptype = REPTYPE_POS;
1701
27.0k
    Lmin = 0;
1702
27.0k
    Lmax = 1;
1703
27.0k
    Fecode++;
1704
27.0k
    goto REPEATNOTCHAR;
1705
1706
3.91k
    case OP_NOTPOSUPTO:
1707
14.3k
    case OP_NOTPOSUPTOI:
1708
14.3k
    reptype = REPTYPE_POS;
1709
14.3k
    Lmin = 0;
1710
14.3k
    Lmax = GET2(Fecode, 1);
1711
14.3k
    Fecode += 1 + IMM2_SIZE;
1712
14.3k
    goto REPEATNOTCHAR;
1713
1714
18.1k
    case OP_NOTSTAR:
1715
32.4k
    case OP_NOTSTARI:
1716
51.4k
    case OP_NOTMINSTAR:
1717
62.7k
    case OP_NOTMINSTARI:
1718
97.9k
    case OP_NOTPLUS:
1719
105k
    case OP_NOTPLUSI:
1720
111k
    case OP_NOTMINPLUS:
1721
131k
    case OP_NOTMINPLUSI:
1722
170k
    case OP_NOTQUERY:
1723
175k
    case OP_NOTQUERYI:
1724
177k
    case OP_NOTMINQUERY:
1725
189k
    case OP_NOTMINQUERYI:
1726
189k
    fc = *Fecode++ - ((Fop >= OP_NOTSTARI)? OP_NOTSTARI: OP_NOTSTAR);
1727
189k
    Lmin = rep_min[fc];
1728
189k
    Lmax = rep_max[fc];
1729
189k
    reptype = rep_typ[fc];
1730
1731
    /* Common code for all repeated single-character non-matches. */
1732
1733
2.22M
    REPEATNOTCHAR:
1734
2.22M
    GETCHARINCTEST(Lc, Fecode);
1735
1736
    /* The code is duplicated for the caseless and caseful cases, for speed,
1737
    since matching characters is likely to be quite common. First, ensure the
1738
    minimum number of matches are present. If Lmin = Lmax, we are done.
1739
    Otherwise, if minimizing, keep trying the rest of the expression and
1740
    advancing one matching character if failing, up to the maximum.
1741
    Alternatively, if maximizing, find the maximum number of characters and
1742
    work backwards. */
1743
1744
2.22M
    if (Fop >= OP_NOTSTARI)     /* Caseless */
1745
600k
      {
1746
600k
#ifdef SUPPORT_UNICODE
1747
600k
      if ((utf || ucp) && Lc > 127)
1748
5.24k
        Loc = UCD_OTHERCASE(Lc);
1749
594k
      else
1750
594k
#endif /* SUPPORT_UNICODE */
1751
1752
594k
      Loc = TABLE_GET(Lc, mb->fcc, Lc);  /* Other case from table */
1753
1754
600k
#ifdef SUPPORT_UNICODE
1755
600k
      if (utf)
1756
166k
        {
1757
166k
        uint32_t d;
1758
498k
        for (i = 1; i <= Lmin; i++)
1759
360k
          {
1760
360k
          if (Feptr >= mb->end_subject)
1761
2.69k
            {
1762
2.69k
            SCHECK_PARTIAL();
1763
2.68k
            RRETURN(MATCH_NOMATCH);
1764
2.68k
            }
1765
357k
          GETCHARINC(d, Feptr);
1766
357k
          if (Lc == d || Loc == d) RRETURN(MATCH_NOMATCH);
1767
357k
          }
1768
166k
        }
1769
433k
      else
1770
433k
#endif  /* SUPPORT_UNICODE */
1771
1772
      /* Not UTF mode */
1773
433k
        {
1774
629k
        for (i = 1; i <= Lmin; i++)
1775
231k
          {
1776
231k
          if (Feptr >= mb->end_subject)
1777
2.73k
            {
1778
2.73k
            SCHECK_PARTIAL();
1779
2.72k
            RRETURN(MATCH_NOMATCH);
1780
2.72k
            }
1781
228k
          if (Lc == *Feptr || Loc == *Feptr) RRETURN(MATCH_NOMATCH);
1782
195k
          Feptr++;
1783
195k
          }
1784
433k
        }
1785
1786
536k
      if (Lmin == Lmax) continue;  /* Finished for exact count */
1787
1788
493k
      if (reptype == REPTYPE_MIN)
1789
110k
        {
1790
110k
#ifdef SUPPORT_UNICODE
1791
110k
        if (utf)
1792
27.9k
          {
1793
27.9k
          uint32_t d;
1794
27.9k
          for (;;)
1795
196k
            {
1796
196k
            RMATCH(Fecode, RM204);
1797
196k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1798
189k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
1799
180k
            if (Feptr >= mb->end_subject)
1800
3.09k
              {
1801
3.09k
              SCHECK_PARTIAL();
1802
3.08k
              RRETURN(MATCH_NOMATCH);
1803
3.08k
              }
1804
177k
            GETCHARINC(d, Feptr);
1805
177k
            if (Lc == d || Loc == d) RRETURN(MATCH_NOMATCH);
1806
177k
            }
1807
27.9k
          }
1808
82.2k
        else
1809
82.2k
#endif  /*SUPPORT_UNICODE */
1810
1811
        /* Not UTF mode */
1812
82.2k
          {
1813
82.2k
          for (;;)
1814
297k
            {
1815
297k
            RMATCH(Fecode, RM29);
1816
297k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1817
292k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
1818
228k
            if (Feptr >= mb->end_subject)
1819
2.54k
              {
1820
2.54k
              SCHECK_PARTIAL();
1821
2.53k
              RRETURN(MATCH_NOMATCH);
1822
2.53k
              }
1823
226k
            if (Lc == *Feptr || Loc == *Feptr) RRETURN(MATCH_NOMATCH);
1824
215k
            Feptr++;
1825
215k
            }
1826
82.2k
          }
1827
110k
        PCRE2_UNREACHABLE(); /* Control never reaches here */
1828
110k
        }
1829
1830
      /* Maximize case */
1831
1832
382k
      else
1833
382k
        {
1834
382k
        Lstart_eptr = Feptr;
1835
1836
382k
#ifdef SUPPORT_UNICODE
1837
382k
        if (utf)
1838
83.0k
          {
1839
83.0k
          uint32_t d;
1840
737k
          for (i = Lmin; i < Lmax; i++)
1841
684k
            {
1842
684k
            int len = 1;
1843
684k
            if (Feptr >= mb->end_subject)
1844
6.93k
              {
1845
6.93k
              SCHECK_PARTIAL();
1846
6.86k
              break;
1847
6.93k
              }
1848
677k
            GETCHARLEN(d, Feptr, len);
1849
677k
            if (Lc == d || Loc == d) break;
1850
653k
            Feptr += len;
1851
653k
            }
1852
1853
          /* After \C in UTF mode, Lstart_eptr might be in the middle of a
1854
          Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't
1855
          go too far. */
1856
1857
82.9k
          if (reptype != REPTYPE_POS) for(;;)
1858
197k
            {
1859
197k
            if (Feptr <= Lstart_eptr) break;
1860
140k
            RMATCH(Fecode, RM205);
1861
140k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1862
140k
            Feptr--;
1863
140k
            BACKCHAR(Feptr);
1864
140k
            }
1865
82.9k
          }
1866
299k
        else
1867
299k
#endif  /* SUPPORT_UNICODE */
1868
1869
        /* Not UTF mode */
1870
299k
          {
1871
6.09M
          for (i = Lmin; i < Lmax; i++)
1872
6.06M
            {
1873
6.06M
            if (Feptr >= mb->end_subject)
1874
11.0k
              {
1875
11.0k
              SCHECK_PARTIAL();
1876
11.0k
              break;
1877
11.0k
              }
1878
6.05M
            if (Lc == *Feptr || Loc == *Feptr) break;
1879
5.79M
            Feptr++;
1880
5.79M
            }
1881
299k
          if (reptype != REPTYPE_POS) for (;;)
1882
191k
            {
1883
191k
            if (Feptr == Lstart_eptr) break;
1884
157k
            RMATCH(Fecode, RM30);
1885
157k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1886
149k
            Feptr--;
1887
149k
            }
1888
299k
          }
1889
382k
        }
1890
493k
      }
1891
1892
    /* Caseful comparisons */
1893
1894
1.62M
    else
1895
1.62M
      {
1896
1.62M
#ifdef SUPPORT_UNICODE
1897
1.62M
      if (utf)
1898
292k
        {
1899
292k
        uint32_t d;
1900
1.36M
        for (i = 1; i <= Lmin; i++)
1901
1.12M
          {
1902
1.12M
          if (Feptr >= mb->end_subject)
1903
5.57k
            {
1904
5.57k
            SCHECK_PARTIAL();
1905
5.56k
            RRETURN(MATCH_NOMATCH);
1906
5.56k
            }
1907
1.12M
          GETCHARINC(d, Feptr);
1908
1.12M
          if (Lc == d) RRETURN(MATCH_NOMATCH);
1909
1.12M
          }
1910
292k
        }
1911
1.33M
      else
1912
1.33M
#endif
1913
      /* Not UTF mode */
1914
1.33M
        {
1915
1.93M
        for (i = 1; i <= Lmin; i++)
1916
664k
          {
1917
664k
          if (Feptr >= mb->end_subject)
1918
12.5k
            {
1919
12.5k
            SCHECK_PARTIAL();
1920
12.5k
            RRETURN(MATCH_NOMATCH);
1921
12.5k
            }
1922
652k
          if (Lc == *Feptr++) RRETURN(MATCH_NOMATCH);
1923
652k
          }
1924
1.33M
        }
1925
1926
1.50M
      if (Lmin == Lmax) continue;
1927
1928
1.37M
      if (reptype == REPTYPE_MIN)
1929
78.4k
        {
1930
78.4k
#ifdef SUPPORT_UNICODE
1931
78.4k
        if (utf)
1932
59.7k
          {
1933
59.7k
          uint32_t d;
1934
59.7k
          for (;;)
1935
262k
            {
1936
262k
            RMATCH(Fecode, RM206);
1937
262k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1938
261k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
1939
214k
            if (Feptr >= mb->end_subject)
1940
3.35k
              {
1941
3.35k
              SCHECK_PARTIAL();
1942
3.34k
              RRETURN(MATCH_NOMATCH);
1943
3.34k
              }
1944
210k
            GETCHARINC(d, Feptr);
1945
210k
            if (Lc == d) RRETURN(MATCH_NOMATCH);
1946
210k
            }
1947
59.7k
          }
1948
18.6k
        else
1949
18.6k
#endif
1950
        /* Not UTF mode */
1951
18.6k
          {
1952
18.6k
          for (;;)
1953
142k
            {
1954
142k
            RMATCH(Fecode, RM31);
1955
141k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1956
135k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
1957
133k
            if (Feptr >= mb->end_subject)
1958
3.62k
              {
1959
3.62k
              SCHECK_PARTIAL();
1960
3.61k
              RRETURN(MATCH_NOMATCH);
1961
3.61k
              }
1962
129k
            if (Lc == *Feptr++) RRETURN(MATCH_NOMATCH);
1963
129k
            }
1964
18.6k
          }
1965
78.4k
        PCRE2_UNREACHABLE(); /* Control never reaches here */
1966
78.4k
        }
1967
1968
      /* Maximize case */
1969
1970
1.29M
      else
1971
1.29M
        {
1972
1.29M
        Lstart_eptr = Feptr;
1973
1974
1.29M
#ifdef SUPPORT_UNICODE
1975
1.29M
        if (utf)
1976
95.6k
          {
1977
95.6k
          uint32_t d;
1978
1.48M
          for (i = Lmin; i < Lmax; i++)
1979
1.47M
            {
1980
1.47M
            int len = 1;
1981
1.47M
            if (Feptr >= mb->end_subject)
1982
16.7k
              {
1983
16.7k
              SCHECK_PARTIAL();
1984
16.7k
              break;
1985
16.7k
              }
1986
1.45M
            GETCHARLEN(d, Feptr, len);
1987
1.45M
            if (Lc == d) break;
1988
1.39M
            Feptr += len;
1989
1.39M
            }
1990
1991
          /* After \C in UTF mode, Lstart_eptr might be in the middle of a
1992
          Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't
1993
          go too far. */
1994
1995
95.5k
          if (reptype != REPTYPE_POS) for(;;)
1996
109k
            {
1997
109k
            if (Feptr <= Lstart_eptr) break;
1998
83.1k
            RMATCH(Fecode, RM207);
1999
83.1k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2000
82.8k
            Feptr--;
2001
82.8k
            BACKCHAR(Feptr);
2002
82.8k
            }
2003
95.5k
          }
2004
1.20M
        else
2005
1.20M
#endif
2006
        /* Not UTF mode */
2007
1.20M
          {
2008
38.7M
          for (i = Lmin; i < Lmax; i++)
2009
38.4M
            {
2010
38.4M
            if (Feptr >= mb->end_subject)
2011
63.8k
              {
2012
63.8k
              SCHECK_PARTIAL();
2013
63.7k
              break;
2014
63.8k
              }
2015
38.4M
            if (Lc == *Feptr) break;
2016
37.5M
            Feptr++;
2017
37.5M
            }
2018
1.20M
          if (reptype != REPTYPE_POS) for (;;)
2019
1.21M
            {
2020
1.21M
            if (Feptr == Lstart_eptr) break;
2021
910k
            RMATCH(Fecode, RM32);
2022
909k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2023
898k
            Feptr--;
2024
898k
            }
2025
1.20M
          }
2026
1.29M
        }
2027
1.37M
      }
2028
1.66M
    break;
2029
2030
1.66M
#undef Lstart_eptr
2031
1.66M
#undef Lmin
2032
1.66M
#undef Lmax
2033
1.66M
#undef Lc
2034
1.66M
#undef Loc
2035
2036
2037
    /* ===================================================================== */
2038
    /* Match a bit-mapped character class, possibly repeatedly. These opcodes
2039
    are used when all the characters in the class have values in the range
2040
    0-255, and either the matching is caseful, or the characters are in the
2041
    range 0-127 when UTF processing is enabled. The only difference between
2042
    OP_CLASS and OP_NCLASS occurs when a data character outside the range is
2043
    encountered. */
2044
2045
9.80M
#define Lbyte_map_address  F->fields.class_repeat.byte_map_address
2046
6.97M
#define Lbyte_map          ((const unsigned char *)Lbyte_map_address)
2047
2.99M
#define Lstart_eptr        F->fields.class_repeat.start_eptr
2048
9.77M
#define Lmin               F->fields.class_repeat.min
2049
9.56M
#define Lmax               F->fields.class_repeat.max
2050
2051
1.66M
    case OP_NCLASS:
2052
2.82M
    case OP_CLASS:
2053
2.82M
      {
2054
2.82M
      Lbyte_map_address = Fecode + 1;           /* Save for matching */
2055
2.82M
      Fecode += 1 + (32 / sizeof(PCRE2_UCHAR)); /* Advance past the item */
2056
2057
      /* Look past the end of the item to see if there is repeat information
2058
      following. Then obey similar code to character type repeats. */
2059
2060
2.82M
      switch (*Fecode)
2061
2.82M
        {
2062
227k
        case OP_CRSTAR:
2063
304k
        case OP_CRMINSTAR:
2064
331k
        case OP_CRPLUS:
2065
580k
        case OP_CRMINPLUS:
2066
720k
        case OP_CRQUERY:
2067
752k
        case OP_CRMINQUERY:
2068
1.00M
        case OP_CRPOSSTAR:
2069
1.24M
        case OP_CRPOSPLUS:
2070
1.29M
        case OP_CRPOSQUERY:
2071
1.29M
        fc = *Fecode++ - OP_CRSTAR;
2072
1.29M
        Lmin = rep_min[fc];
2073
1.29M
        Lmax = rep_max[fc];
2074
1.29M
        reptype = rep_typ[fc];
2075
1.29M
        break;
2076
2077
68.4k
        case OP_CRRANGE:
2078
86.7k
        case OP_CRMINRANGE:
2079
180k
        case OP_CRPOSRANGE:
2080
180k
        Lmin = GET2(Fecode, 1);
2081
180k
        Lmax = GET2(Fecode, 1 + IMM2_SIZE);
2082
180k
        if (Lmax == 0) Lmax = UINT32_MAX;       /* Max 0 => infinity */
2083
180k
        reptype = rep_typ[*Fecode - OP_CRSTAR];
2084
180k
        Fecode += 1 + 2 * IMM2_SIZE;
2085
180k
        break;
2086
2087
1.34M
        default:               /* No repeat follows */
2088
1.34M
        Lmin = Lmax = 1;
2089
1.34M
        break;
2090
2.82M
        }
2091
2092
      /* First, ensure the minimum number of matches are present. */
2093
2094
2.82M
#ifdef SUPPORT_UNICODE
2095
2.82M
      if (utf)
2096
660k
        {
2097
1.00M
        for (i = 1; i <= Lmin; i++)
2098
777k
          {
2099
777k
          if (Feptr >= mb->end_subject)
2100
6.29k
            {
2101
6.29k
            SCHECK_PARTIAL();
2102
6.27k
            RRETURN(MATCH_NOMATCH);
2103
6.27k
            }
2104
770k
          GETCHARINC(fc, Feptr);
2105
770k
          if (fc > 255)
2106
15.2k
            {
2107
15.2k
            if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH);
2108
15.2k
            }
2109
755k
          else
2110
755k
            if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
2111
770k
          }
2112
660k
        }
2113
2.16M
      else
2114
2.16M
#endif
2115
      /* Not UTF mode */
2116
2.16M
        {
2117
2.90M
        for (i = 1; i <= Lmin; i++)
2118
1.50M
          {
2119
1.50M
          if (Feptr >= mb->end_subject)
2120
25.2k
            {
2121
25.2k
            SCHECK_PARTIAL();
2122
25.2k
            RRETURN(MATCH_NOMATCH);
2123
25.2k
            }
2124
1.48M
          fc = *Feptr++;
2125
#if PCRE2_CODE_UNIT_WIDTH != 8
2126
          if (fc > 255)
2127
            {
2128
            if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH);
2129
            }
2130
          else
2131
#endif
2132
1.48M
          if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
2133
1.48M
          }
2134
2.16M
        }
2135
2136
      /* If Lmax == Lmin we are done. Continue with main loop. */
2137
2138
1.62M
      if (Lmin == Lmax) continue;
2139
2140
      /* If minimizing, keep testing the rest of the expression and advancing
2141
      the pointer while it matches the class. */
2142
2143
944k
      if (reptype == REPTYPE_MIN)
2144
130k
        {
2145
130k
#ifdef SUPPORT_UNICODE
2146
130k
        if (utf)
2147
36.8k
          {
2148
36.8k
          for (;;)
2149
96.7k
            {
2150
96.7k
            RMATCH(Fecode, RM200);
2151
96.0k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2152
95.5k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
2153
84.5k
            if (Feptr >= mb->end_subject)
2154
2.74k
              {
2155
2.74k
              SCHECK_PARTIAL();
2156
2.73k
              RRETURN(MATCH_NOMATCH);
2157
2.73k
              }
2158
81.8k
            GETCHARINC(fc, Feptr);
2159
81.8k
            if (fc > 255)
2160
1.28k
              {
2161
1.28k
              if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH);
2162
1.28k
              }
2163
80.5k
            else
2164
80.5k
              if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
2165
81.8k
            }
2166
36.8k
          }
2167
93.8k
        else
2168
93.8k
#endif
2169
        /* Not UTF mode */
2170
93.8k
          {
2171
93.8k
          for (;;)
2172
536k
            {
2173
536k
            RMATCH(Fecode, RM23);
2174
534k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2175
506k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
2176
495k
            if (Feptr >= mb->end_subject)
2177
5.32k
              {
2178
5.32k
              SCHECK_PARTIAL();
2179
5.31k
              RRETURN(MATCH_NOMATCH);
2180
5.31k
              }
2181
490k
            fc = *Feptr++;
2182
#if PCRE2_CODE_UNIT_WIDTH != 8
2183
            if (fc > 255)
2184
              {
2185
              if (Fop == OP_CLASS) RRETURN(MATCH_NOMATCH);
2186
              }
2187
            else
2188
#endif
2189
490k
            if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) RRETURN(MATCH_NOMATCH);
2190
490k
            }
2191
93.8k
          }
2192
130k
        PCRE2_UNREACHABLE(); /* Control never reaches here */
2193
130k
        }
2194
2195
      /* If maximizing, find the longest possible run, then work backwards. */
2196
2197
813k
      else
2198
813k
        {
2199
813k
        Lstart_eptr = Feptr;
2200
2201
813k
#ifdef SUPPORT_UNICODE
2202
813k
        if (utf)
2203
89.2k
          {
2204
227k
          for (i = Lmin; i < Lmax; i++)
2205
218k
            {
2206
218k
            int len = 1;
2207
218k
            if (Feptr >= mb->end_subject)
2208
3.99k
              {
2209
3.99k
              SCHECK_PARTIAL();
2210
3.97k
              break;
2211
3.99k
              }
2212
214k
            GETCHARLEN(fc, Feptr, len);
2213
214k
            if (fc > 255)
2214
3.78k
              {
2215
3.78k
              if (Fop == OP_CLASS) break;
2216
3.78k
              }
2217
210k
            else
2218
210k
              if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) break;
2219
137k
            Feptr += len;
2220
137k
            }
2221
2222
89.1k
          if (reptype == REPTYPE_POS) continue;    /* No backtracking */
2223
2224
          /* After \C in UTF mode, Lstart_eptr might be in the middle of a
2225
          Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't
2226
          go too far. */
2227
2228
30.0k
          for (;;)
2229
85.8k
            {
2230
85.8k
            RMATCH(Fecode, RM201);
2231
84.7k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2232
84.4k
            if (Feptr-- <= Lstart_eptr) break;  /* Tried at original position */
2233
55.7k
            BACKCHAR(Feptr);
2234
55.7k
            }
2235
30.0k
          }
2236
724k
        else
2237
724k
#endif
2238
          /* Not UTF mode */
2239
724k
          {
2240
4.10M
          for (i = Lmin; i < Lmax; i++)
2241
3.99M
            {
2242
3.99M
            if (Feptr >= mb->end_subject)
2243
35.2k
              {
2244
35.2k
              SCHECK_PARTIAL();
2245
35.2k
              break;
2246
35.2k
              }
2247
3.95M
            fc = *Feptr;
2248
#if PCRE2_CODE_UNIT_WIDTH != 8
2249
            if (fc > 255)
2250
              {
2251
              if (Fop == OP_CLASS) break;
2252
              }
2253
            else
2254
#endif
2255
3.95M
            if ((Lbyte_map[fc/8] & (1u << (fc&7))) == 0) break;
2256
3.37M
            Feptr++;
2257
3.37M
            }
2258
2259
724k
          if (reptype == REPTYPE_POS) continue;    /* No backtracking */
2260
2261
2.09M
          while (Feptr >= Lstart_eptr)
2262
1.76M
            {
2263
1.76M
            RMATCH(Fecode, RM24);
2264
1.76M
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2265
1.68M
            Feptr--;
2266
1.68M
            }
2267
415k
          }
2268
2269
362k
        RRETURN(MATCH_NOMATCH);
2270
362k
        }
2271
944k
      }
2272
2273
944k
    PCRE2_UNREACHABLE(); /* Control never reaches here */
2274
2275
0
#undef Lbyte_map_address
2276
0
#undef Lbyte_map
2277
0
#undef Lstart_eptr
2278
0
#undef Lmin
2279
0
#undef Lmax
2280
2281
2282
    /* ===================================================================== */
2283
    /* Match an extended character class. In the 8-bit library, this opcode is
2284
    encountered only when UTF-8 mode mode is supported. In the 16-bit and
2285
    32-bit libraries, codepoints greater than 255 may be encountered even when
2286
    UTF is not supported. */
2287
2288
410k
#define Lstart_eptr  F->fields.xclass_repeat.start_eptr
2289
6.02M
#define Lxclass_data F->fields.xclass_repeat.xclass_data
2290
5.78M
#define Lmin         F->fields.xclass_repeat.min
2291
6.02M
#define Lmax         F->fields.xclass_repeat.max
2292
2293
0
#ifdef SUPPORT_WIDE_CHARS
2294
1.50M
    case OP_XCLASS:
2295
1.50M
      {
2296
1.50M
      Lxclass_data = Fecode + 1 + LINK_SIZE;  /* Save for matching */
2297
1.50M
      Fecode += GET(Fecode, 1);               /* Advance past the item */
2298
2299
1.50M
      switch (*Fecode)
2300
1.50M
        {
2301
19.0k
        case OP_CRSTAR:
2302
169k
        case OP_CRMINSTAR:
2303
187k
        case OP_CRPLUS:
2304
196k
        case OP_CRMINPLUS:
2305
211k
        case OP_CRQUERY:
2306
399k
        case OP_CRMINQUERY:
2307
441k
        case OP_CRPOSSTAR:
2308
531k
        case OP_CRPOSPLUS:
2309
580k
        case OP_CRPOSQUERY:
2310
580k
        fc = *Fecode++ - OP_CRSTAR;
2311
580k
        Lmin = rep_min[fc];
2312
580k
        Lmax = rep_max[fc];
2313
580k
        reptype = rep_typ[fc];
2314
580k
        break;
2315
2316
31.7k
        case OP_CRRANGE:
2317
39.1k
        case OP_CRMINRANGE:
2318
42.4k
        case OP_CRPOSRANGE:
2319
42.4k
        Lmin = GET2(Fecode, 1);
2320
42.4k
        Lmax = GET2(Fecode, 1 + IMM2_SIZE);
2321
42.4k
        if (Lmax == 0) Lmax = UINT32_MAX;  /* Max 0 => infinity */
2322
42.4k
        reptype = rep_typ[*Fecode - OP_CRSTAR];
2323
42.4k
        Fecode += 1 + 2 * IMM2_SIZE;
2324
42.4k
        break;
2325
2326
883k
        default:               /* No repeat follows */
2327
883k
        Lmin = Lmax = 1;
2328
883k
        break;
2329
1.50M
        }
2330
2331
      /* First, ensure the minimum number of matches are present. */
2332
2333
2.08M
      for (i = 1; i <= Lmin; i++)
2334
1.10M
        {
2335
1.10M
        if (Feptr >= mb->end_subject)
2336
11.0k
          {
2337
11.0k
          SCHECK_PARTIAL();
2338
11.0k
          RRETURN(MATCH_NOMATCH);
2339
11.0k
          }
2340
1.09M
        GETCHARINCTEST(fc, Feptr);
2341
1.09M
        if (!PRIV(xclass)(fc, Lxclass_data,
2342
1.09M
            (const uint8_t*)mb->start_code, utf))
2343
512k
          RRETURN(MATCH_NOMATCH);
2344
1.09M
        }
2345
2346
      /* If Lmax == Lmin we can just continue with the main loop. */
2347
2348
982k
      if (Lmin == Lmax) continue;
2349
2350
      /* If minimizing, keep testing the rest of the expression and advancing
2351
      the pointer while it matches the class. */
2352
2353
525k
      if (reptype == REPTYPE_MIN)
2354
350k
        {
2355
350k
        for (;;)
2356
1.11M
          {
2357
1.11M
          RMATCH(Fecode, RM100);
2358
1.11M
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2359
1.03M
          if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
2360
1.02M
          if (Feptr >= mb->end_subject)
2361
6.28k
            {
2362
6.28k
            SCHECK_PARTIAL();
2363
6.27k
            RRETURN(MATCH_NOMATCH);
2364
6.27k
            }
2365
1.01M
          GETCHARINCTEST(fc, Feptr);
2366
1.01M
          if (!PRIV(xclass)(fc, Lxclass_data,
2367
1.01M
              (const uint8_t*)mb->start_code, utf))
2368
256k
            RRETURN(MATCH_NOMATCH);
2369
1.01M
          }
2370
350k
        PCRE2_UNREACHABLE(); /* Control never reaches here */
2371
350k
        }
2372
2373
      /* If maximizing, find the longest possible run, then work backwards. */
2374
2375
175k
      else
2376
175k
        {
2377
175k
        Lstart_eptr = Feptr;
2378
2.46M
        for (i = Lmin; i < Lmax; i++)
2379
2.43M
          {
2380
2.43M
          int len = 1;
2381
2.43M
          if (Feptr >= mb->end_subject)
2382
26.5k
            {
2383
26.5k
            SCHECK_PARTIAL();
2384
26.4k
            break;
2385
26.5k
            }
2386
2.40M
#ifdef SUPPORT_UNICODE
2387
2.40M
          GETCHARLENTEST(fc, Feptr, len);
2388
#else
2389
          fc = *Feptr;
2390
#endif
2391
2.40M
          if (!PRIV(xclass)(fc, Lxclass_data,
2392
2.40M
              (const uint8_t*)mb->start_code, utf)) break;
2393
2.28M
          Feptr += len;
2394
2.28M
          }
2395
2396
175k
        if (reptype == REPTYPE_POS) continue;    /* No backtracking */
2397
2398
        /* After \C in UTF mode, Lstart_eptr might be in the middle of a
2399
        Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't
2400
        go too far. */
2401
2402
50.1k
        for(;;)
2403
243k
          {
2404
243k
          RMATCH(Fecode, RM101);
2405
241k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2406
234k
          if (Feptr-- <= Lstart_eptr) break;  /* Tried at original position */
2407
193k
#ifdef SUPPORT_UNICODE
2408
193k
          if (utf) BACKCHAR(Feptr);
2409
193k
#endif
2410
193k
          }
2411
41.0k
        RRETURN(MATCH_NOMATCH);
2412
41.0k
        }
2413
2414
525k
      PCRE2_UNREACHABLE(); /* Control never reaches here */
2415
525k
      }
2416
0
#endif  /* SUPPORT_WIDE_CHARS: end of XCLASS */
2417
2418
0
#undef Lstart_eptr
2419
0
#undef Lxclass_data
2420
0
#undef Lmin
2421
0
#undef Lmax
2422
2423
2424
    /* ===================================================================== */
2425
    /* Match a complex, set-based character class. This opcodes are used when
2426
    there is complex nesting or logical operations within the character
2427
    class. */
2428
2429
129k
#define Lstart_eptr  F->fields.eclass_repeat.start_eptr
2430
8.15M
#define Leclass_data F->fields.eclass_repeat.eclass_data
2431
4.07M
#define Leclass_len  F->fields.eclass_repeat.eclass_len
2432
3.98M
#define Lmin         F->fields.eclass_repeat.min
2433
3.94M
#define Lmax         F->fields.eclass_repeat.max
2434
2435
0
#ifdef SUPPORT_WIDE_CHARS
2436
1.07M
    case OP_ECLASS:
2437
1.07M
      {
2438
1.07M
      Leclass_data = Fecode + 1 + LINK_SIZE;  /* Save for matching */
2439
1.07M
      Fecode += GET(Fecode, 1);               /* Advance past the item */
2440
1.07M
      Leclass_len = (PCRE2_SIZE)(Fecode - Leclass_data);
2441
2442
1.07M
      switch (*Fecode)
2443
1.07M
        {
2444
11.3k
        case OP_CRSTAR:
2445
418k
        case OP_CRMINSTAR:
2446
419k
        case OP_CRPLUS:
2447
423k
        case OP_CRMINPLUS:
2448
427k
        case OP_CRQUERY:
2449
427k
        case OP_CRMINQUERY:
2450
450k
        case OP_CRPOSSTAR:
2451
454k
        case OP_CRPOSPLUS:
2452
461k
        case OP_CRPOSQUERY:
2453
461k
        fc = *Fecode++ - OP_CRSTAR;
2454
461k
        Lmin = rep_min[fc];
2455
461k
        Lmax = rep_max[fc];
2456
461k
        reptype = rep_typ[fc];
2457
461k
        break;
2458
2459
2.21k
        case OP_CRRANGE:
2460
4.27k
        case OP_CRMINRANGE:
2461
15.5k
        case OP_CRPOSRANGE:
2462
15.5k
        Lmin = GET2(Fecode, 1);
2463
15.5k
        Lmax = GET2(Fecode, 1 + IMM2_SIZE);
2464
15.5k
        if (Lmax == 0) Lmax = UINT32_MAX;  /* Max 0 => infinity */
2465
15.5k
        reptype = rep_typ[*Fecode - OP_CRSTAR];
2466
15.5k
        Fecode += 1 + 2 * IMM2_SIZE;
2467
15.5k
        break;
2468
2469
597k
        default:               /* No repeat follows */
2470
597k
        Lmin = Lmax = 1;
2471
597k
        break;
2472
1.07M
        }
2473
2474
      /* First, ensure the minimum number of matches are present. */
2475
2476
1.30M
      for (i = 1; i <= Lmin; i++)
2477
737k
        {
2478
737k
        if (Feptr >= mb->end_subject)
2479
2.52k
          {
2480
2.52k
          SCHECK_PARTIAL();
2481
2.52k
          RRETURN(MATCH_NOMATCH);
2482
2.52k
          }
2483
734k
        GETCHARINCTEST(fc, Feptr);
2484
734k
        if (!PRIV(eclass)(fc, Leclass_data, Leclass_data + Leclass_len,
2485
734k
                          (const uint8_t*)mb->start_code, utf))
2486
499k
          RRETURN(MATCH_NOMATCH);
2487
734k
        }
2488
2489
      /* If Lmax == Lmin we can just continue with the main loop. */
2490
2491
572k
      if (Lmin == Lmax) continue;
2492
2493
      /* If minimizing, keep testing the rest of the expression and advancing
2494
      the pointer while it matches the class. */
2495
2496
457k
      if (reptype == REPTYPE_MIN)
2497
409k
        {
2498
409k
        for (;;)
2499
1.11M
          {
2500
1.11M
          RMATCH(Fecode, RM102);
2501
1.11M
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2502
978k
          if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
2503
978k
          if (Feptr >= mb->end_subject)
2504
2.64k
            {
2505
2.64k
            SCHECK_PARTIAL();
2506
2.64k
            RRETURN(MATCH_NOMATCH);
2507
2.64k
            }
2508
975k
          GETCHARINCTEST(fc, Feptr);
2509
975k
          if (!PRIV(eclass)(fc, Leclass_data, Leclass_data + Leclass_len,
2510
975k
                            (const uint8_t*)mb->start_code, utf))
2511
266k
            RRETURN(MATCH_NOMATCH);
2512
975k
          }
2513
409k
        PCRE2_UNREACHABLE(); /* Control never reaches here */
2514
409k
        }
2515
2516
      /* If maximizing, find the longest possible run, then work backwards. */
2517
2518
47.5k
      else
2519
47.5k
        {
2520
47.5k
        Lstart_eptr = Feptr;
2521
1.30M
        for (i = Lmin; i < Lmax; i++)
2522
1.30M
          {
2523
1.30M
          int len = 1;
2524
1.30M
          if (Feptr >= mb->end_subject)
2525
8.82k
            {
2526
8.82k
            SCHECK_PARTIAL();
2527
8.80k
            break;
2528
8.82k
            }
2529
1.29M
#ifdef SUPPORT_UNICODE
2530
1.29M
          GETCHARLENTEST(fc, Feptr, len);
2531
#else
2532
          fc = *Feptr;
2533
#endif
2534
1.29M
          if (!PRIV(eclass)(fc, Leclass_data, Leclass_data + Leclass_len,
2535
1.29M
                            (const uint8_t*)mb->start_code, utf))
2536
35.9k
            break;
2537
1.25M
          Feptr += len;
2538
1.25M
          }
2539
2540
47.4k
        if (reptype == REPTYPE_POS) continue;    /* No backtracking */
2541
2542
        /* After \C in UTF mode, Lstart_eptr might be in the middle of a
2543
        Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't
2544
        go too far. */
2545
2546
15.7k
        for(;;)
2547
84.5k
          {
2548
84.5k
          RMATCH(Fecode, RM103);
2549
83.3k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2550
81.9k
          if (Feptr-- <= Lstart_eptr) break;  /* Tried at original position */
2551
68.7k
#ifdef SUPPORT_UNICODE
2552
68.7k
          if (utf) BACKCHAR(Feptr);
2553
68.7k
#endif
2554
68.7k
          }
2555
13.1k
        RRETURN(MATCH_NOMATCH);
2556
13.1k
        }
2557
2558
457k
      PCRE2_UNREACHABLE(); /* Control never reaches here */
2559
457k
      }
2560
0
#endif  /* SUPPORT_WIDE_CHARS: end of ECLASS */
2561
2562
0
#undef Lstart_eptr
2563
0
#undef Leclass_data
2564
0
#undef Leclass_len
2565
0
#undef Lmin
2566
0
#undef Lmax
2567
2568
2569
    /* ===================================================================== */
2570
    /* Match various character types when PCRE2_UCP is not set. These opcodes
2571
    are not generated when PCRE2_UCP is set - instead appropriate property
2572
    tests are compiled. */
2573
2574
642k
    case OP_NOT_DIGIT:
2575
642k
    if (Feptr >= mb->end_subject)
2576
5.25k
      {
2577
5.25k
      SCHECK_PARTIAL();
2578
5.24k
      RRETURN(MATCH_NOMATCH);
2579
5.24k
      }
2580
637k
    GETCHARINCTEST(fc, Feptr);
2581
637k
    if (CHMAX_255(fc) && (mb->ctypes[fc] & ctype_digit) != 0)
2582
17.2k
      RRETURN(MATCH_NOMATCH);
2583
620k
    Fecode++;
2584
620k
    break;
2585
2586
425k
    case OP_DIGIT:
2587
425k
    if (Feptr >= mb->end_subject)
2588
8.04k
      {
2589
8.04k
      SCHECK_PARTIAL();
2590
8.01k
      RRETURN(MATCH_NOMATCH);
2591
8.01k
      }
2592
417k
    GETCHARINCTEST(fc, Feptr);
2593
417k
    if (!CHMAX_255(fc) || (mb->ctypes[fc] & ctype_digit) == 0)
2594
367k
      RRETURN(MATCH_NOMATCH);
2595
50.5k
    Fecode++;
2596
50.5k
    break;
2597
2598
574k
    case OP_NOT_WHITESPACE:
2599
574k
    if (Feptr >= mb->end_subject)
2600
8.62k
      {
2601
8.62k
      SCHECK_PARTIAL();
2602
8.59k
      RRETURN(MATCH_NOMATCH);
2603
8.59k
      }
2604
565k
    GETCHARINCTEST(fc, Feptr);
2605
565k
    if (CHMAX_255(fc) && (mb->ctypes[fc] & ctype_space) != 0)
2606
11.3k
      RRETURN(MATCH_NOMATCH);
2607
554k
    Fecode++;
2608
554k
    break;
2609
2610
939k
    case OP_WHITESPACE:
2611
939k
    if (Feptr >= mb->end_subject)
2612
17.6k
      {
2613
17.6k
      SCHECK_PARTIAL();
2614
17.6k
      RRETURN(MATCH_NOMATCH);
2615
17.6k
      }
2616
922k
    GETCHARINCTEST(fc, Feptr);
2617
922k
    if (!CHMAX_255(fc) || (mb->ctypes[fc] & ctype_space) == 0)
2618
882k
      RRETURN(MATCH_NOMATCH);
2619
39.3k
    Fecode++;
2620
39.3k
    break;
2621
2622
254k
    case OP_NOT_WORDCHAR:
2623
254k
    if (Feptr >= mb->end_subject)
2624
5.77k
      {
2625
5.77k
      SCHECK_PARTIAL();
2626
5.75k
      RRETURN(MATCH_NOMATCH);
2627
5.75k
      }
2628
248k
    GETCHARINCTEST(fc, Feptr);
2629
248k
    if (CHMAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0)
2630
62.7k
      RRETURN(MATCH_NOMATCH);
2631
185k
    Fecode++;
2632
185k
    break;
2633
2634
473k
    case OP_WORDCHAR:
2635
473k
    if (Feptr >= mb->end_subject)
2636
44.8k
      {
2637
44.8k
      SCHECK_PARTIAL();
2638
44.7k
      RRETURN(MATCH_NOMATCH);
2639
44.7k
      }
2640
428k
    GETCHARINCTEST(fc, Feptr);
2641
428k
    if (!CHMAX_255(fc) || (mb->ctypes[fc] & ctype_word) == 0)
2642
375k
      RRETURN(MATCH_NOMATCH);
2643
53.1k
    Fecode++;
2644
53.1k
    break;
2645
2646
373k
    case OP_ANYNL:
2647
373k
    if (Feptr >= mb->end_subject)
2648
8.84k
      {
2649
8.84k
      SCHECK_PARTIAL();
2650
8.82k
      RRETURN(MATCH_NOMATCH);
2651
8.82k
      }
2652
364k
    GETCHARINCTEST(fc, Feptr);
2653
364k
    switch(fc)
2654
364k
      {
2655
315k
      default: RRETURN(MATCH_NOMATCH);
2656
2657
35.8k
      case CHAR_CR:
2658
35.8k
      if (Feptr >= mb->end_subject)
2659
25.4k
        {
2660
25.4k
        SCHECK_PARTIAL();
2661
25.4k
        }
2662
10.4k
      else if (*Feptr == CHAR_LF) Feptr++;
2663
35.8k
      break;
2664
2665
35.8k
      case CHAR_LF:
2666
4.42k
      break;
2667
2668
3.06k
      case CHAR_VT:
2669
4.44k
      case CHAR_FF:
2670
5.34k
      case CHAR_NEL:
2671
5.34k
#ifndef EBCDIC
2672
5.87k
      case 0x2028:
2673
8.85k
      case 0x2029:
2674
8.85k
#endif  /* Not EBCDIC */
2675
8.85k
      if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) RRETURN(MATCH_NOMATCH);
2676
8.85k
      break;
2677
364k
      }
2678
49.1k
    Fecode++;
2679
49.1k
    break;
2680
2681
1.55M
    case OP_NOT_HSPACE:
2682
1.55M
    if (Feptr >= mb->end_subject)
2683
15.1k
      {
2684
15.1k
      SCHECK_PARTIAL();
2685
15.1k
      RRETURN(MATCH_NOMATCH);
2686
15.1k
      }
2687
1.53M
    GETCHARINCTEST(fc, Feptr);
2688
1.53M
    switch(fc)
2689
1.53M
      {
2690
708k
      HSPACE_CASES: RRETURN(MATCH_NOMATCH);  /* Byte and multibyte cases */
2691
1.48M
      default: break;
2692
1.53M
      }
2693
1.48M
    Fecode++;
2694
1.48M
    break;
2695
2696
740k
    case OP_HSPACE:
2697
740k
    if (Feptr >= mb->end_subject)
2698
33.0k
      {
2699
33.0k
      SCHECK_PARTIAL();
2700
33.0k
      RRETURN(MATCH_NOMATCH);
2701
33.0k
      }
2702
707k
    GETCHARINCTEST(fc, Feptr);
2703
707k
    switch(fc)
2704
707k
      {
2705
51.8k
      HSPACE_CASES: break;  /* Byte and multibyte cases */
2706
655k
      default: RRETURN(MATCH_NOMATCH);
2707
707k
      }
2708
51.8k
    Fecode++;
2709
51.8k
    break;
2710
2711
309k
    case OP_NOT_VSPACE:
2712
309k
    if (Feptr >= mb->end_subject)
2713
9.78k
      {
2714
9.78k
      SCHECK_PARTIAL();
2715
9.74k
      RRETURN(MATCH_NOMATCH);
2716
9.74k
      }
2717
300k
    GETCHARINCTEST(fc, Feptr);
2718
300k
    switch(fc)
2719
300k
      {
2720
70.5k
      VSPACE_CASES: RRETURN(MATCH_NOMATCH);
2721
283k
      default: break;
2722
300k
      }
2723
283k
    Fecode++;
2724
283k
    break;
2725
2726
571k
    case OP_VSPACE:
2727
571k
    if (Feptr >= mb->end_subject)
2728
7.53k
      {
2729
7.53k
      SCHECK_PARTIAL();
2730
7.51k
      RRETURN(MATCH_NOMATCH);
2731
7.51k
      }
2732
563k
    GETCHARINCTEST(fc, Feptr);
2733
563k
    switch(fc)
2734
563k
      {
2735
22.4k
      VSPACE_CASES: break;
2736
541k
      default: RRETURN(MATCH_NOMATCH);
2737
563k
      }
2738
22.4k
    Fecode++;
2739
22.4k
    break;
2740
2741
2742
0
#ifdef SUPPORT_UNICODE
2743
2744
    /* ===================================================================== */
2745
    /* Check the next character by Unicode property. We will get here only
2746
    if the support is in the binary; otherwise a compile-time error occurs. */
2747
2748
1.42M
    case OP_PROP:
2749
2.65M
    case OP_NOTPROP:
2750
2.65M
    if (Feptr >= mb->end_subject)
2751
71.9k
      {
2752
71.9k
      SCHECK_PARTIAL();
2753
71.9k
      RRETURN(MATCH_NOMATCH);
2754
71.9k
      }
2755
2.58M
    GETCHARINCTEST(fc, Feptr);
2756
2.58M
      {
2757
2.58M
      const uint32_t *cp;
2758
2.58M
      uint32_t chartype;
2759
2.58M
      const ucd_record *prop = GET_UCD(fc);
2760
2.58M
      BOOL notmatch = Fop == OP_NOTPROP;
2761
2762
2.58M
      switch(Fecode[1])
2763
2.58M
        {
2764
159k
        case PT_LAMP:
2765
159k
        chartype = prop->chartype;
2766
159k
        if ((chartype == ucp_Lu ||
2767
129k
             chartype == ucp_Ll ||
2768
106k
             chartype == ucp_Lt) == notmatch)
2769
53.6k
          RRETURN(MATCH_NOMATCH);
2770
105k
        break;
2771
2772
105k
        case PT_GC:
2773
71.8k
        if ((Fecode[2] == PRIV(ucp_gentype)[prop->chartype]) == notmatch)
2774
20.3k
          RRETURN(MATCH_NOMATCH);
2775
51.5k
        break;
2776
2777
419k
        case PT_PC:
2778
419k
        if ((Fecode[2] == prop->chartype) == notmatch)
2779
62.6k
          RRETURN(MATCH_NOMATCH);
2780
357k
        break;
2781
2782
357k
        case PT_SC:
2783
13.6k
        if ((Fecode[2] == prop->script) == notmatch)
2784
2.88k
          RRETURN(MATCH_NOMATCH);
2785
10.7k
        break;
2786
2787
32.8k
        case PT_SCX:
2788
32.8k
          {
2789
32.8k
          BOOL ok = (Fecode[2] == prop->script ||
2790
32.1k
                     MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Fecode[2]) != 0);
2791
32.8k
          if (ok == notmatch) RRETURN(MATCH_NOMATCH);
2792
32.8k
          }
2793
30.8k
        break;
2794
2795
        /* These are specials */
2796
2797
30.8k
        case PT_ALNUM:
2798
22.5k
        chartype = prop->chartype;
2799
22.5k
        if ((PRIV(ucp_gentype)[chartype] == ucp_L ||
2800
12.3k
             PRIV(ucp_gentype)[chartype] == ucp_N) == notmatch)
2801
10.9k
          RRETURN(MATCH_NOMATCH);
2802
11.5k
        break;
2803
2804
        /* Perl space used to exclude VT, but from Perl 5.18 it is included,
2805
        which means that Perl space and POSIX space are now identical. PCRE
2806
        was changed at release 8.34. */
2807
2808
691k
        case PT_SPACE:    /* Perl space */
2809
692k
        case PT_PXSPACE:  /* POSIX space */
2810
692k
        switch(fc)
2811
692k
          {
2812
432k
          HSPACE_CASES:
2813
432k
          VSPACE_CASES:
2814
370k
          if (notmatch) RRETURN(MATCH_NOMATCH);
2815
46.4k
          break;
2816
2817
629k
          default:
2818
629k
          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == notmatch)
2819
393k
            RRETURN(MATCH_NOMATCH);
2820
235k
          break;
2821
692k
          }
2822
282k
        break;
2823
2824
472k
        case PT_WORD:
2825
472k
        chartype = prop->chartype;
2826
472k
        if ((PRIV(ucp_gentype)[chartype] == ucp_L ||
2827
342k
             PRIV(ucp_gentype)[chartype] == ucp_N ||
2828
318k
             chartype == ucp_Mn ||
2829
316k
             chartype == ucp_Pc) == notmatch)
2830
289k
          RRETURN(MATCH_NOMATCH);
2831
182k
        break;
2832
2833
450k
        case PT_CLIST:
2834
#if PCRE2_CODE_UNIT_WIDTH == 32
2835
            if (fc > MAX_UTF_CODE_POINT)
2836
              {
2837
              if (notmatch) break;;
2838
              RRETURN(MATCH_NOMATCH);
2839
              }
2840
#endif
2841
450k
        cp = PRIV(ucd_caseless_sets) + Fecode[2];
2842
450k
        for (;;)
2843
784k
          {
2844
784k
          if (fc < *cp)
2845
416k
            { if (notmatch) break; else { RRETURN(MATCH_NOMATCH); } }
2846
367k
          if (fc == *cp++)
2847
34.2k
            { if (notmatch) { RRETURN(MATCH_NOMATCH); } else break; }
2848
367k
          }
2849
38.6k
        break;
2850
2851
191k
        case PT_UCNC:
2852
191k
        if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT ||
2853
189k
             fc == CHAR_GRAVE_ACCENT || (fc >= 0xa0 && fc <= 0xd7ff) ||
2854
142k
             fc >= 0xe000) == notmatch)
2855
52.3k
          RRETURN(MATCH_NOMATCH);
2856
139k
        break;
2857
2858
139k
        case PT_BIDICL:
2859
24.6k
        if ((UCD_BIDICLASS_PROP(prop) == Fecode[2]) == notmatch)
2860
2.23k
          RRETURN(MATCH_NOMATCH);
2861
22.4k
        break;
2862
2863
30.5k
        case PT_BOOL:
2864
30.5k
          {
2865
30.5k
          BOOL ok = MAPBIT(PRIV(ucd_boolprop_sets) +
2866
30.5k
            UCD_BPROPS_PROP(prop), Fecode[2]) != 0;
2867
30.5k
          if (ok == notmatch) RRETURN(MATCH_NOMATCH);
2868
30.5k
          }
2869
29.9k
        break;
2870
2871
        /* This should never occur */
2872
2873
        /* LCOV_EXCL_START */
2874
29.9k
        default:
2875
0
        PCRE2_DEBUG_UNREACHABLE();
2876
0
        return PCRE2_ERROR_INTERNAL;
2877
        /* LCOV_EXCL_STOP */
2878
2.58M
        }
2879
2880
1.26M
      Fecode += 3;
2881
1.26M
      }
2882
0
    break;
2883
2884
2885
    /* ===================================================================== */
2886
    /* Match an extended Unicode sequence. We will get here only if the support
2887
    is in the binary; otherwise a compile-time error occurs. */
2888
2889
173k
    case OP_EXTUNI:
2890
173k
    if (Feptr >= mb->end_subject)
2891
4.06k
      {
2892
4.06k
      SCHECK_PARTIAL();
2893
4.05k
      RRETURN(MATCH_NOMATCH);
2894
4.05k
      }
2895
169k
    else
2896
169k
      {
2897
169k
      GETCHARINCTEST(fc, Feptr);
2898
169k
      Feptr = PRIV(extuni)(fc, Feptr, mb->check_subject, mb->end_subject, utf,
2899
169k
        NULL);
2900
169k
      }
2901
169k
    CHECK_PARTIAL();
2902
169k
    Fecode++;
2903
169k
    break;
2904
2905
0
#endif  /* SUPPORT_UNICODE */
2906
2907
2908
    /* ===================================================================== */
2909
    /* Match a single character type repeatedly. Note that the property type
2910
    does not need to be in a stack frame as it is not used within an RMATCH()
2911
    loop. */
2912
2913
24.7M
#define Lstart_eptr  F->fields.type_repeat.start_eptr
2914
68.7M
#define Lmin         F->fields.type_repeat.min
2915
130M
#define Lmax         F->fields.type_repeat.max
2916
70.0M
#define Lctype       F->fields.type_repeat.ctype
2917
25.7M
#define Lpropvalue   F->fields.type_repeat.propvalue
2918
2919
1.47M
    case OP_TYPEEXACT:
2920
1.47M
    Lmin = Lmax = GET2(Fecode, 1);
2921
1.47M
    Fecode += 1 + IMM2_SIZE;
2922
1.47M
    goto REPEATTYPE;
2923
2924
227k
    case OP_TYPEUPTO:
2925
393k
    case OP_TYPEMINUPTO:
2926
393k
    Lmin = 0;
2927
393k
    Lmax = GET2(Fecode, 1);
2928
393k
    reptype = (*Fecode == OP_TYPEMINUPTO)? REPTYPE_MIN : REPTYPE_MAX;
2929
393k
    Fecode += 1 + IMM2_SIZE;
2930
393k
    goto REPEATTYPE;
2931
2932
2.13M
    case OP_TYPEPOSSTAR:
2933
2.13M
    reptype = REPTYPE_POS;
2934
2.13M
    Lmin = 0;
2935
2.13M
    Lmax = UINT32_MAX;
2936
2.13M
    Fecode++;
2937
2.13M
    goto REPEATTYPE;
2938
2939
2.25M
    case OP_TYPEPOSPLUS:
2940
2.25M
    reptype = REPTYPE_POS;
2941
2.25M
    Lmin = 1;
2942
2.25M
    Lmax = UINT32_MAX;
2943
2.25M
    Fecode++;
2944
2.25M
    goto REPEATTYPE;
2945
2946
1.31M
    case OP_TYPEPOSQUERY:
2947
1.31M
    reptype = REPTYPE_POS;
2948
1.31M
    Lmin = 0;
2949
1.31M
    Lmax = 1;
2950
1.31M
    Fecode++;
2951
1.31M
    goto REPEATTYPE;
2952
2953
130k
    case OP_TYPEPOSUPTO:
2954
130k
    reptype = REPTYPE_POS;
2955
130k
    Lmin = 0;
2956
130k
    Lmax = GET2(Fecode, 1);
2957
130k
    Fecode += 1 + IMM2_SIZE;
2958
130k
    goto REPEATTYPE;
2959
2960
915k
    case OP_TYPESTAR:
2961
1.54M
    case OP_TYPEMINSTAR:
2962
2.23M
    case OP_TYPEPLUS:
2963
2.69M
    case OP_TYPEMINPLUS:
2964
3.73M
    case OP_TYPEQUERY:
2965
4.37M
    case OP_TYPEMINQUERY:
2966
4.37M
    fc = *Fecode++ - OP_TYPESTAR;
2967
4.37M
    Lmin = rep_min[fc];
2968
4.37M
    Lmax = rep_max[fc];
2969
4.37M
    reptype = rep_typ[fc];
2970
2971
    /* Common code for all repeated character type matches. */
2972
2973
12.0M
    REPEATTYPE:
2974
12.0M
    Lctype = *Fecode++;      /* Code for the character type */
2975
2976
12.0M
#ifdef SUPPORT_UNICODE
2977
12.0M
    if (Lctype == OP_PROP || Lctype == OP_NOTPROP)
2978
4.39M
      {
2979
4.39M
      proptype = *Fecode++;
2980
4.39M
      Lpropvalue = *Fecode++;
2981
4.39M
      }
2982
7.68M
    else proptype = -1;
2983
12.0M
#endif
2984
2985
    /* First, ensure the minimum number of matches are present. Use inline
2986
    code for maximizing the speed, and do the type test once at the start
2987
    (i.e. keep it out of the loops). As there are no calls to RMATCH in the
2988
    loops, we can use an ordinary variable for "notmatch". The code for UTF
2989
    mode is separated out for tidiness, except for Unicode property tests. */
2990
2991
12.0M
    if (Lmin > 0)
2992
4.88M
      {
2993
4.88M
#ifdef SUPPORT_UNICODE
2994
4.88M
      if (proptype >= 0)  /* Property tests in all modes */
2995
1.63M
        {
2996
1.63M
        BOOL notmatch = Lctype == OP_NOTPROP;
2997
1.63M
        switch(proptype)
2998
1.63M
          {
2999
86.9k
          case PT_LAMP:
3000
150k
          for (i = 1; i <= Lmin; i++)
3001
94.4k
            {
3002
94.4k
            int chartype;
3003
94.4k
            if (Feptr >= mb->end_subject)
3004
4.41k
              {
3005
4.41k
              SCHECK_PARTIAL();
3006
4.39k
              RRETURN(MATCH_NOMATCH);
3007
4.39k
              }
3008
90.0k
            GETCHARINCTEST(fc, Feptr);
3009
90.0k
            chartype = UCD_CHARTYPE(fc);
3010
90.0k
            if ((chartype == ucp_Lu ||
3011
79.0k
                 chartype == ucp_Ll ||
3012
72.1k
                 chartype == ucp_Lt) == notmatch)
3013
26.4k
              RRETURN(MATCH_NOMATCH);
3014
90.0k
            }
3015
56.0k
          break;
3016
3017
89.2k
          case PT_GC:
3018
206k
          for (i = 1; i <= Lmin; i++)
3019
142k
            {
3020
142k
            if (Feptr >= mb->end_subject)
3021
2.33k
              {
3022
2.33k
              SCHECK_PARTIAL();
3023
2.32k
              RRETURN(MATCH_NOMATCH);
3024
2.32k
              }
3025
140k
            GETCHARINCTEST(fc, Feptr);
3026
140k
            if ((UCD_CATEGORY(fc) == Lpropvalue) == notmatch)
3027
22.9k
              RRETURN(MATCH_NOMATCH);
3028
140k
            }
3029
63.9k
          break;
3030
3031
461k
          case PT_PC:
3032
853k
          for (i = 1; i <= Lmin; i++)
3033
477k
            {
3034
477k
            if (Feptr >= mb->end_subject)
3035
20.6k
              {
3036
20.6k
              SCHECK_PARTIAL();
3037
20.6k
              RRETURN(MATCH_NOMATCH);
3038
20.6k
              }
3039
456k
            GETCHARINCTEST(fc, Feptr);
3040
456k
            if ((UCD_CHARTYPE(fc) == Lpropvalue) == notmatch)
3041
64.7k
              RRETURN(MATCH_NOMATCH);
3042
456k
            }
3043
375k
          break;
3044
3045
375k
          case PT_SC:
3046
52.2k
          for (i = 1; i <= Lmin; i++)
3047
47.9k
            {
3048
47.9k
            if (Feptr >= mb->end_subject)
3049
2.12k
              {
3050
2.12k
              SCHECK_PARTIAL();
3051
2.11k
              RRETURN(MATCH_NOMATCH);
3052
2.11k
              }
3053
45.7k
            GETCHARINCTEST(fc, Feptr);
3054
45.7k
            if ((UCD_SCRIPT(fc) == Lpropvalue) == notmatch)
3055
5.88k
              RRETURN(MATCH_NOMATCH);
3056
45.7k
            }
3057
4.38k
          break;
3058
3059
60.0k
          case PT_SCX:
3060
706k
          for (i = 1; i <= Lmin; i++)
3061
686k
            {
3062
686k
            BOOL ok;
3063
686k
            const ucd_record *prop;
3064
686k
            if (Feptr >= mb->end_subject)
3065
21.4k
              {
3066
21.4k
              SCHECK_PARTIAL();
3067
21.4k
              RRETURN(MATCH_NOMATCH);
3068
21.4k
              }
3069
664k
            GETCHARINCTEST(fc, Feptr);
3070
664k
            prop = GET_UCD(fc);
3071
664k
            ok = (prop->script == Lpropvalue ||
3072
651k
                  MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0);
3073
664k
            if (ok == notmatch)
3074
17.9k
              RRETURN(MATCH_NOMATCH);
3075
664k
            }
3076
20.5k
          break;
3077
3078
167k
          case PT_ALNUM:
3079
279k
          for (i = 1; i <= Lmin; i++)
3080
168k
            {
3081
168k
            int category;
3082
168k
            if (Feptr >= mb->end_subject)
3083
3.65k
              {
3084
3.65k
              SCHECK_PARTIAL();
3085
3.63k
              RRETURN(MATCH_NOMATCH);
3086
3.63k
              }
3087
164k
            GETCHARINCTEST(fc, Feptr);
3088
164k
            category = UCD_CATEGORY(fc);
3089
164k
            if ((category == ucp_L || category == ucp_N) == notmatch)
3090
52.5k
              RRETURN(MATCH_NOMATCH);
3091
164k
            }
3092
111k
          break;
3093
3094
          /* Perl space used to exclude VT, but from Perl 5.18 it is included,
3095
          which means that Perl space and POSIX space are now identical. PCRE
3096
          was changed at release 8.34. */
3097
3098
365k
          case PT_SPACE:    /* Perl space */
3099
366k
          case PT_PXSPACE:  /* POSIX space */
3100
916k
          for (i = 1; i <= Lmin; i++)
3101
794k
            {
3102
794k
            if (Feptr >= mb->end_subject)
3103
7.57k
              {
3104
7.57k
              SCHECK_PARTIAL();
3105
7.53k
              RRETURN(MATCH_NOMATCH);
3106
7.53k
              }
3107
786k
            GETCHARINCTEST(fc, Feptr);
3108
786k
            switch(fc)
3109
786k
              {
3110
433k
              HSPACE_CASES:
3111
433k
              VSPACE_CASES:
3112
341k
              if (notmatch) RRETURN(MATCH_NOMATCH);
3113
22.4k
              break;
3114
3115
730k
              default:
3116
730k
              if ((UCD_CATEGORY(fc) == ucp_Z) == notmatch)
3117
203k
                RRETURN(MATCH_NOMATCH);
3118
527k
              break;
3119
786k
              }
3120
786k
            }
3121
122k
          break;
3122
3123
122k
          case PT_WORD:
3124
178k
          for (i = 1; i <= Lmin; i++)
3125
140k
            {
3126
140k
            int chartype, category;
3127
140k
            if (Feptr >= mb->end_subject)
3128
7.17k
              {
3129
7.17k
              SCHECK_PARTIAL();
3130
7.16k
              RRETURN(MATCH_NOMATCH);
3131
7.16k
              }
3132
133k
            GETCHARINCTEST(fc, Feptr);
3133
133k
            chartype = UCD_CHARTYPE(fc);
3134
133k
            category = PRIV(ucp_gentype)[chartype];
3135
133k
            if ((category == ucp_L || category == ucp_N ||
3136
79.6k
                 chartype == ucp_Mn || chartype == ucp_Pc) == notmatch)
3137
65.8k
              RRETURN(MATCH_NOMATCH);
3138
133k
            }
3139
38.5k
          break;
3140
3141
79.9k
          case PT_CLIST:
3142
118k
          for (i = 1; i <= Lmin; i++)
3143
108k
            {
3144
108k
            const uint32_t *cp;
3145
108k
            if (Feptr >= mb->end_subject)
3146
2.12k
              {
3147
2.12k
              SCHECK_PARTIAL();
3148
2.11k
              RRETURN(MATCH_NOMATCH);
3149
2.11k
              }
3150
106k
            GETCHARINCTEST(fc, Feptr);
3151
#if PCRE2_CODE_UNIT_WIDTH == 32
3152
            if (fc > MAX_UTF_CODE_POINT)
3153
              {
3154
              if (notmatch) continue;
3155
              RRETURN(MATCH_NOMATCH);
3156
              }
3157
#endif
3158
106k
            cp = PRIV(ucd_caseless_sets) + Lpropvalue;
3159
106k
            for (;;)
3160
179k
              {
3161
179k
              if (fc < *cp)
3162
101k
                {
3163
101k
                if (notmatch) break;
3164
66.4k
                RRETURN(MATCH_NOMATCH);
3165
66.4k
                }
3166
78.3k
              if (fc == *cp++)
3167
5.15k
                {
3168
5.15k
                if (notmatch) RRETURN(MATCH_NOMATCH);
3169
3.52k
                break;
3170
5.15k
                }
3171
78.3k
              }
3172
106k
            }
3173
9.73k
          break;
3174
3175
88.2k
          case PT_UCNC:
3176
296k
          for (i = 1; i <= Lmin; i++)
3177
241k
            {
3178
241k
            if (Feptr >= mb->end_subject)
3179
3.65k
              {
3180
3.65k
              SCHECK_PARTIAL();
3181
3.62k
              RRETURN(MATCH_NOMATCH);
3182
3.62k
              }
3183
237k
            GETCHARINCTEST(fc, Feptr);
3184
237k
            if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT ||
3185
235k
                 fc == CHAR_GRAVE_ACCENT || (fc >= 0xa0 && fc <= 0xd7ff) ||
3186
206k
                 fc >= 0xe000) == notmatch)
3187
28.9k
              RRETURN(MATCH_NOMATCH);
3188
237k
            }
3189
55.5k
          break;
3190
3191
65.4k
          case PT_BIDICL:
3192
1.75M
          for (i = 1; i <= Lmin; i++)
3193
1.71M
            {
3194
1.71M
            if (Feptr >= mb->end_subject)
3195
7.95k
              {
3196
7.95k
              SCHECK_PARTIAL();
3197
7.94k
              RRETURN(MATCH_NOMATCH);
3198
7.94k
              }
3199
1.70M
            GETCHARINCTEST(fc, Feptr);
3200
1.70M
            if ((UCD_BIDICLASS(fc) == Lpropvalue) == notmatch)
3201
16.2k
              RRETURN(MATCH_NOMATCH);
3202
1.70M
            }
3203
41.2k
          break;
3204
3205
48.7k
          case PT_BOOL:
3206
337k
          for (i = 1; i <= Lmin; i++)
3207
309k
            {
3208
309k
            BOOL ok;
3209
309k
            const ucd_record *prop;
3210
309k
            if (Feptr >= mb->end_subject)
3211
4.57k
              {
3212
4.57k
              SCHECK_PARTIAL();
3213
4.56k
              RRETURN(MATCH_NOMATCH);
3214
4.56k
              }
3215
305k
            GETCHARINCTEST(fc, Feptr);
3216
305k
            prop = GET_UCD(fc);
3217
305k
            ok = MAPBIT(PRIV(ucd_boolprop_sets) +
3218
305k
              UCD_BPROPS_PROP(prop), Lpropvalue) != 0;
3219
305k
            if (ok == notmatch)
3220
16.9k
              RRETURN(MATCH_NOMATCH);
3221
305k
            }
3222
27.2k
          break;
3223
3224
          /* This should not occur */
3225
3226
          /* LCOV_EXCL_START */
3227
27.2k
          default:
3228
0
          PCRE2_DEBUG_UNREACHABLE();
3229
0
          return PCRE2_ERROR_INTERNAL;
3230
          /* LCOV_EXCL_STOP */
3231
1.63M
          }
3232
1.63M
        }
3233
3234
      /* Match extended Unicode sequences. We will get here only if the
3235
      support is in the binary; otherwise a compile-time error occurs. */
3236
3237
3.24M
      else if (Lctype == OP_EXTUNI)
3238
36.2k
        {
3239
280k
        for (i = 1; i <= Lmin; i++)
3240
251k
          {
3241
251k
          if (Feptr >= mb->end_subject)
3242
7.78k
            {
3243
7.78k
            SCHECK_PARTIAL();
3244
7.77k
            RRETURN(MATCH_NOMATCH);
3245
7.77k
            }
3246
243k
          else
3247
243k
            {
3248
243k
            GETCHARINCTEST(fc, Feptr);
3249
243k
            Feptr = PRIV(extuni)(fc, Feptr, mb->check_subject,
3250
243k
              mb->end_subject, utf, NULL);
3251
243k
            }
3252
243k
          CHECK_PARTIAL();
3253
243k
          }
3254
36.2k
        }
3255
3.20M
      else
3256
3.20M
#endif     /* SUPPORT_UNICODE */
3257
3258
/* Handle all other cases in UTF mode */
3259
3260
3.20M
#ifdef SUPPORT_UNICODE
3261
3.20M
      if (utf) switch(Lctype)
3262
1.07M
        {
3263
55.3k
        case OP_ANY:
3264
457k
        for (i = 1; i <= Lmin; i++)
3265
408k
          {
3266
408k
          if (Feptr >= mb->end_subject)
3267
6.02k
            {
3268
6.02k
            SCHECK_PARTIAL();
3269
6.00k
            RRETURN(MATCH_NOMATCH);
3270
6.00k
            }
3271
402k
          if (IS_NEWLINE(Feptr)) RRETURN(MATCH_NOMATCH);
3272
402k
          if (mb->partial != 0 &&
3273
204k
              Feptr + 1 >= mb->end_subject &&
3274
2.44k
              NLBLOCK->nltype == NLTYPE_FIXED &&
3275
2.44k
              NLBLOCK->nllen == 2 &&
3276
0
              *Feptr == NLBLOCK->nl[0])
3277
0
            {
3278
0
            mb->hitend = TRUE;
3279
0
            if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
3280
0
            }
3281
402k
          Feptr++;
3282
402k
          ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++);
3283
402k
          }
3284
49.0k
        break;
3285
3286
49.0k
        case OP_ALLANY:
3287
288k
        for (i = 1; i <= Lmin; i++)
3288
255k
          {
3289
255k
          if (Feptr >= mb->end_subject)
3290
4.27k
            {
3291
4.27k
            SCHECK_PARTIAL();
3292
4.25k
            RRETURN(MATCH_NOMATCH);
3293
4.25k
            }
3294
250k
          Feptr++;
3295
250k
          ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++);
3296
250k
          }
3297
33.1k
        break;
3298
3299
33.1k
        case OP_ANYBYTE:
3300
0
        if (Feptr > mb->end_subject - Lmin) RRETURN(MATCH_NOMATCH);
3301
0
        Feptr += Lmin;
3302
0
        break;
3303
3304
169k
        case OP_ANYNL:
3305
193k
        for (i = 1; i <= Lmin; i++)
3306
178k
          {
3307
178k
          if (Feptr >= mb->end_subject)
3308
3.88k
            {
3309
3.88k
            SCHECK_PARTIAL();
3310
3.86k
            RRETURN(MATCH_NOMATCH);
3311
3.86k
            }
3312
174k
          GETCHARINC(fc, Feptr);
3313
174k
          switch(fc)
3314
174k
            {
3315
149k
            default: RRETURN(MATCH_NOMATCH);
3316
3317
12.9k
            case CHAR_CR:
3318
12.9k
            if (Feptr < mb->end_subject && *Feptr == CHAR_LF) Feptr++;
3319
12.9k
            break;
3320
3321
2.16k
            case CHAR_LF:
3322
2.16k
            break;
3323
3324
2.11k
            case CHAR_VT:
3325
3.37k
            case CHAR_FF:
3326
3.92k
            case CHAR_NEL:
3327
3.92k
#ifndef EBCDIC
3328
5.53k
            case 0x2028:
3329
9.64k
            case 0x2029:
3330
9.64k
#endif  /* Not EBCDIC */
3331
9.64k
            if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) RRETURN(MATCH_NOMATCH);
3332
9.64k
            break;
3333
174k
            }
3334
174k
          }
3335
15.5k
        break;
3336
3337
135k
        case OP_NOT_HSPACE:
3338
786k
        for (i = 1; i <= Lmin; i++)
3339
700k
          {
3340
700k
          if (Feptr >= mb->end_subject)
3341
15.2k
            {
3342
15.2k
            SCHECK_PARTIAL();
3343
15.1k
            RRETURN(MATCH_NOMATCH);
3344
15.1k
            }
3345
685k
          GETCHARINC(fc, Feptr);
3346
685k
          switch(fc)
3347
685k
            {
3348
320k
            HSPACE_CASES: RRETURN(MATCH_NOMATCH);
3349
650k
            default: break;
3350
685k
            }
3351
685k
          }
3352
85.5k
        break;
3353
3354
292k
        case OP_HSPACE:
3355
311k
        for (i = 1; i <= Lmin; i++)
3356
301k
          {
3357
301k
          if (Feptr >= mb->end_subject)
3358
6.93k
            {
3359
6.93k
            SCHECK_PARTIAL();
3360
6.92k
            RRETURN(MATCH_NOMATCH);
3361
6.92k
            }
3362
294k
          GETCHARINC(fc, Feptr);
3363
294k
          switch(fc)
3364
294k
            {
3365
19.0k
            HSPACE_CASES: break;
3366
275k
            default: RRETURN(MATCH_NOMATCH);
3367
294k
            }
3368
294k
          }
3369
10.5k
        break;
3370
3371
29.1k
        case OP_NOT_VSPACE:
3372
179k
        for (i = 1; i <= Lmin; i++)
3373
161k
          {
3374
161k
          if (Feptr >= mb->end_subject)
3375
4.00k
            {
3376
4.00k
            SCHECK_PARTIAL();
3377
3.98k
            RRETURN(MATCH_NOMATCH);
3378
3.98k
            }
3379
157k
          GETCHARINC(fc, Feptr);
3380
157k
          switch(fc)
3381
157k
            {
3382
30.5k
            VSPACE_CASES: RRETURN(MATCH_NOMATCH);
3383
150k
            default: break;
3384
157k
            }
3385
157k
          }
3386
18.0k
        break;
3387
3388
94.1k
        case OP_VSPACE:
3389
102k
        for (i = 1; i <= Lmin; i++)
3390
95.6k
          {
3391
95.6k
          if (Feptr >= mb->end_subject)
3392
3.80k
            {
3393
3.80k
            SCHECK_PARTIAL();
3394
3.79k
            RRETURN(MATCH_NOMATCH);
3395
3.79k
            }
3396
91.8k
          GETCHARINC(fc, Feptr);
3397
91.8k
          switch(fc)
3398
91.8k
            {
3399
8.08k
            VSPACE_CASES: break;
3400
83.7k
            default: RRETURN(MATCH_NOMATCH);
3401
91.8k
            }
3402
91.8k
          }
3403
6.67k
        break;
3404
3405
12.0k
        case OP_NOT_DIGIT:
3406
42.2k
        for (i = 1; i <= Lmin; i++)
3407
34.2k
          {
3408
34.2k
          if (Feptr >= mb->end_subject)
3409
2.22k
            {
3410
2.22k
            SCHECK_PARTIAL();
3411
2.20k
            RRETURN(MATCH_NOMATCH);
3412
2.20k
            }
3413
32.0k
          GETCHARINC(fc, Feptr);
3414
32.0k
          if (fc < 128 && (mb->ctypes[fc] & ctype_digit) != 0)
3415
1.86k
            RRETURN(MATCH_NOMATCH);
3416
32.0k
          }
3417
7.92k
        break;
3418
3419
128k
        case OP_DIGIT:
3420
193k
        for (i = 1; i <= Lmin; i++)
3421
136k
          {
3422
136k
          uint32_t cc;
3423
136k
          if (Feptr >= mb->end_subject)
3424
13.5k
            {
3425
13.5k
            SCHECK_PARTIAL();
3426
13.5k
            RRETURN(MATCH_NOMATCH);
3427
13.5k
            }
3428
122k
          cc = *Feptr;
3429
122k
          if (cc >= 128 || (mb->ctypes[cc] & ctype_digit) == 0)
3430
58.2k
            RRETURN(MATCH_NOMATCH);
3431
64.3k
          Feptr++;
3432
          /* No need to skip more code units - we know it has only one. */
3433
64.3k
          }
3434
57.0k
        break;
3435
3436
57.0k
        case OP_NOT_WHITESPACE:
3437
236k
        for (i = 1; i <= Lmin; i++)
3438
230k
          {
3439
230k
          uint32_t cc;
3440
230k
          if (Feptr >= mb->end_subject)
3441
2.29k
            {
3442
2.29k
            SCHECK_PARTIAL();
3443
2.26k
            RRETURN(MATCH_NOMATCH);
3444
2.26k
            }
3445
228k
          cc = *Feptr;
3446
228k
          if (cc < 128 && (mb->ctypes[cc] & ctype_space) != 0)
3447
8.64k
            RRETURN(MATCH_NOMATCH);
3448
219k
          Feptr++;
3449
219k
          ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++);
3450
219k
          }
3451
6.10k
        break;
3452
3453
50.6k
        case OP_WHITESPACE:
3454
58.5k
        for (i = 1; i <= Lmin; i++)
3455
54.5k
          {
3456
54.5k
          uint32_t cc;
3457
54.5k
          if (Feptr >= mb->end_subject)
3458
3.06k
            {
3459
3.06k
            SCHECK_PARTIAL();
3460
3.04k
            RRETURN(MATCH_NOMATCH);
3461
3.04k
            }
3462
51.5k
          cc = *Feptr;
3463
51.5k
          if (cc >= 128 || (mb->ctypes[cc] & ctype_space) == 0)
3464
43.6k
            RRETURN(MATCH_NOMATCH);
3465
7.87k
          Feptr++;
3466
          /* No need to skip more code units - we know it has only one. */
3467
7.87k
          }
3468
3.94k
        break;
3469
3470
32.0k
        case OP_NOT_WORDCHAR:
3471
65.2k
        for (i = 1; i <= Lmin; i++)
3472
49.1k
          {
3473
49.1k
          uint32_t cc;
3474
49.1k
          if (Feptr >= mb->end_subject)
3475
2.62k
            {
3476
2.62k
            SCHECK_PARTIAL();
3477
2.60k
            RRETURN(MATCH_NOMATCH);
3478
2.60k
            }
3479
46.5k
          cc = *Feptr;
3480
46.5k
          if (cc < 128 && (mb->ctypes[cc] & ctype_word) != 0)
3481
13.3k
            RRETURN(MATCH_NOMATCH);
3482
33.2k
          Feptr++;
3483
33.2k
          ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++);
3484
33.2k
          }
3485
16.0k
        break;
3486
3487
23.4k
        case OP_WORDCHAR:
3488
30.8k
        for (i = 1; i <= Lmin; i++)
3489
25.4k
          {
3490
25.4k
          uint32_t cc;
3491
25.4k
          if (Feptr >= mb->end_subject)
3492
2.71k
            {
3493
2.71k
            SCHECK_PARTIAL();
3494
2.70k
            RRETURN(MATCH_NOMATCH);
3495
2.70k
            }
3496
22.7k
          cc = *Feptr;
3497
22.7k
          if (cc >= 128 || (mb->ctypes[cc] & ctype_word) == 0)
3498
15.3k
            RRETURN(MATCH_NOMATCH);
3499
7.44k
          Feptr++;
3500
          /* No need to skip more code units - we know it has only one. */
3501
7.44k
          }
3502
5.37k
        break;
3503
3504
        /* LCOV_EXCL_START */
3505
5.37k
        default:
3506
0
        PCRE2_DEBUG_UNREACHABLE();
3507
0
        return PCRE2_ERROR_INTERNAL;
3508
        /* LCOV_EXCL_STOP */
3509
1.07M
        }  /* End switch(Lctype) */
3510
3511
2.12M
      else
3512
2.12M
#endif     /* SUPPORT_UNICODE */
3513
3514
      /* Code for the non-UTF case for minimum matching of operators other
3515
      than OP_PROP and OP_NOTPROP. */
3516
3517
2.12M
      switch(Lctype)
3518
2.12M
        {
3519
51.8k
        case OP_ANY:
3520
2.66M
        for (i = 1; i <= Lmin; i++)
3521
2.63M
          {
3522
2.63M
          if (Feptr >= mb->end_subject)
3523
25.5k
            {
3524
25.5k
            SCHECK_PARTIAL();
3525
25.4k
            RRETURN(MATCH_NOMATCH);
3526
25.4k
            }
3527
2.61M
          if (IS_NEWLINE(Feptr)) RRETURN(MATCH_NOMATCH);
3528
2.60M
          if (mb->partial != 0 &&
3529
781k
              Feptr + 1 >= mb->end_subject &&
3530
8.61k
              NLBLOCK->nltype == NLTYPE_FIXED &&
3531
8.61k
              NLBLOCK->nllen == 2 &&
3532
0
              *Feptr == NLBLOCK->nl[0])
3533
0
            {
3534
0
            mb->hitend = TRUE;
3535
0
            if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
3536
0
            }
3537
2.60M
          Feptr++;
3538
2.60M
          }
3539
21.9k
        break;
3540
3541
25.5k
        case OP_ALLANY:
3542
25.5k
        if (Feptr > mb->end_subject - Lmin)
3543
7.94k
          {
3544
7.94k
          SCHECK_PARTIAL();
3545
7.93k
          RRETURN(MATCH_NOMATCH);
3546
7.93k
          }
3547
17.5k
        Feptr += Lmin;
3548
17.5k
        break;
3549
3550
        /* This OP_ANYBYTE case will never be reached because \C gets turned
3551
        into OP_ALLANY in non-UTF mode. Cut out the code so that coverage
3552
        reports don't complain about it's never being used. */
3553
3554
/*        case OP_ANYBYTE:
3555
*        if (Feptr > mb->end_subject - Lmin)
3556
*          {
3557
*          SCHECK_PARTIAL();
3558
*          RRETURN(MATCH_NOMATCH);
3559
*          }
3560
*        Feptr += Lmin;
3561
*        break;
3562
*/
3563
182k
        case OP_ANYNL:
3564
216k
        for (i = 1; i <= Lmin; i++)
3565
189k
          {
3566
189k
          if (Feptr >= mb->end_subject)
3567
5.86k
            {
3568
5.86k
            SCHECK_PARTIAL();
3569
5.84k
            RRETURN(MATCH_NOMATCH);
3570
5.84k
            }
3571
183k
          switch(*Feptr++)
3572
183k
            {
3573
148k
            default: RRETURN(MATCH_NOMATCH);
3574
3575
17.5k
            case CHAR_CR:
3576
17.5k
            if (Feptr < mb->end_subject && *Feptr == CHAR_LF) Feptr++;
3577
17.5k
            break;
3578
3579
10.1k
            case CHAR_LF:
3580
10.1k
            break;
3581
3582
3.43k
            case CHAR_VT:
3583
5.29k
            case CHAR_FF:
3584
6.81k
            case CHAR_NEL:
3585
#if PCRE2_CODE_UNIT_WIDTH != 8
3586
            case 0x2028:
3587
            case 0x2029:
3588
#endif
3589
6.81k
            if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) RRETURN(MATCH_NOMATCH);
3590
6.81k
            break;
3591
183k
            }
3592
183k
          }
3593
27.4k
        break;
3594
3595
103k
        case OP_NOT_HSPACE:
3596
733k
        for (i = 1; i <= Lmin; i++)
3597
658k
          {
3598
658k
          if (Feptr >= mb->end_subject)
3599
18.1k
            {
3600
18.1k
            SCHECK_PARTIAL();
3601
18.0k
            RRETURN(MATCH_NOMATCH);
3602
18.0k
            }
3603
639k
          switch(*Feptr++)
3604
639k
            {
3605
630k
            default: break;
3606
630k
            HSPACE_BYTE_CASES:
3607
#if PCRE2_CODE_UNIT_WIDTH != 8
3608
            HSPACE_MULTIBYTE_CASES:
3609
#endif
3610
15.0k
            RRETURN(MATCH_NOMATCH);
3611
639k
            }
3612
639k
          }
3613
75.8k
        break;
3614
3615
367k
        case OP_HSPACE:
3616
372k
        for (i = 1; i <= Lmin; i++)
3617
368k
          {
3618
368k
          if (Feptr >= mb->end_subject)
3619
10.0k
            {
3620
10.0k
            SCHECK_PARTIAL();
3621
10.0k
            RRETURN(MATCH_NOMATCH);
3622
10.0k
            }
3623
358k
          switch(*Feptr++)
3624
358k
            {
3625
353k
            default: RRETURN(MATCH_NOMATCH);
3626
10.1k
            HSPACE_BYTE_CASES:
3627
#if PCRE2_CODE_UNIT_WIDTH != 8
3628
            HSPACE_MULTIBYTE_CASES:
3629
#endif
3630
10.1k
            break;
3631
358k
            }
3632
358k
          }
3633
3.66k
        break;
3634
3635
67.5k
        case OP_NOT_VSPACE:
3636
286k
        for (i = 1; i <= Lmin; i++)
3637
238k
          {
3638
238k
          if (Feptr >= mb->end_subject)
3639
8.78k
            {
3640
8.78k
            SCHECK_PARTIAL();
3641
8.74k
            RRETURN(MATCH_NOMATCH);
3642
8.74k
            }
3643
230k
          switch(*Feptr++)
3644
230k
            {
3645
32.8k
            VSPACE_BYTE_CASES:
3646
#if PCRE2_CODE_UNIT_WIDTH != 8
3647
            VSPACE_MULTIBYTE_CASES:
3648
#endif
3649
32.8k
            RRETURN(MATCH_NOMATCH);
3650
219k
            default: break;
3651
230k
            }
3652
230k
          }
3653
47.9k
        break;
3654
3655
230k
        case OP_VSPACE:
3656
244k
        for (i = 1; i <= Lmin; i++)
3657
235k
          {
3658
235k
          if (Feptr >= mb->end_subject)
3659
7.06k
            {
3660
7.06k
            SCHECK_PARTIAL();
3661
7.03k
            RRETURN(MATCH_NOMATCH);
3662
7.03k
            }
3663
228k
          switch(*Feptr++)
3664
228k
            {
3665
214k
            default: RRETURN(MATCH_NOMATCH);
3666
38.7k
            VSPACE_BYTE_CASES:
3667
#if PCRE2_CODE_UNIT_WIDTH != 8
3668
            VSPACE_MULTIBYTE_CASES:
3669
#endif
3670
38.7k
            break;
3671
228k
            }
3672
228k
          }
3673
8.55k
        break;
3674
3675
42.0k
        case OP_NOT_DIGIT:
3676
688k
        for (i = 1; i <= Lmin; i++)
3677
659k
          {
3678
659k
          if (Feptr >= mb->end_subject)
3679
3.69k
            {
3680
3.69k
            SCHECK_PARTIAL();
3681
3.67k
            RRETURN(MATCH_NOMATCH);
3682
3.67k
            }
3683
656k
          if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_digit) != 0)
3684
10.1k
            RRETURN(MATCH_NOMATCH);
3685
645k
          Feptr++;
3686
645k
          }
3687
28.1k
        break;
3688
3689
469k
        case OP_DIGIT:
3690
864k
        for (i = 1; i <= Lmin; i++)
3691
470k
          {
3692
470k
          if (Feptr >= mb->end_subject)
3693
33.4k
            {
3694
33.4k
            SCHECK_PARTIAL();
3695
33.4k
            RRETURN(MATCH_NOMATCH);
3696
33.4k
            }
3697
437k
          if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_digit) == 0)
3698
42.4k
            RRETURN(MATCH_NOMATCH);
3699
395k
          Feptr++;
3700
395k
          }
3701
393k
        break;
3702
3703
393k
        case OP_NOT_WHITESPACE:
3704
6.97M
        for (i = 1; i <= Lmin; i++)
3705
6.83M
          {
3706
6.83M
          if (Feptr >= mb->end_subject)
3707
20.7k
            {
3708
20.7k
            SCHECK_PARTIAL();
3709
20.6k
            RRETURN(MATCH_NOMATCH);
3710
20.6k
            }
3711
6.81M
          if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_space) != 0)
3712
12.8k
            RRETURN(MATCH_NOMATCH);
3713
6.79M
          Feptr++;
3714
6.79M
          }
3715
146k
        break;
3716
3717
245k
        case OP_WHITESPACE:
3718
271k
        for (i = 1; i <= Lmin; i++)
3719
268k
          {
3720
268k
          if (Feptr >= mb->end_subject)
3721
13.9k
            {
3722
13.9k
            SCHECK_PARTIAL();
3723
13.9k
            RRETURN(MATCH_NOMATCH);
3724
13.9k
            }
3725
254k
          if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_space) == 0)
3726
228k
            RRETURN(MATCH_NOMATCH);
3727
26.1k
          Feptr++;
3728
26.1k
          }
3729
3.24k
        break;
3730
3731
76.1k
        case OP_NOT_WORDCHAR:
3732
160k
        for (i = 1; i <= Lmin; i++)
3733
114k
          {
3734
114k
          if (Feptr >= mb->end_subject)
3735
5.26k
            {
3736
5.26k
            SCHECK_PARTIAL();
3737
5.24k
            RRETURN(MATCH_NOMATCH);
3738
5.24k
            }
3739
108k
          if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_word) != 0)
3740
24.2k
            RRETURN(MATCH_NOMATCH);
3741
84.5k
          Feptr++;
3742
84.5k
          }
3743
46.6k
        break;
3744
3745
88.6k
        case OP_WORDCHAR:
3746
111k
        for (i = 1; i <= Lmin; i++)
3747
97.7k
          {
3748
97.7k
          if (Feptr >= mb->end_subject)
3749
5.79k
            {
3750
5.79k
            SCHECK_PARTIAL();
3751
5.77k
            RRETURN(MATCH_NOMATCH);
3752
5.77k
            }
3753
91.9k
          if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_word) == 0)
3754
68.7k
            RRETURN(MATCH_NOMATCH);
3755
23.2k
          Feptr++;
3756
23.2k
          }
3757
14.1k
        break;
3758
3759
        /* LCOV_EXCL_START */
3760
14.1k
        default:
3761
0
        PCRE2_DEBUG_UNREACHABLE();
3762
0
        return PCRE2_ERROR_INTERNAL;
3763
        /* LCOV_EXCL_STOP */
3764
2.12M
        }
3765
4.88M
      }
3766
3767
    /* If Lmin = Lmax we are done. Continue with the main loop. */
3768
3769
9.29M
    if (Lmin == Lmax) continue;
3770
3771
    /* If minimizing, we have to test the rest of the pattern before each
3772
    subsequent match. This means we cannot use a local "notmatch" variable as
3773
    in the other cases. As all 4 temporary 32-bit values in the frame are
3774
    already in use, just test the type each time. */
3775
3776
8.91M
    if (reptype == REPTYPE_MIN)
3777
1.58M
      {
3778
1.58M
#ifdef SUPPORT_UNICODE
3779
1.58M
      if (proptype >= 0)
3780
812k
        {
3781
812k
        switch(proptype)
3782
812k
          {
3783
17.2k
          case PT_LAMP:
3784
17.2k
          for (;;)
3785
104k
            {
3786
104k
            int chartype;
3787
104k
            RMATCH(Fecode, RM208);
3788
104k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3789
103k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3790
101k
            if (Feptr >= mb->end_subject)
3791
2.73k
              {
3792
2.73k
              SCHECK_PARTIAL();
3793
2.72k
              RRETURN(MATCH_NOMATCH);
3794
2.72k
              }
3795
99.2k
            GETCHARINCTEST(fc, Feptr);
3796
99.2k
            chartype = UCD_CHARTYPE(fc);
3797
99.2k
            if ((chartype == ucp_Lu ||
3798
91.2k
                 chartype == ucp_Ll ||
3799
99.2k
                 chartype == ucp_Lt) == (Lctype == OP_NOTPROP))
3800
11.8k
              RRETURN(MATCH_NOMATCH);
3801
99.2k
            }
3802
17.2k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
3803
3804
20.1k
          case PT_GC:
3805
20.1k
          for (;;)
3806
93.7k
            {
3807
93.7k
            RMATCH(Fecode, RM209);
3808
93.6k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3809
93.3k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3810
82.9k
            if (Feptr >= mb->end_subject)
3811
4.84k
              {
3812
4.84k
              SCHECK_PARTIAL();
3813
4.83k
              RRETURN(MATCH_NOMATCH);
3814
4.83k
              }
3815
78.1k
            GETCHARINCTEST(fc, Feptr);
3816
78.1k
            if ((UCD_CATEGORY(fc) == Lpropvalue) == (Lctype == OP_NOTPROP))
3817
4.59k
              RRETURN(MATCH_NOMATCH);
3818
78.1k
            }
3819
20.1k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
3820
3821
62.2k
          case PT_PC:
3822
62.2k
          for (;;)
3823
286k
            {
3824
286k
            RMATCH(Fecode, RM210);
3825
286k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3826
285k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3827
268k
            if (Feptr >= mb->end_subject)
3828
6.72k
              {
3829
6.72k
              SCHECK_PARTIAL();
3830
6.71k
              RRETURN(MATCH_NOMATCH);
3831
6.71k
              }
3832
262k
            GETCHARINCTEST(fc, Feptr);
3833
262k
            if ((UCD_CHARTYPE(fc) == Lpropvalue) == (Lctype == OP_NOTPROP))
3834
37.5k
              RRETURN(MATCH_NOMATCH);
3835
262k
            }
3836
62.2k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
3837
3838
21.1k
          case PT_SC:
3839
21.1k
          for (;;)
3840
79.7k
            {
3841
79.7k
            RMATCH(Fecode, RM211);
3842
79.6k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3843
79.0k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3844
64.1k
            if (Feptr >= mb->end_subject)
3845
2.87k
              {
3846
2.87k
              SCHECK_PARTIAL();
3847
2.85k
              RRETURN(MATCH_NOMATCH);
3848
2.85k
              }
3849
61.2k
            GETCHARINCTEST(fc, Feptr);
3850
61.2k
            if ((UCD_SCRIPT(fc) == Lpropvalue) == (Lctype == OP_NOTPROP))
3851
2.62k
              RRETURN(MATCH_NOMATCH);
3852
61.2k
            }
3853
21.1k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
3854
3855
25.5k
          case PT_SCX:
3856
25.5k
          for (;;)
3857
167k
            {
3858
167k
            BOOL ok;
3859
167k
            const ucd_record *prop;
3860
167k
            RMATCH(Fecode, RM224);
3861
167k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3862
161k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3863
159k
            if (Feptr >= mb->end_subject)
3864
12.9k
              {
3865
12.9k
              SCHECK_PARTIAL();
3866
12.9k
              RRETURN(MATCH_NOMATCH);
3867
12.9k
              }
3868
146k
            GETCHARINCTEST(fc, Feptr);
3869
146k
            prop = GET_UCD(fc);
3870
146k
            ok = (prop->script == Lpropvalue
3871
143k
                  || MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0);
3872
146k
            if (ok == (Lctype == OP_NOTPROP))
3873
4.24k
              RRETURN(MATCH_NOMATCH);
3874
146k
            }
3875
25.5k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
3876
3877
30.9k
          case PT_ALNUM:
3878
30.9k
          for (;;)
3879
106k
            {
3880
106k
            int category;
3881
106k
            RMATCH(Fecode, RM212);
3882
106k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3883
104k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3884
104k
            if (Feptr >= mb->end_subject)
3885
8.43k
              {
3886
8.43k
              SCHECK_PARTIAL();
3887
8.41k
              RRETURN(MATCH_NOMATCH);
3888
8.41k
              }
3889
95.9k
            GETCHARINCTEST(fc, Feptr);
3890
95.9k
            category = UCD_CATEGORY(fc);
3891
95.9k
            if ((category == ucp_L || category == ucp_N) == (Lctype == OP_NOTPROP))
3892
20.3k
              RRETURN(MATCH_NOMATCH);
3893
95.9k
            }
3894
30.9k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
3895
3896
          /* Perl space used to exclude VT, but from Perl 5.18 it is included,
3897
          which means that Perl space and POSIX space are now identical. PCRE
3898
          was changed at release 8.34. */
3899
3900
228k
          case PT_SPACE:    /* Perl space */
3901
228k
          case PT_PXSPACE:  /* POSIX space */
3902
228k
          for (;;)
3903
855k
            {
3904
855k
            RMATCH(Fecode, RM213);
3905
855k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3906
854k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3907
766k
            if (Feptr >= mb->end_subject)
3908
14.3k
              {
3909
14.3k
              SCHECK_PARTIAL();
3910
14.3k
              RRETURN(MATCH_NOMATCH);
3911
14.3k
              }
3912
752k
            GETCHARINCTEST(fc, Feptr);
3913
752k
            switch(fc)
3914
752k
              {
3915
792k
              HSPACE_CASES:
3916
792k
              VSPACE_CASES:
3917
707k
              if (Lctype == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
3918
78.6k
              break;
3919
3920
632k
              default:
3921
632k
              if ((UCD_CATEGORY(fc) == ucp_Z) == (Lctype == OP_NOTPROP))
3922
84.2k
                RRETURN(MATCH_NOMATCH);
3923
548k
              break;
3924
752k
              }
3925
752k
            }
3926
228k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
3927
3928
60.5k
          case PT_WORD:
3929
60.5k
          for (;;)
3930
121k
            {
3931
121k
            int chartype, category;
3932
121k
            RMATCH(Fecode, RM214);
3933
121k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3934
119k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3935
112k
            if (Feptr >= mb->end_subject)
3936
3.25k
              {
3937
3.25k
              SCHECK_PARTIAL();
3938
3.25k
              RRETURN(MATCH_NOMATCH);
3939
3.25k
              }
3940
109k
            GETCHARINCTEST(fc, Feptr);
3941
109k
            chartype = UCD_CHARTYPE(fc);
3942
109k
            category = PRIV(ucp_gentype)[chartype];
3943
109k
            if ((category == ucp_L ||
3944
80.2k
                 category == ucp_N ||
3945
77.2k
                 chartype == ucp_Mn ||
3946
109k
                 chartype == ucp_Pc) == (Lctype == OP_NOTPROP))
3947
48.6k
              RRETURN(MATCH_NOMATCH);
3948
109k
            }
3949
60.5k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
3950
3951
272k
          case PT_CLIST:
3952
272k
          for (;;)
3953
335k
            {
3954
335k
            const uint32_t *cp;
3955
335k
            RMATCH(Fecode, RM215);
3956
335k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3957
309k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3958
306k
            if (Feptr >= mb->end_subject)
3959
2.57k
              {
3960
2.57k
              SCHECK_PARTIAL();
3961
2.56k
              RRETURN(MATCH_NOMATCH);
3962
2.56k
              }
3963
303k
            GETCHARINCTEST(fc, Feptr);
3964
#if PCRE2_CODE_UNIT_WIDTH == 32
3965
            if (fc > MAX_UTF_CODE_POINT)
3966
              {
3967
              if (Lctype == OP_NOTPROP) continue;
3968
              RRETURN(MATCH_NOMATCH);
3969
              }
3970
#endif
3971
303k
            cp = PRIV(ucd_caseless_sets) + Lpropvalue;
3972
303k
            for (;;)
3973
483k
              {
3974
483k
              if (fc < *cp)
3975
283k
                {
3976
283k
                if (Lctype == OP_NOTPROP) break;
3977
238k
                RRETURN(MATCH_NOMATCH);
3978
238k
                }
3979
199k
              if (fc == *cp++)
3980
20.2k
                {
3981
20.2k
                if (Lctype == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
3982
18.6k
                break;
3983
20.2k
                }
3984
199k
              }
3985
303k
            }
3986
272k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
3987
3988
14.8k
          case PT_UCNC:
3989
14.8k
          for (;;)
3990
131k
            {
3991
131k
            RMATCH(Fecode, RM216);
3992
131k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3993
131k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
3994
129k
            if (Feptr >= mb->end_subject)
3995
3.20k
              {
3996
3.20k
              SCHECK_PARTIAL();
3997
3.19k
              RRETURN(MATCH_NOMATCH);
3998
3.19k
              }
3999
126k
            GETCHARINCTEST(fc, Feptr);
4000
126k
            if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT ||
4001
124k
                 fc == CHAR_GRAVE_ACCENT || (fc >= 0xa0 && fc <= 0xd7ff) ||
4002
126k
                 fc >= 0xe000) == (Lctype == OP_NOTPROP))
4003
9.45k
              RRETURN(MATCH_NOMATCH);
4004
126k
            }
4005
14.8k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
4006
4007
37.2k
          case PT_BIDICL:
4008
37.2k
          for (;;)
4009
273k
            {
4010
273k
            RMATCH(Fecode, RM223);
4011
273k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4012
272k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
4013
244k
            if (Feptr >= mb->end_subject)
4014
6.04k
              {
4015
6.04k
              SCHECK_PARTIAL();
4016
6.04k
              RRETURN(MATCH_NOMATCH);
4017
6.04k
              }
4018
238k
            GETCHARINCTEST(fc, Feptr);
4019
238k
            if ((UCD_BIDICLASS(fc) == Lpropvalue) == (Lctype == OP_NOTPROP))
4020
1.48k
              RRETURN(MATCH_NOMATCH);
4021
238k
            }
4022
37.2k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
4023
4024
21.6k
          case PT_BOOL:
4025
21.6k
          for (;;)
4026
130k
            {
4027
130k
            BOOL ok;
4028
130k
            const ucd_record *prop;
4029
130k
            RMATCH(Fecode, RM222);
4030
129k
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4031
129k
            if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
4032
118k
            if (Feptr >= mb->end_subject)
4033
2.16k
              {
4034
2.16k
              SCHECK_PARTIAL();
4035
2.15k
              RRETURN(MATCH_NOMATCH);
4036
2.15k
              }
4037
116k
            GETCHARINCTEST(fc, Feptr);
4038
116k
            prop = GET_UCD(fc);
4039
116k
            ok = MAPBIT(PRIV(ucd_boolprop_sets) +
4040
116k
              UCD_BPROPS_PROP(prop), Lpropvalue) != 0;
4041
116k
            if (ok == (Lctype == OP_NOTPROP))
4042
7.84k
              RRETURN(MATCH_NOMATCH);
4043
116k
            }
4044
21.6k
          PCRE2_UNREACHABLE(); /* Control never reaches here */
4045
4046
          /* This should never occur */
4047
4048
          /* LCOV_EXCL_START */
4049
0
          default:
4050
0
          PCRE2_DEBUG_UNREACHABLE();
4051
0
          return PCRE2_ERROR_INTERNAL;
4052
          /* LCOV_EXCL_STOP */
4053
812k
          }
4054
812k
        }
4055
4056
      /* Match extended Unicode sequences. We will get here only if the
4057
      support is in the binary; otherwise a compile-time error occurs. */
4058
4059
772k
      else if (Lctype == OP_EXTUNI)
4060
24.2k
        {
4061
24.2k
        for (;;)
4062
180k
          {
4063
180k
          RMATCH(Fecode, RM217);
4064
180k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4065
180k
          if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
4066
163k
          if (Feptr >= mb->end_subject)
4067
6.81k
            {
4068
6.81k
            SCHECK_PARTIAL();
4069
6.80k
            RRETURN(MATCH_NOMATCH);
4070
6.80k
            }
4071
156k
          else
4072
156k
            {
4073
156k
            GETCHARINCTEST(fc, Feptr);
4074
156k
            Feptr = PRIV(extuni)(fc, Feptr, mb->check_subject, mb->end_subject,
4075
156k
              utf, NULL);
4076
156k
            }
4077
156k
          CHECK_PARTIAL();
4078
156k
          }
4079
24.2k
        }
4080
747k
      else
4081
747k
#endif     /* SUPPORT_UNICODE */
4082
4083
      /* UTF mode for non-property testing character types. */
4084
4085
747k
#ifdef SUPPORT_UNICODE
4086
747k
      if (utf)
4087
486k
        {
4088
486k
        for (;;)
4089
1.63M
          {
4090
1.63M
          RMATCH(Fecode, RM218);
4091
1.63M
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4092
1.62M
          if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
4093
1.48M
          if (Feptr >= mb->end_subject)
4094
40.2k
            {
4095
40.2k
            SCHECK_PARTIAL();
4096
40.2k
            RRETURN(MATCH_NOMATCH);
4097
40.2k
            }
4098
1.44M
          if (Lctype == OP_ANY && IS_NEWLINE(Feptr)) RRETURN(MATCH_NOMATCH);
4099
1.44M
          GETCHARINC(fc, Feptr);
4100
1.44M
          switch(Lctype)
4101
1.44M
            {
4102
156k
            case OP_ANY:               /* This is the non-NL case */
4103
156k
            if (mb->partial != 0 &&    /* Take care with CRLF partial */
4104
21.6k
                Feptr >= mb->end_subject &&
4105
571
                NLBLOCK->nltype == NLTYPE_FIXED &&
4106
571
                NLBLOCK->nllen == 2 &&
4107
0
                fc == NLBLOCK->nl[0])
4108
0
              {
4109
0
              mb->hitend = TRUE;
4110
0
              if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
4111
0
              }
4112
156k
            break;
4113
4114
156k
            case OP_ALLANY:
4115
47.0k
            case OP_ANYBYTE:
4116
47.0k
            break;
4117
4118
58.1k
            case OP_ANYNL:
4119
58.1k
            switch(fc)
4120
58.1k
              {
4121
36.6k
              default: RRETURN(MATCH_NOMATCH);
4122
4123
13.2k
              case CHAR_CR:
4124
13.2k
              if (Feptr < mb->end_subject && *Feptr == CHAR_LF) Feptr++;
4125
13.2k
              break;
4126
4127
1.12k
              case CHAR_LF:
4128
1.12k
              break;
4129
4130
3.39k
              case CHAR_VT:
4131
4.41k
              case CHAR_FF:
4132
5.38k
              case CHAR_NEL:
4133
5.38k
#ifndef EBCDIC
4134
6.25k
              case 0x2028:
4135
7.18k
              case 0x2029:
4136
7.18k
#endif  /* Not EBCDIC */
4137
7.18k
              if (mb->bsr_convention == PCRE2_BSR_ANYCRLF)
4138
0
                RRETURN(MATCH_NOMATCH);
4139
7.18k
              break;
4140
58.1k
              }
4141
21.5k
            break;
4142
4143
513k
            case OP_NOT_HSPACE:
4144
513k
            switch(fc)
4145
513k
              {
4146
253k
              HSPACE_CASES: RRETURN(MATCH_NOMATCH);
4147
488k
              default: break;
4148
513k
              }
4149
488k
            break;
4150
4151
488k
            case OP_HSPACE:
4152
131k
            switch(fc)
4153
131k
              {
4154
36.2k
              HSPACE_CASES: break;
4155
94.9k
              default: RRETURN(MATCH_NOMATCH);
4156
131k
              }
4157
36.2k
            break;
4158
4159
69.4k
            case OP_NOT_VSPACE:
4160
69.4k
            switch(fc)
4161
69.4k
              {
4162
22.2k
              VSPACE_CASES: RRETURN(MATCH_NOMATCH);
4163
63.6k
              default: break;
4164
69.4k
              }
4165
63.6k
            break;
4166
4167
63.6k
            case OP_VSPACE:
4168
49.6k
            switch(fc)
4169
49.6k
              {
4170
6.02k
              VSPACE_CASES: break;
4171
43.6k
              default: RRETURN(MATCH_NOMATCH);
4172
49.6k
              }
4173
6.02k
            break;
4174
4175
144k
            case OP_NOT_DIGIT:
4176
144k
            if (fc < 256 && (mb->ctypes[fc] & ctype_digit) != 0)
4177
3.14k
              RRETURN(MATCH_NOMATCH);
4178
141k
            break;
4179
4180
141k
            case OP_DIGIT:
4181
10.0k
            if (fc >= 256 || (mb->ctypes[fc] & ctype_digit) == 0)
4182
8.95k
              RRETURN(MATCH_NOMATCH);
4183
1.07k
            break;
4184
4185
69.8k
            case OP_NOT_WHITESPACE:
4186
69.8k
            if (fc < 256 && (mb->ctypes[fc] & ctype_space) != 0)
4187
2.94k
              RRETURN(MATCH_NOMATCH);
4188
66.9k
            break;
4189
4190
149k
            case OP_WHITESPACE:
4191
149k
            if (fc >= 256 || (mb->ctypes[fc] & ctype_space) == 0)
4192
59.8k
              RRETURN(MATCH_NOMATCH);
4193
89.6k
            break;
4194
4195
89.6k
            case OP_NOT_WORDCHAR:
4196
32.7k
            if (fc < 256 && (mb->ctypes[fc] & ctype_word) != 0)
4197
9.55k
              RRETURN(MATCH_NOMATCH);
4198
23.1k
            break;
4199
4200
23.1k
            case OP_WORDCHAR:
4201
13.8k
            if (fc >= 256 || (mb->ctypes[fc] & ctype_word) == 0)
4202
8.07k
              RRETURN(MATCH_NOMATCH);
4203
5.78k
            break;
4204
4205
            /* LCOV_EXCL_START */
4206
5.78k
            default:
4207
0
            PCRE2_DEBUG_UNREACHABLE();
4208
0
            return PCRE2_ERROR_INTERNAL;
4209
            /* LCOV_EXCL_STOP */
4210
1.44M
            }
4211
1.44M
          }
4212
486k
        }
4213
261k
      else
4214
261k
#endif  /* SUPPORT_UNICODE */
4215
4216
      /* Not UTF mode */
4217
261k
        {
4218
261k
        for (;;)
4219
898k
          {
4220
898k
          RMATCH(Fecode, RM33);
4221
896k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4222
843k
          if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
4223
783k
          if (Feptr >= mb->end_subject)
4224
22.3k
            {
4225
22.3k
            SCHECK_PARTIAL();
4226
22.2k
            RRETURN(MATCH_NOMATCH);
4227
22.2k
            }
4228
760k
          if (Lctype == OP_ANY && IS_NEWLINE(Feptr))
4229
1.56k
            RRETURN(MATCH_NOMATCH);
4230
759k
          fc = *Feptr++;
4231
759k
          switch(Lctype)
4232
759k
            {
4233
86.2k
            case OP_ANY:               /* This is the non-NL case */
4234
86.2k
            if (mb->partial != 0 &&    /* Take care with CRLF partial */
4235
15.3k
                Feptr >= mb->end_subject &&
4236
549
                NLBLOCK->nltype == NLTYPE_FIXED &&
4237
549
                NLBLOCK->nllen == 2 &&
4238
0
                fc == NLBLOCK->nl[0])
4239
0
              {
4240
0
              mb->hitend = TRUE;
4241
0
              if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
4242
0
              }
4243
86.2k
            break;
4244
4245
93.6k
            case OP_ALLANY:
4246
93.6k
            case OP_ANYBYTE:
4247
93.6k
            break;
4248
4249
46.1k
            case OP_ANYNL:
4250
46.1k
            switch(fc)
4251
46.1k
              {
4252
25.5k
              default: RRETURN(MATCH_NOMATCH);
4253
4254
6.14k
              case CHAR_CR:
4255
6.14k
              if (Feptr < mb->end_subject && *Feptr == CHAR_LF) Feptr++;
4256
6.14k
              break;
4257
4258
10.2k
              case CHAR_LF:
4259
10.2k
              break;
4260
4261
871
              case CHAR_VT:
4262
2.91k
              case CHAR_FF:
4263
4.24k
              case CHAR_NEL:
4264
#if PCRE2_CODE_UNIT_WIDTH != 8
4265
              case 0x2028:
4266
              case 0x2029:
4267
#endif
4268
4.24k
              if (mb->bsr_convention == PCRE2_BSR_ANYCRLF)
4269
0
                RRETURN(MATCH_NOMATCH);
4270
4.24k
              break;
4271
46.1k
              }
4272
20.6k
            break;
4273
4274
199k
            case OP_NOT_HSPACE:
4275
199k
            switch(fc)
4276
199k
              {
4277
193k
              default: break;
4278
193k
              HSPACE_BYTE_CASES:
4279
#if PCRE2_CODE_UNIT_WIDTH != 8
4280
              HSPACE_MULTIBYTE_CASES:
4281
#endif
4282
11.9k
              RRETURN(MATCH_NOMATCH);
4283
199k
              }
4284
193k
            break;
4285
4286
193k
            case OP_HSPACE:
4287
15.4k
            switch(fc)
4288
15.4k
              {
4289
14.3k
              default: RRETURN(MATCH_NOMATCH);
4290
2.31k
              HSPACE_BYTE_CASES:
4291
#if PCRE2_CODE_UNIT_WIDTH != 8
4292
              HSPACE_MULTIBYTE_CASES:
4293
#endif
4294
2.31k
              break;
4295
15.4k
              }
4296
1.04k
            break;
4297
4298
50.9k
            case OP_NOT_VSPACE:
4299
50.9k
            switch(fc)
4300
50.9k
              {
4301
48.4k
              default: break;
4302
48.4k
              VSPACE_BYTE_CASES:
4303
#if PCRE2_CODE_UNIT_WIDTH != 8
4304
              VSPACE_MULTIBYTE_CASES:
4305
#endif
4306
7.53k
              RRETURN(MATCH_NOMATCH);
4307
50.9k
              }
4308
48.4k
            break;
4309
4310
48.4k
            case OP_VSPACE:
4311
35.5k
            switch(fc)
4312
35.5k
              {
4313
29.5k
              default: RRETURN(MATCH_NOMATCH);
4314
14.7k
              VSPACE_BYTE_CASES:
4315
#if PCRE2_CODE_UNIT_WIDTH != 8
4316
              VSPACE_MULTIBYTE_CASES:
4317
#endif
4318
14.7k
              break;
4319
35.5k
              }
4320
6.07k
            break;
4321
4322
78.5k
            case OP_NOT_DIGIT:
4323
78.5k
            if (MAX_255(fc) && (mb->ctypes[fc] & ctype_digit) != 0)
4324
6.07k
              RRETURN(MATCH_NOMATCH);
4325
72.5k
            break;
4326
4327
72.5k
            case OP_DIGIT:
4328
3.32k
            if (!MAX_255(fc) || (mb->ctypes[fc] & ctype_digit) == 0)
4329
2.58k
              RRETURN(MATCH_NOMATCH);
4330
737
            break;
4331
4332
79.5k
            case OP_NOT_WHITESPACE:
4333
79.5k
            if (MAX_255(fc) && (mb->ctypes[fc] & ctype_space) != 0)
4334
2.04k
              RRETURN(MATCH_NOMATCH);
4335
77.4k
            break;
4336
4337
77.4k
            case OP_WHITESPACE:
4338
50.5k
            if (!MAX_255(fc) || (mb->ctypes[fc] & ctype_space) == 0)
4339
25.9k
              RRETURN(MATCH_NOMATCH);
4340
24.6k
            break;
4341
4342
24.6k
            case OP_NOT_WORDCHAR:
4343
13.6k
            if (MAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0)
4344
2.81k
              RRETURN(MATCH_NOMATCH);
4345
10.8k
            break;
4346
4347
10.8k
            case OP_WORDCHAR:
4348
5.83k
            if (!MAX_255(fc) || (mb->ctypes[fc] & ctype_word) == 0)
4349
3.98k
              RRETURN(MATCH_NOMATCH);
4350
1.84k
            break;
4351
4352
            /* LCOV_EXCL_START */
4353
1.84k
            default:
4354
0
            PCRE2_DEBUG_UNREACHABLE();
4355
0
            return PCRE2_ERROR_INTERNAL;
4356
            /* LCOV_EXCL_STOP */
4357
759k
            }
4358
759k
          }
4359
261k
        }
4360
4361
0
      PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */
4362
0
      }
4363
4364
    /* If maximizing, it is worth using inline code for speed, doing the type
4365
    test once at the start (i.e. keep it out of the loops). Once again,
4366
    "notmatch" can be an ordinary local variable because the loops do not call
4367
    RMATCH. */
4368
4369
7.33M
    else
4370
7.33M
      {
4371
7.33M
      Lstart_eptr = Feptr;  /* Remember where we started */
4372
4373
7.33M
#ifdef SUPPORT_UNICODE
4374
7.33M
      if (proptype >= 0)
4375
2.73M
        {
4376
2.73M
        BOOL notmatch = Lctype == OP_NOTPROP;
4377
2.73M
        switch(proptype)
4378
2.73M
          {
4379
70.3k
          case PT_LAMP:
4380
415k
          for (i = Lmin; i < Lmax; i++)
4381
411k
            {
4382
411k
            int chartype;
4383
411k
            int len = 1;
4384
411k
            if (Feptr >= mb->end_subject)
4385
8.67k
              {
4386
8.67k
              SCHECK_PARTIAL();
4387
8.65k
              break;
4388
8.67k
              }
4389
403k
            GETCHARLENTEST(fc, Feptr, len);
4390
403k
            chartype = UCD_CHARTYPE(fc);
4391
403k
            if ((chartype == ucp_Lu ||
4392
378k
                 chartype == ucp_Ll ||
4393
345k
                 chartype == ucp_Lt) == notmatch)
4394
58.0k
              break;
4395
345k
            Feptr+= len;
4396
345k
            }
4397
70.3k
          break;
4398
4399
115k
          case PT_GC:
4400
495k
          for (i = Lmin; i < Lmax; i++)
4401
433k
            {
4402
433k
            int len = 1;
4403
433k
            if (Feptr >= mb->end_subject)
4404
9.50k
              {
4405
9.50k
              SCHECK_PARTIAL();
4406
9.48k
              break;
4407
9.50k
              }
4408
423k
            GETCHARLENTEST(fc, Feptr, len);
4409
423k
            if ((UCD_CATEGORY(fc) == Lpropvalue) == notmatch) break;
4410
380k
            Feptr+= len;
4411
380k
            }
4412
115k
          break;
4413
4414
799k
          case PT_PC:
4415
13.9M
          for (i = Lmin; i < Lmax; i++)
4416
13.9M
            {
4417
13.9M
            int len = 1;
4418
13.9M
            if (Feptr >= mb->end_subject)
4419
24.8k
              {
4420
24.8k
              SCHECK_PARTIAL();
4421
24.8k
              break;
4422
24.8k
              }
4423
13.9M
            GETCHARLENTEST(fc, Feptr, len);
4424
13.9M
            if ((UCD_CHARTYPE(fc) == Lpropvalue) == notmatch) break;
4425
13.1M
            Feptr+= len;
4426
13.1M
            }
4427
799k
          break;
4428
4429
799k
          case PT_SC:
4430
153k
          for (i = Lmin; i < Lmax; i++)
4431
132k
            {
4432
132k
            int len = 1;
4433
132k
            if (Feptr >= mb->end_subject)
4434
6.07k
              {
4435
6.07k
              SCHECK_PARTIAL();
4436
6.04k
              break;
4437
6.07k
              }
4438
126k
            GETCHARLENTEST(fc, Feptr, len);
4439
126k
            if ((UCD_SCRIPT(fc) == Lpropvalue) == notmatch) break;
4440
121k
            Feptr+= len;
4441
121k
            }
4442
31.2k
          break;
4443
4444
31.2k
          case PT_SCX:
4445
638k
          for (i = Lmin; i < Lmax; i++)
4446
636k
            {
4447
636k
            BOOL ok;
4448
636k
            const ucd_record *prop;
4449
636k
            int len = 1;
4450
636k
            if (Feptr >= mb->end_subject)
4451
15.5k
              {
4452
15.5k
              SCHECK_PARTIAL();
4453
15.4k
              break;
4454
15.5k
              }
4455
620k
            GETCHARLENTEST(fc, Feptr, len);
4456
620k
            prop = GET_UCD(fc);
4457
620k
            ok = (prop->script == Lpropvalue ||
4458
616k
                  MAPBIT(PRIV(ucd_script_sets) + UCD_SCRIPTX_PROP(prop), Lpropvalue) != 0);
4459
620k
            if (ok == notmatch) break;
4460
614k
            Feptr+= len;
4461
614k
            }
4462
23.3k
          break;
4463
4464
147k
          case PT_ALNUM:
4465
401k
          for (i = Lmin; i < Lmax; i++)
4466
399k
            {
4467
399k
            int category;
4468
399k
            int len = 1;
4469
399k
            if (Feptr >= mb->end_subject)
4470
11.4k
              {
4471
11.4k
              SCHECK_PARTIAL();
4472
11.4k
              break;
4473
11.4k
              }
4474
387k
            GETCHARLENTEST(fc, Feptr, len);
4475
387k
            category = UCD_CATEGORY(fc);
4476
387k
            if ((category == ucp_L || category == ucp_N) == notmatch)
4477
133k
              break;
4478
254k
            Feptr+= len;
4479
254k
            }
4480
147k
          break;
4481
4482
          /* Perl space used to exclude VT, but from Perl 5.18 it is included,
4483
          which means that Perl space and POSIX space are now identical. PCRE
4484
          was changed at release 8.34. */
4485
4486
1.23M
          case PT_SPACE:    /* Perl space */
4487
1.23M
          case PT_PXSPACE:  /* POSIX space */
4488
23.6M
          for (i = Lmin; i < Lmax; i++)
4489
23.4M
            {
4490
23.4M
            int len = 1;
4491
23.4M
            if (Feptr >= mb->end_subject)
4492
146k
              {
4493
146k
              SCHECK_PARTIAL();
4494
146k
              break;
4495
146k
              }
4496
23.2M
            GETCHARLENTEST(fc, Feptr, len);
4497
23.2M
            switch(fc)
4498
23.2M
              {
4499
1.55M
              HSPACE_CASES:
4500
2.32M
              VSPACE_CASES:
4501
2.32M
              if (notmatch) goto ENDLOOP99;  /* Break the loop */
4502
183k
              break;
4503
4504
22.8M
              default:
4505
22.8M
              if ((UCD_CATEGORY(fc) == ucp_Z) == notmatch)
4506
669k
                goto ENDLOOP99;   /* Break the loop */
4507
22.2M
              break;
4508
23.2M
              }
4509
22.3M
            Feptr+= len;
4510
22.3M
            }
4511
1.23M
          ENDLOOP99:
4512
1.23M
          break;
4513
4514
322k
          case PT_WORD:
4515
336k
          for (i = Lmin; i < Lmax; i++)
4516
316k
            {
4517
316k
            int chartype, category;
4518
316k
            int len = 1;
4519
316k
            if (Feptr >= mb->end_subject)
4520
5.26k
              {
4521
5.26k
              SCHECK_PARTIAL();
4522
5.25k
              break;
4523
5.26k
              }
4524
311k
            GETCHARLENTEST(fc, Feptr, len);
4525
311k
            chartype = UCD_CHARTYPE(fc);
4526
311k
            category = PRIV(ucp_gentype)[chartype];
4527
311k
            if ((category == ucp_L ||
4528
224k
                 category == ucp_N ||
4529
208k
                 chartype == ucp_Mn ||
4530
205k
                 chartype == ucp_Pc) == notmatch)
4531
79.9k
              break;
4532
231k
            Feptr+= len;
4533
231k
            }
4534
105k
          break;
4535
4536
105k
          case PT_CLIST:
4537
162k
          for (i = Lmin; i < Lmax; i++)
4538
161k
            {
4539
161k
            const uint32_t *cp;
4540
161k
            int len = 1;
4541
161k
            if (Feptr >= mb->end_subject)
4542
5.41k
              {
4543
5.41k
              SCHECK_PARTIAL();
4544
5.40k
              break;
4545
5.41k
              }
4546
155k
            GETCHARLENTEST(fc, Feptr, len);
4547
#if PCRE2_CODE_UNIT_WIDTH == 32
4548
            if (fc > MAX_UTF_CODE_POINT)
4549
              {
4550
              if (!notmatch) goto GOT_MAX;
4551
              }
4552
            else
4553
#endif
4554
155k
              {
4555
155k
              cp = PRIV(ucd_caseless_sets) + Lpropvalue;
4556
155k
              for (;;)
4557
281k
                {
4558
281k
                if (fc < *cp)
4559
147k
                  { if (notmatch) break; else goto GOT_MAX; }
4560
134k
                if (fc == *cp++)
4561
8.35k
                  { if (notmatch) goto GOT_MAX; else break; }
4562
134k
                }
4563
155k
              }
4564
4565
76.6k
            Feptr += len;
4566
76.6k
            }
4567
85.7k
          GOT_MAX:
4568
85.7k
          break;
4569
4570
74.9k
          case PT_UCNC:
4571
470k
          for (i = Lmin; i < Lmax; i++)
4572
435k
            {
4573
435k
            int len = 1;
4574
435k
            if (Feptr >= mb->end_subject)
4575
7.67k
              {
4576
7.67k
              SCHECK_PARTIAL();
4577
7.65k
              break;
4578
7.67k
              }
4579
427k
            GETCHARLENTEST(fc, Feptr, len);
4580
427k
            if ((fc == CHAR_DOLLAR_SIGN || fc == CHAR_COMMERCIAL_AT ||
4581
424k
                 fc == CHAR_GRAVE_ACCENT || (fc >= 0xa0 && fc <= 0xd7ff) ||
4582
392k
                 fc >= 0xe000) == notmatch)
4583
32.0k
              break;
4584
395k
            Feptr += len;
4585
395k
            }
4586
74.9k
          break;
4587
4588
74.9k
          case PT_BIDICL:
4589
495k
          for (i = Lmin; i < Lmax; i++)
4590
480k
            {
4591
480k
            int len = 1;
4592
480k
            if (Feptr >= mb->end_subject)
4593
10.7k
              {
4594
10.7k
              SCHECK_PARTIAL();
4595
10.6k
              break;
4596
10.7k
              }
4597
469k
            GETCHARLENTEST(fc, Feptr, len);
4598
469k
            if ((UCD_BIDICLASS(fc) == Lpropvalue) == notmatch) break;
4599
464k
            Feptr+= len;
4600
464k
            }
4601
30.1k
          break;
4602
4603
30.1k
          case PT_BOOL:
4604
158k
          for (i = Lmin; i < Lmax; i++)
4605
149k
            {
4606
149k
            BOOL ok;
4607
149k
            const ucd_record *prop;
4608
149k
            int len = 1;
4609
149k
            if (Feptr >= mb->end_subject)
4610
4.88k
              {
4611
4.88k
              SCHECK_PARTIAL();
4612
4.87k
              break;
4613
4.88k
              }
4614
144k
            GETCHARLENTEST(fc, Feptr, len);
4615
144k
            prop = GET_UCD(fc);
4616
144k
            ok = MAPBIT(PRIV(ucd_boolprop_sets) +
4617
144k
              UCD_BPROPS_PROP(prop), Lpropvalue) != 0;
4618
144k
            if (ok == notmatch) break;
4619
138k
            Feptr+= len;
4620
138k
            }
4621
20.0k
          break;
4622
4623
          /* LCOV_EXCL_START */
4624
20.0k
          default:
4625
0
          PCRE2_DEBUG_UNREACHABLE();
4626
0
          return PCRE2_ERROR_INTERNAL;
4627
          /* LCOV_EXCL_STOP */
4628
2.73M
          }
4629
4630
        /* Feptr is now past the end of the maximum run */
4631
4632
2.73M
        if (reptype == REPTYPE_POS) continue;    /* No backtracking */
4633
4634
        /* After \C in UTF mode, Lstart_eptr might be in the middle of a
4635
        Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't
4636
        go too far. */
4637
4638
864k
        for(;;)
4639
3.04M
          {
4640
3.04M
          if (Feptr <= Lstart_eptr) break;
4641
2.19M
          RMATCH(Fecode, RM221);
4642
2.19M
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4643
2.17M
          Feptr--;
4644
2.17M
          if (utf) BACKCHAR(Feptr);
4645
2.17M
          }
4646
864k
        }
4647
4648
      /* Match extended Unicode grapheme clusters. We will get here only if the
4649
      support is in the binary; otherwise a compile-time error occurs. */
4650
4651
4.59M
      else if (Lctype == OP_EXTUNI)
4652
35.3k
        {
4653
518k
        for (i = Lmin; i < Lmax; i++)
4654
501k
          {
4655
501k
          if (Feptr >= mb->end_subject)
4656
18.3k
            {
4657
18.3k
            SCHECK_PARTIAL();
4658
18.3k
            break;
4659
18.3k
            }
4660
483k
          else
4661
483k
            {
4662
483k
            GETCHARINCTEST(fc, Feptr);
4663
483k
            Feptr = PRIV(extuni)(fc, Feptr, mb->check_subject, mb->end_subject,
4664
483k
              utf, NULL);
4665
483k
            }
4666
483k
          CHECK_PARTIAL();
4667
483k
          }
4668
4669
        /* Feptr is now past the end of the maximum run */
4670
4671
35.2k
        if (reptype == REPTYPE_POS) continue;    /* No backtracking */
4672
4673
        /* We use <= Lstart_eptr rather than == Lstart_eptr to detect the start
4674
        of the run while backtracking because the use of \C in UTF mode can
4675
        cause BACKCHAR to move back past Lstart_eptr. This is just palliative;
4676
        the use of \C in UTF mode is fraught with danger. */
4677
4678
32.4k
        for(;;)
4679
385k
          {
4680
385k
          int lgb, rgb;
4681
385k
          PCRE2_SPTR fptr;
4682
4683
385k
          if (Feptr <= Lstart_eptr) break;   /* At start of char run */
4684
353k
          RMATCH(Fecode, RM219);
4685
353k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4686
4687
          /* Backtracking over an extended grapheme cluster involves inspecting
4688
          the previous two characters (if present) to see if a break is
4689
          permitted between them. */
4690
4691
352k
          Feptr--;
4692
352k
          if (!utf) fc = *Feptr; else
4693
91.4k
            {
4694
91.4k
            BACKCHAR(Feptr);
4695
91.4k
            GETCHAR(fc, Feptr);
4696
91.4k
            }
4697
352k
          rgb = UCD_GRAPHBREAK(fc);
4698
4699
352k
          for (;;)
4700
354k
            {
4701
354k
            if (Feptr <= Lstart_eptr) break;   /* At start of char run */
4702
324k
            fptr = Feptr - 1;
4703
324k
            if (!utf) fc = *fptr; else
4704
85.9k
              {
4705
85.9k
              BACKCHAR(fptr);
4706
85.9k
              GETCHAR(fc, fptr);
4707
85.9k
              }
4708
324k
            lgb = UCD_GRAPHBREAK(fc);
4709
324k
            if ((PRIV(ucp_gbtable)[lgb] & (1u << rgb)) == 0) break;
4710
1.45k
            Feptr = fptr;
4711
1.45k
            rgb = lgb;
4712
1.45k
            }
4713
352k
          }
4714
32.4k
        }
4715
4716
4.56M
      else
4717
4.56M
#endif   /* SUPPORT_UNICODE */
4718
4719
4.56M
#ifdef SUPPORT_UNICODE
4720
4.56M
      if (utf)
4721
1.28M
        {
4722
1.28M
        switch(Lctype)
4723
1.28M
          {
4724
60.3k
          case OP_ANY:
4725
328k
          for (i = Lmin; i < Lmax; i++)
4726
277k
            {
4727
277k
            if (Feptr >= mb->end_subject)
4728
8.34k
              {
4729
8.34k
              SCHECK_PARTIAL();
4730
8.28k
              break;
4731
8.34k
              }
4732
269k
            if (IS_NEWLINE(Feptr)) break;
4733
268k
            if (mb->partial != 0 &&    /* Take care with CRLF partial */
4734
107k
                Feptr + 1 >= mb->end_subject &&
4735
1.50k
                NLBLOCK->nltype == NLTYPE_FIXED &&
4736
1.50k
                NLBLOCK->nllen == 2 &&
4737
0
                *Feptr == NLBLOCK->nl[0])
4738
0
              {
4739
0
              mb->hitend = TRUE;
4740
0
              if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
4741
0
              }
4742
268k
            Feptr++;
4743
268k
            ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++);
4744
268k
            }
4745
60.2k
          break;
4746
4747
60.2k
          case OP_ALLANY:
4748
39.9k
          if (Lmax < UINT32_MAX)
4749
29.6k
            {
4750
92.3k
            for (i = Lmin; i < Lmax; i++)
4751
64.5k
              {
4752
64.5k
              if (Feptr >= mb->end_subject)
4753
1.80k
                {
4754
1.80k
                SCHECK_PARTIAL();
4755
1.79k
                break;
4756
1.80k
                }
4757
62.7k
              Feptr++;
4758
62.7k
              ACROSSCHAR(Feptr < mb->end_subject, Feptr, Feptr++);
4759
62.7k
              }
4760
29.6k
            }
4761
10.2k
          else
4762
10.2k
            {
4763
10.2k
            Feptr = mb->end_subject;   /* Unlimited UTF-8 repeat */
4764
10.2k
            SCHECK_PARTIAL();
4765
10.2k
            }
4766
39.8k
          break;
4767
4768
          /* The "byte" (i.e. "code unit") case is the same as non-UTF */
4769
4770
39.8k
          case OP_ANYBYTE:
4771
0
          fc = Lmax - Lmin;
4772
0
          if (fc > (uint32_t)(mb->end_subject - Feptr))
4773
0
            {
4774
0
            Feptr = mb->end_subject;
4775
0
            SCHECK_PARTIAL();
4776
0
            }
4777
0
          else Feptr += fc;
4778
0
          break;
4779
4780
55.4k
          case OP_ANYNL:
4781
67.8k
          for (i = Lmin; i < Lmax; i++)
4782
65.2k
            {
4783
65.2k
            int len = 1;
4784
65.2k
            if (Feptr >= mb->end_subject)
4785
6.30k
              {
4786
6.30k
              SCHECK_PARTIAL();
4787
6.28k
              break;
4788
6.30k
              }
4789
58.9k
            GETCHARLEN(fc, Feptr, len);
4790
58.9k
            if (fc == CHAR_CR)
4791
6.00k
              {
4792
6.00k
              if (++Feptr >= mb->end_subject) break;
4793
5.29k
              if (*Feptr == CHAR_LF) Feptr++;
4794
5.29k
              }
4795
52.9k
            else
4796
52.9k
              {
4797
52.9k
              if (fc != CHAR_LF &&
4798
51.6k
                  (mb->bsr_convention == PCRE2_BSR_ANYCRLF ||
4799
51.6k
                   (fc != CHAR_VT && fc != CHAR_FF && fc != CHAR_NEL
4800
47.5k
#ifndef EBCDIC
4801
47.5k
                    && fc != 0x2028 && fc != 0x2029
4802
51.6k
#endif  /* Not EBCDIC */
4803
51.6k
                    )))
4804
45.8k
                break;
4805
7.14k
              Feptr += len;
4806
7.14k
              }
4807
58.9k
            }
4808
55.3k
          break;
4809
4810
123k
          case OP_NOT_HSPACE:
4811
313k
          case OP_HSPACE:
4812
2.21M
          for (i = Lmin; i < Lmax; i++)
4813
2.19M
            {
4814
2.19M
            BOOL gotspace;
4815
2.19M
            int len = 1;
4816
2.19M
            if (Feptr >= mb->end_subject)
4817
18.7k
              {
4818
18.7k
              SCHECK_PARTIAL();
4819
18.7k
              break;
4820
18.7k
              }
4821
2.17M
            GETCHARLEN(fc, Feptr, len);
4822
2.17M
            switch(fc)
4823
2.17M
              {
4824
124k
              HSPACE_CASES: gotspace = TRUE; break;
4825
2.05M
              default: gotspace = FALSE; break;
4826
2.17M
              }
4827
2.17M
            if (gotspace == (Lctype == OP_NOT_HSPACE)) break;
4828
1.90M
            Feptr += len;
4829
1.90M
            }
4830
313k
          break;
4831
4832
313k
          case OP_NOT_VSPACE:
4833
77.9k
          case OP_VSPACE:
4834
557k
          for (i = Lmin; i < Lmax; i++)
4835
534k
            {
4836
534k
            BOOL gotspace;
4837
534k
            int len = 1;
4838
534k
            if (Feptr >= mb->end_subject)
4839
6.12k
              {
4840
6.12k
              SCHECK_PARTIAL();
4841
6.09k
              break;
4842
6.12k
              }
4843
528k
            GETCHARLEN(fc, Feptr, len);
4844
528k
            switch(fc)
4845
528k
              {
4846
22.2k
              VSPACE_CASES: gotspace = TRUE; break;
4847
506k
              default: gotspace = FALSE; break;
4848
528k
              }
4849
528k
            if (gotspace == (Lctype == OP_NOT_VSPACE)) break;
4850
479k
            Feptr += len;
4851
479k
            }
4852
77.8k
          break;
4853
4854
91.3k
          case OP_NOT_DIGIT:
4855
3.03M
          for (i = Lmin; i < Lmax; i++)
4856
3.03M
            {
4857
3.03M
            int len = 1;
4858
3.03M
            if (Feptr >= mb->end_subject)
4859
18.6k
              {
4860
18.6k
              SCHECK_PARTIAL();
4861
18.6k
              break;
4862
18.6k
              }
4863
3.01M
            GETCHARLEN(fc, Feptr, len);
4864
3.01M
            if (fc < 256 && (mb->ctypes[fc] & ctype_digit) != 0) break;
4865
2.94M
            Feptr+= len;
4866
2.94M
            }
4867
91.3k
          break;
4868
4869
91.3k
          case OP_DIGIT:
4870
92.7k
          for (i = Lmin; i < Lmax; i++)
4871
91.5k
            {
4872
91.5k
            int len = 1;
4873
91.5k
            if (Feptr >= mb->end_subject)
4874
4.13k
              {
4875
4.13k
              SCHECK_PARTIAL();
4876
4.12k
              break;
4877
4.13k
              }
4878
87.4k
            GETCHARLEN(fc, Feptr, len);
4879
87.4k
            if (fc >= 256 ||(mb->ctypes[fc] & ctype_digit) == 0) break;
4880
6.03k
            Feptr+= len;
4881
6.03k
            }
4882
86.6k
          break;
4883
4884
86.6k
          case OP_NOT_WHITESPACE:
4885
1.34M
          for (i = Lmin; i < Lmax; i++)
4886
1.33M
            {
4887
1.33M
            int len = 1;
4888
1.33M
            if (Feptr >= mb->end_subject)
4889
9.12k
              {
4890
9.12k
              SCHECK_PARTIAL();
4891
9.11k
              break;
4892
9.12k
              }
4893
1.33M
            GETCHARLEN(fc, Feptr, len);
4894
1.33M
            if (fc < 256 && (mb->ctypes[fc] & ctype_space) != 0) break;
4895
1.26M
            Feptr+= len;
4896
1.26M
            }
4897
77.3k
          break;
4898
4899
295k
          case OP_WHITESPACE:
4900
348k
          for (i = Lmin; i < Lmax; i++)
4901
300k
            {
4902
300k
            int len = 1;
4903
300k
            if (Feptr >= mb->end_subject)
4904
5.56k
              {
4905
5.56k
              SCHECK_PARTIAL();
4906
5.54k
              break;
4907
5.56k
              }
4908
294k
            GETCHARLEN(fc, Feptr, len);
4909
294k
            if (fc >= 256 ||(mb->ctypes[fc] & ctype_space) == 0) break;
4910
53.1k
            Feptr+= len;
4911
53.1k
            }
4912
295k
          break;
4913
4914
295k
          case OP_NOT_WORDCHAR:
4915
362k
          for (i = Lmin; i < Lmax; i++)
4916
315k
            {
4917
315k
            int len = 1;
4918
315k
            if (Feptr >= mb->end_subject)
4919
3.11k
              {
4920
3.11k
              SCHECK_PARTIAL();
4921
3.08k
              break;
4922
3.11k
              }
4923
312k
            GETCHARLEN(fc, Feptr, len);
4924
312k
            if (fc < 256 && (mb->ctypes[fc] & ctype_word) != 0) break;
4925
245k
            Feptr+= len;
4926
245k
            }
4927
117k
          break;
4928
4929
117k
          case OP_WORDCHAR:
4930
103k
          for (i = Lmin; i < Lmax; i++)
4931
98.4k
            {
4932
98.4k
            int len = 1;
4933
98.4k
            if (Feptr >= mb->end_subject)
4934
4.75k
              {
4935
4.75k
              SCHECK_PARTIAL();
4936
4.74k
              break;
4937
4.75k
              }
4938
93.6k
            GETCHARLEN(fc, Feptr, len);
4939
93.6k
            if (fc >= 256 || (mb->ctypes[fc] & ctype_word) == 0) break;
4940
34.2k
            Feptr+= len;
4941
34.2k
            }
4942
68.8k
          break;
4943
4944
          /* LCOV_EXCL_START */
4945
68.8k
          default:
4946
0
          PCRE2_DEBUG_UNREACHABLE();
4947
0
          return PCRE2_ERROR_INTERNAL;
4948
          /* LCOV_EXCL_STOP */
4949
1.28M
          }
4950
4951
1.28M
        if (reptype == REPTYPE_POS) continue;    /* No backtracking */
4952
4953
        /* After \C in UTF mode, Lstart_eptr might be in the middle of a
4954
        Unicode character. Use <= Lstart_eptr to ensure backtracking doesn't go
4955
        too far. */
4956
4957
485k
        for(;;)
4958
2.03M
          {
4959
2.03M
          if (Feptr <= Lstart_eptr) break;
4960
1.55M
          RMATCH(Fecode, RM220);
4961
1.55M
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4962
1.54M
          Feptr--;
4963
1.54M
          BACKCHAR(Feptr);
4964
1.54M
          if (Lctype == OP_ANYNL && Feptr > Lstart_eptr &&
4965
4.62k
              *Feptr == CHAR_NL && Feptr[-1] == CHAR_CR)
4966
1.00k
            Feptr--;
4967
1.54M
          }
4968
485k
        }
4969
3.27M
      else
4970
3.27M
#endif  /* SUPPORT_UNICODE */
4971
4972
      /* Not UTF mode */
4973
3.27M
        {
4974
3.27M
        switch(Lctype)
4975
3.27M
          {
4976
119k
          case OP_ANY:
4977
3.69M
          for (i = Lmin; i < Lmax; i++)
4978
3.66M
            {
4979
3.66M
            if (Feptr >= mb->end_subject)
4980
77.4k
              {
4981
77.4k
              SCHECK_PARTIAL();
4982
77.1k
              break;
4983
77.4k
              }
4984
3.58M
            if (IS_NEWLINE(Feptr)) break;
4985
3.57M
            if (mb->partial != 0 &&    /* Take care with CRLF partial */
4986
317k
                Feptr + 1 >= mb->end_subject &&
4987
7.34k
                NLBLOCK->nltype == NLTYPE_FIXED &&
4988
7.34k
                NLBLOCK->nllen == 2 &&
4989
0
                *Feptr == NLBLOCK->nl[0])
4990
0
              {
4991
0
              mb->hitend = TRUE;
4992
0
              if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
4993
0
              }
4994
3.57M
            Feptr++;
4995
3.57M
            }
4996
118k
          break;
4997
4998
118k
          case OP_ALLANY:
4999
75.3k
          case OP_ANYBYTE:
5000
75.3k
          fc = Lmax - Lmin;
5001
75.3k
          if (fc > (uint32_t)(mb->end_subject - Feptr))
5002
61.4k
            {
5003
61.4k
            Feptr = mb->end_subject;
5004
61.4k
            SCHECK_PARTIAL();
5005
61.4k
            }
5006
13.9k
          else Feptr += fc;
5007
75.2k
          break;
5008
5009
129k
          case OP_ANYNL:
5010
171k
          for (i = Lmin; i < Lmax; i++)
5011
164k
            {
5012
164k
            if (Feptr >= mb->end_subject)
5013
7.95k
              {
5014
7.95k
              SCHECK_PARTIAL();
5015
7.92k
              break;
5016
7.95k
              }
5017
156k
            fc = *Feptr;
5018
156k
            if (fc == CHAR_CR)
5019
18.0k
              {
5020
18.0k
              if (++Feptr >= mb->end_subject) break;
5021
17.0k
              if (*Feptr == CHAR_LF) Feptr++;
5022
17.0k
              }
5023
138k
            else
5024
138k
              {
5025
138k
              if (fc != CHAR_LF && (mb->bsr_convention == PCRE2_BSR_ANYCRLF ||
5026
128k
                 (fc != CHAR_VT && fc != CHAR_FF && fc != CHAR_NEL
5027
#if PCRE2_CODE_UNIT_WIDTH != 8
5028
                 && fc != 0x2028 && fc != 0x2029
5029
#endif
5030
128k
                 ))) break;
5031
25.0k
              Feptr++;
5032
25.0k
              }
5033
156k
            }
5034
129k
          break;
5035
5036
131k
          case OP_NOT_HSPACE:
5037
5.15M
          for (i = Lmin; i < Lmax; i++)
5038
5.15M
            {
5039
5.15M
            if (Feptr >= mb->end_subject)
5040
66.5k
              {
5041
66.5k
              SCHECK_PARTIAL();
5042
66.2k
              break;
5043
66.5k
              }
5044
5.08M
            switch(*Feptr)
5045
5.08M
              {
5046
5.02M
              default: Feptr++; break;
5047
104k
              HSPACE_BYTE_CASES:
5048
#if PCRE2_CODE_UNIT_WIDTH != 8
5049
              HSPACE_MULTIBYTE_CASES:
5050
#endif
5051
104k
              goto ENDLOOP00;
5052
5.08M
              }
5053
5.08M
            }
5054
130k
          ENDLOOP00:
5055
130k
          break;
5056
5057
256k
          case OP_HSPACE:
5058
269k
          for (i = Lmin; i < Lmax; i++)
5059
260k
            {
5060
260k
            if (Feptr >= mb->end_subject)
5061
6.07k
              {
5062
6.07k
              SCHECK_PARTIAL();
5063
6.06k
              break;
5064
6.07k
              }
5065
254k
            switch(*Feptr)
5066
254k
              {
5067
241k
              default: goto ENDLOOP01;
5068
241k
              HSPACE_BYTE_CASES:
5069
#if PCRE2_CODE_UNIT_WIDTH != 8
5070
              HSPACE_MULTIBYTE_CASES:
5071
#endif
5072
32.3k
              Feptr++; break;
5073
254k
              }
5074
254k
            }
5075
256k
          ENDLOOP01:
5076
256k
          break;
5077
5078
60.0k
          case OP_NOT_VSPACE:
5079
1.05M
          for (i = Lmin; i < Lmax; i++)
5080
1.04M
            {
5081
1.04M
            if (Feptr >= mb->end_subject)
5082
10.8k
              {
5083
10.8k
              SCHECK_PARTIAL();
5084
10.7k
              break;
5085
10.8k
              }
5086
1.03M
            switch(*Feptr)
5087
1.03M
              {
5088
996k
              default: Feptr++; break;
5089
93.8k
              VSPACE_BYTE_CASES:
5090
#if PCRE2_CODE_UNIT_WIDTH != 8
5091
              VSPACE_MULTIBYTE_CASES:
5092
#endif
5093
93.8k
              goto ENDLOOP02;
5094
1.03M
              }
5095
1.03M
            }
5096
59.9k
          ENDLOOP02:
5097
59.9k
          break;
5098
5099
193k
          case OP_VSPACE:
5100
206k
          for (i = Lmin; i < Lmax; i++)
5101
201k
            {
5102
201k
            if (Feptr >= mb->end_subject)
5103
5.08k
              {
5104
5.08k
              SCHECK_PARTIAL();
5105
5.06k
              break;
5106
5.08k
              }
5107
196k
            switch(*Feptr)
5108
196k
              {
5109
184k
              default: goto ENDLOOP03;
5110
184k
              VSPACE_BYTE_CASES:
5111
#if PCRE2_CODE_UNIT_WIDTH != 8
5112
              VSPACE_MULTIBYTE_CASES:
5113
#endif
5114
36.3k
              Feptr++; break;
5115
196k
              }
5116
196k
            }
5117
193k
          ENDLOOP03:
5118
193k
          break;
5119
5120
546k
          case OP_NOT_DIGIT:
5121
17.0M
          for (i = Lmin; i < Lmax; i++)
5122
16.9M
            {
5123
16.9M
            if (Feptr >= mb->end_subject)
5124
61.1k
              {
5125
61.1k
              SCHECK_PARTIAL();
5126
61.0k
              break;
5127
61.1k
              }
5128
16.9M
            if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_digit) != 0)
5129
462k
              break;
5130
16.4M
            Feptr++;
5131
16.4M
            }
5132
546k
          break;
5133
5134
546k
          case OP_DIGIT:
5135
688k
          for (i = Lmin; i < Lmax; i++)
5136
684k
            {
5137
684k
            if (Feptr >= mb->end_subject)
5138
7.44k
              {
5139
7.44k
              SCHECK_PARTIAL();
5140
7.43k
              break;
5141
7.44k
              }
5142
677k
            if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_digit) == 0)
5143
497k
              break;
5144
179k
            Feptr++;
5145
179k
            }
5146
508k
          break;
5147
5148
508k
          case OP_NOT_WHITESPACE:
5149
23.4M
          for (i = Lmin; i < Lmax; i++)
5150
23.3M
            {
5151
23.3M
            if (Feptr >= mb->end_subject)
5152
89.5k
              {
5153
89.5k
              SCHECK_PARTIAL();
5154
89.4k
              break;
5155
89.5k
              }
5156
23.2M
            if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_space) != 0)
5157
179k
              break;
5158
23.1M
            Feptr++;
5159
23.1M
            }
5160
289k
          break;
5161
5162
630k
          case OP_WHITESPACE:
5163
825k
          for (i = Lmin; i < Lmax; i++)
5164
686k
            {
5165
686k
            if (Feptr >= mb->end_subject)
5166
102k
              {
5167
102k
              SCHECK_PARTIAL();
5168
102k
              break;
5169
102k
              }
5170
584k
            if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_space) == 0)
5171
389k
              break;
5172
195k
            Feptr++;
5173
195k
            }
5174
630k
          break;
5175
5176
630k
          case OP_NOT_WORDCHAR:
5177
956k
          for (i = Lmin; i < Lmax; i++)
5178
910k
            {
5179
910k
            if (Feptr >= mb->end_subject)
5180
8.91k
              {
5181
8.91k
              SCHECK_PARTIAL();
5182
8.87k
              break;
5183
8.91k
              }
5184
901k
            if (MAX_255(*Feptr) && (mb->ctypes[*Feptr] & ctype_word) != 0)
5185
123k
              break;
5186
777k
            Feptr++;
5187
777k
            }
5188
178k
          break;
5189
5190
178k
          case OP_WORDCHAR:
5191
242k
          for (i = Lmin; i < Lmax; i++)
5192
236k
            {
5193
236k
            if (Feptr >= mb->end_subject)
5194
8.27k
              {
5195
8.27k
              SCHECK_PARTIAL();
5196
8.25k
              break;
5197
8.27k
              }
5198
227k
            if (!MAX_255(*Feptr) || (mb->ctypes[*Feptr] & ctype_word) == 0)
5199
143k
              break;
5200
84.4k
            Feptr++;
5201
84.4k
            }
5202
158k
          break;
5203
5204
          /* LCOV_EXCL_START */
5205
158k
          default:
5206
0
          PCRE2_DEBUG_UNREACHABLE();
5207
0
          return PCRE2_ERROR_INTERNAL;
5208
          /* LCOV_EXCL_STOP */
5209
3.27M
          }
5210
5211
3.27M
        if (reptype == REPTYPE_POS) continue;    /* No backtracking */
5212
5213
1.12M
        for (;;)
5214
5.58M
          {
5215
5.58M
          if (Feptr == Lstart_eptr) break;
5216
4.50M
          RMATCH(Fecode, RM34);
5217
4.49M
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5218
4.46M
          Feptr--;
5219
4.46M
          if (Lctype == OP_ANYNL && Feptr > Lstart_eptr && *Feptr == CHAR_LF &&
5220
8.97k
              Feptr[-1] == CHAR_CR) Feptr--;
5221
4.46M
          }
5222
1.12M
        }
5223
7.33M
      }
5224
2.43M
    break;  /* End of repeat character type processing */
5225
5226
2.43M
#undef Lstart_eptr
5227
2.43M
#undef Lmin
5228
2.43M
#undef Lmax
5229
2.43M
#undef Lctype
5230
2.43M
#undef Lpropvalue
5231
5232
5233
    /* ===================================================================== */
5234
    /* Match a back reference, possibly repeatedly. Look past the end of the
5235
    item to see if there is repeat information following. The OP_REF and
5236
    OP_REFI opcodes are used for a reference to a numbered group or to a
5237
    non-duplicated named group. For a duplicated named group, OP_DNREF and
5238
    OP_DNREFI are used. In this case we must scan the list of groups to which
5239
    the name refers, and use the first one that is set. */
5240
5241
2.43M
#define Lstart    F->fields.ref_repeat.start
5242
4.14M
#define Loffset   F->fields.ref_repeat.offset
5243
2.43M
#define Llength   F->fields.ref_repeat.length
5244
2.43M
#define Lmin      F->fields.ref_repeat.min
5245
2.43M
#define Lmax      F->fields.ref_repeat.max
5246
2.43M
#define Lcaseless F->byte1
5247
2.43M
#define Lcaseopts F->byte2
5248
5249
2.43M
    case OP_DNREF:
5250
62.5k
    case OP_DNREFI:
5251
62.5k
    Lcaseless = (uint8_t)(Fop == OP_DNREFI);
5252
62.5k
    Lcaseopts = (uint8_t)((Fop == OP_DNREFI)? Fecode[1 + 2*IMM2_SIZE] : 0);
5253
62.5k
      {
5254
62.5k
      int count = GET2(Fecode, 1+IMM2_SIZE);
5255
62.5k
      PCRE2_SPTR slot = mb->name_table + GET2(Fecode, 1) * mb->name_entry_size;
5256
62.5k
      Fecode += 1 + 2*IMM2_SIZE + (Fop == OP_DNREFI? 1 : 0);
5257
5258
352k
      while (count-- > 0)
5259
294k
        {
5260
294k
        Loffset = (GET2(slot, 0) << 1) - 2;
5261
294k
        if (Loffset < Foffset_top && Fovector[Loffset] != PCRE2_UNSET) break;
5262
289k
        slot += mb->name_entry_size;
5263
289k
        }
5264
62.5k
      }
5265
62.5k
    goto REF_REPEAT;
5266
5267
648k
    case OP_REF:
5268
926k
    case OP_REFI:
5269
926k
    Lcaseless = (Fop == OP_REFI);
5270
926k
    Lcaseopts = (Fop == OP_REFI)? Fecode[1 + IMM2_SIZE] : 0;
5271
926k
    Loffset = (GET2(Fecode, 1) << 1) - 2;
5272
926k
    Fecode += 1 + IMM2_SIZE + (Fop == OP_REFI? 1 : 0);
5273
5274
    /* Set up for repetition, or handle the non-repeated case. The maximum and
5275
    minimum must be in the heap frame, but as they are short-term values, we
5276
    use temporary fields. */
5277
5278
989k
    REF_REPEAT:
5279
989k
    switch (*Fecode)
5280
989k
      {
5281
40.5k
      case OP_CRSTAR:
5282
55.5k
      case OP_CRMINSTAR:
5283
289k
      case OP_CRPLUS:
5284
410k
      case OP_CRMINPLUS:
5285
439k
      case OP_CRQUERY:
5286
446k
      case OP_CRMINQUERY:
5287
461k
      case OP_CRPOSSTAR:
5288
483k
      case OP_CRPOSPLUS:
5289
487k
      case OP_CRPOSQUERY:
5290
487k
      fc = *Fecode++ - OP_CRSTAR;
5291
487k
      Lmin = rep_min[fc];
5292
487k
      Lmax = rep_max[fc];
5293
487k
      reptype = rep_typ[fc];
5294
487k
      break;
5295
5296
48.6k
      case OP_CRRANGE:
5297
49.0k
      case OP_CRMINRANGE:
5298
72.5k
      case OP_CRPOSRANGE:
5299
72.5k
      Lmin = GET2(Fecode, 1);
5300
72.5k
      Lmax = GET2(Fecode, 1 + IMM2_SIZE);
5301
72.5k
      reptype = rep_typ[*Fecode - OP_CRSTAR];
5302
72.5k
      if (Lmax == 0) Lmax = UINT32_MAX;  /* Max 0 => infinity */
5303
72.5k
      Fecode += 1 + 2 * IMM2_SIZE;
5304
72.5k
      break;
5305
5306
429k
      default:                  /* No repeat follows */
5307
429k
        {
5308
429k
        rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &length);
5309
429k
        if (rrc != 0)
5310
374k
          {
5311
374k
          if (rrc > 0) Feptr = mb->end_subject;   /* Partial match */
5312
374k
          CHECK_PARTIAL();
5313
374k
          RRETURN(MATCH_NOMATCH);
5314
374k
          }
5315
429k
        }
5316
54.4k
      Feptr += length;
5317
54.4k
      continue;              /* With the main loop */
5318
989k
      }
5319
5320
    /* Handle repeated back references. If a set group has length zero, just
5321
    continue with the main loop, because it matches however many times. For an
5322
    unset reference, if the minimum is zero, we can also just continue. We can
5323
    also continue if PCRE2_MATCH_UNSET_BACKREF is set, because this makes unset
5324
    group behave as a zero-length group. For any other unset cases, carrying
5325
    on will result in NOMATCH. */
5326
5327
560k
    if (Loffset < Foffset_top && Fovector[Loffset] != PCRE2_UNSET)
5328
214k
      {
5329
214k
      if (Fovector[Loffset] == Fovector[Loffset + 1]) continue;
5330
214k
      }
5331
345k
    else  /* Group is not set */
5332
345k
      {
5333
345k
      if (Lmin == 0 || (mb->poptions & PCRE2_MATCH_UNSET_BACKREF) != 0)
5334
72.8k
        continue;
5335
345k
      }
5336
5337
    /* First, ensure the minimum number of matches are present. */
5338
5339
440k
    for (i = 1; i <= Lmin; i++)
5340
362k
      {
5341
362k
      PCRE2_SIZE slength;
5342
362k
      rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength);
5343
362k
      if (rrc != 0)
5344
359k
        {
5345
359k
        if (rrc > 0) Feptr = mb->end_subject;   /* Partial match */
5346
359k
        CHECK_PARTIAL();
5347
359k
        RRETURN(MATCH_NOMATCH);
5348
359k
        }
5349
3.47k
      Feptr += slength;
5350
3.47k
      }
5351
5352
    /* If min = max, we are done. They are not both allowed to be zero. */
5353
5354
77.7k
    if (Lmin == Lmax) continue;
5355
5356
    /* If minimizing, keep trying and advancing the pointer. */
5357
5358
77.4k
    if (reptype == REPTYPE_MIN)
5359
20.8k
      {
5360
20.8k
      for (;;)
5361
28.2k
        {
5362
28.2k
        PCRE2_SIZE slength;
5363
28.2k
        RMATCH(Fecode, RM20);
5364
28.1k
        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5365
27.6k
        if (Lmin++ >= Lmax) RRETURN(MATCH_NOMATCH);
5366
26.7k
        rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength);
5367
26.7k
        if (rrc != 0)
5368
19.3k
          {
5369
19.3k
          if (rrc > 0) Feptr = mb->end_subject;   /* Partial match */
5370
19.3k
          CHECK_PARTIAL();
5371
19.3k
          RRETURN(MATCH_NOMATCH);
5372
19.3k
          }
5373
7.40k
        Feptr += slength;
5374
7.40k
        }
5375
5376
20.8k
      PCRE2_UNREACHABLE(); /* Control never reaches here */
5377
20.8k
      }
5378
5379
    /* If maximizing, find the longest string and work backwards, as long as
5380
    the matched lengths for each iteration are the same. */
5381
5382
56.5k
    else
5383
56.5k
      {
5384
56.5k
      BOOL samelengths = TRUE;
5385
56.5k
      Lstart = Feptr;     /* Starting position */
5386
56.5k
      Llength = Fovector[Loffset+1] - Fovector[Loffset];
5387
5388
283k
      for (i = Lmin; i < Lmax; i++)
5389
283k
        {
5390
283k
        PCRE2_SIZE slength;
5391
283k
        rrc = match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength);
5392
283k
        if (rrc != 0)
5393
55.8k
          {
5394
          /* Can't use CHECK_PARTIAL because we don't want to update Feptr in
5395
          the soft partial matching case. */
5396
5397
55.8k
          if (rrc > 0 && mb->partial != 0 &&
5398
781
              mb->end_subject > mb->start_used_ptr)
5399
781
            {
5400
781
            mb->hitend = TRUE;
5401
781
            if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
5402
781
            }
5403
55.8k
          break;
5404
55.8k
          }
5405
5406
227k
        if (slength != Llength) samelengths = FALSE;
5407
227k
        Feptr += slength;
5408
227k
        }
5409
5410
      /* No recursion if the repeat type is possessive. */
5411
56.5k
      if (reptype == REPTYPE_POS) break;
5412
5413
      /* If the length matched for each repetition is the same as the length of
5414
      the captured group, we can easily work backwards. This is the normal
5415
      case. However, in caseless UTF-8 mode there are pairs of case-equivalent
5416
      characters whose lengths (in terms of code units) differ. However, this
5417
      is very rare, so we handle it by re-matching fewer and fewer times. */
5418
5419
47.2k
      if (samelengths)
5420
45.9k
        {
5421
90.6k
        while (Feptr >= Lstart)
5422
49.4k
          {
5423
49.4k
          RMATCH(Fecode, RM21);
5424
49.3k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5425
44.7k
          Feptr -= Llength;
5426
44.7k
          }
5427
45.9k
        }
5428
5429
      /* The rare case of non-matching lengths. Re-scan the repetition for each
5430
      iteration. We know that match_ref() will succeed every time. */
5431
5432
1.30k
      else
5433
1.30k
        {
5434
1.30k
        Lmax = i;
5435
1.30k
        for (;;)
5436
3.11k
          {
5437
3.11k
          RMATCH(Fecode, RM22);
5438
3.11k
          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5439
2.28k
          if (Feptr == Lstart) break; /* Failed after minimal repetition */
5440
1.81k
          Feptr = Lstart;
5441
1.81k
          Lmax--;
5442
7.32k
          for (i = Lmin; i < Lmax; i++)
5443
5.51k
            {
5444
5.51k
            PCRE2_SIZE slength;
5445
5.51k
            (void)match_ref(Loffset, Lcaseless, Lcaseopts, F, mb, &slength);
5446
5.51k
            Feptr += slength;
5447
5.51k
            }
5448
1.81k
          }
5449
1.30k
        }
5450
5451
41.6k
      RRETURN(MATCH_NOMATCH);
5452
41.6k
      }
5453
5454
0
    PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */
5455
5456
0
#undef Lstart
5457
0
#undef Loffset
5458
0
#undef Llength
5459
0
#undef Lmin
5460
0
#undef Lmax
5461
0
#undef Lcaseless
5462
0
#undef Lcaseopts
5463
5464
5465
/* ========================================================================= */
5466
/*           Opcodes for the start of various parenthesized items            */
5467
/* ========================================================================= */
5468
5469
    /* In all cases, if the result of RMATCH() is MATCH_THEN, check whether the
5470
    (*THEN) is within the current branch by comparing the address of OP_THEN
5471
    that is passed back with the end of the branch. If (*THEN) is within the
5472
    current branch, and the branch is one of two or more alternatives (it
5473
    either starts or ends with OP_ALT), we have reached the limit of THEN's
5474
    action, so convert the return code to NOMATCH, which will cause normal
5475
    backtracking to happen from now on. Otherwise, THEN is passed back to an
5476
    outer alternative. This implements Perl's treatment of parenthesized
5477
    groups, where a group not containing | does not affect the current
5478
    alternative, that is, (X) is NOT the same as (X|(*F)). */
5479
5480
5481
    /* ===================================================================== */
5482
    /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a non-possessive
5483
    bracket group, indicating that it may occur zero times. It may repeat
5484
    infinitely, or not at all - i.e. it could be ()* or ()? or even (){0} in
5485
    the pattern. Brackets with fixed upper repeat limits are compiled as a
5486
    number of copies, with the optional ones preceded by BRAZERO or BRAMINZERO.
5487
    Possessive groups with possible zero repeats are preceded by BRAPOSZERO. */
5488
5489
267k
    case OP_BRAZERO:
5490
267k
      {
5491
267k
      PCRE2_SPTR next_ecode;
5492
5493
267k
      Fecode++;
5494
267k
      RMATCH(Fecode, RM9);
5495
203k
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5496
198k
      next_ecode = Fecode;
5497
327k
      do next_ecode += GET(next_ecode, 1); while (*next_ecode == OP_ALT);
5498
198k
      Fecode = next_ecode + 1 + LINK_SIZE;
5499
198k
      }
5500
0
    break;
5501
5502
45.9k
    case OP_BRAMINZERO:
5503
45.9k
      {
5504
45.9k
      PCRE2_SPTR next_ecode;
5505
5506
45.9k
      Fecode++;
5507
45.9k
      next_ecode = Fecode;
5508
76.9k
      do next_ecode += GET(next_ecode, 1); while (*next_ecode == OP_ALT);
5509
45.9k
      RMATCH(next_ecode + 1 + LINK_SIZE, RM10);
5510
44.7k
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5511
44.7k
      }
5512
42.2k
    break;
5513
5514
42.2k
    case OP_SKIPZERO:
5515
6.51k
      {
5516
6.51k
      PCRE2_SPTR next_ecode = Fecode + 1;
5517
15.7k
      do next_ecode += GET(next_ecode, 1); while (*next_ecode == OP_ALT);
5518
6.51k
      Fecode = next_ecode + 1 + LINK_SIZE;
5519
6.51k
      }
5520
6.51k
    break;
5521
5522
5523
    /* ===================================================================== */
5524
    /* Handle possessive brackets with an unlimited repeat. The end of these
5525
    brackets will always be OP_KETRPOS, which returns MATCH_KETRPOS without
5526
    going further in the pattern. */
5527
5528
309k
#define Lstart_eptr    F->fields.op_brapos.start_eptr
5529
163k
#define Lstart_group   F->fields.op_brapos.start_group
5530
286k
#define Lframe_type    F->fields.op_brapos.frame_type
5531
414k
#define Lmatched_once  F->byte1
5532
133k
#define Lzero_allowed  F->byte2
5533
5534
49.9k
    case OP_BRAPOSZERO:
5535
49.9k
    Lzero_allowed = TRUE;                /* Zero repeat is allowed */
5536
49.9k
    Fecode += 1;
5537
49.9k
    if (*Fecode == OP_CBRAPOS || *Fecode == OP_SCBRAPOS)
5538
42.8k
      goto POSSESSIVE_CAPTURE;
5539
7.11k
    goto POSSESSIVE_NON_CAPTURE;
5540
5541
13.3k
    case OP_BRAPOS:
5542
23.3k
    case OP_SBRAPOS:
5543
23.3k
    Lzero_allowed = FALSE;               /* Zero repeat not allowed */
5544
5545
30.4k
    POSSESSIVE_NON_CAPTURE:
5546
30.4k
    Lframe_type = GF_NOCAPTURE;          /* Remembered frame type */
5547
30.4k
    goto POSSESSIVE_GROUP;
5548
5549
8.75k
    case OP_CBRAPOS:
5550
26.0k
    case OP_SCBRAPOS:
5551
26.0k
    Lzero_allowed = FALSE;               /* Zero repeat not allowed */
5552
5553
68.9k
    POSSESSIVE_CAPTURE:
5554
68.9k
    number = GET2(Fecode, 1+LINK_SIZE);
5555
68.9k
    Lframe_type = GF_CAPTURE | number;   /* Remembered frame type */
5556
5557
99.4k
    POSSESSIVE_GROUP:
5558
99.4k
    Lmatched_once = FALSE;               /* Never matched */
5559
99.4k
    Lstart_group = Fecode;               /* Start of this group */
5560
5561
99.4k
    for (;;)
5562
186k
      {
5563
186k
      Lstart_eptr = Feptr;               /* Position at group start */
5564
186k
      group_frame_type = Lframe_type;
5565
186k
      RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM8);
5566
184k
      if (rrc == MATCH_KETRPOS)
5567
122k
        {
5568
122k
        Lmatched_once = TRUE;            /* Matched at least once */
5569
122k
        if (Feptr == Lstart_eptr)        /* Empty match; skip to end */
5570
58.4k
          {
5571
195k
          do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT);
5572
58.4k
          break;
5573
58.4k
          }
5574
5575
64.1k
        Fecode = Lstart_group;
5576
64.1k
        continue;
5577
122k
        }
5578
5579
      /* See comment above about handling THEN. */
5580
5581
62.1k
      if (rrc == MATCH_THEN)
5582
1.70k
        {
5583
1.70k
        PCRE2_SPTR next_ecode = Fecode + GET(Fecode,1);
5584
1.70k
        if (mb->verb_ecode_ptr < next_ecode &&
5585
1.70k
            (*Fecode == OP_ALT || *next_ecode == OP_ALT))
5586
1.18k
          rrc = MATCH_NOMATCH;
5587
1.70k
        }
5588
5589
62.1k
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5590
61.0k
      Fecode += GET(Fecode, 1);
5591
61.0k
      if (*Fecode != OP_ALT) break;
5592
61.0k
      }
5593
5594
    /* Success if matched something or zero repeat allowed */
5595
5596
96.3k
    if (Lmatched_once || Lzero_allowed)
5597
76.7k
      {
5598
76.7k
      Fecode += 1 + LINK_SIZE;
5599
76.7k
      break;
5600
76.7k
      }
5601
5602
19.5k
    RRETURN(MATCH_NOMATCH);
5603
5604
0
#undef Lstart_eptr
5605
0
#undef Lstart_group
5606
0
#undef Lframe_type
5607
0
#undef Lmatched_once
5608
0
#undef Lzero_allowed
5609
5610
5611
    /* ===================================================================== */
5612
    /* Handle non-capturing brackets that cannot match an empty string. When we
5613
    get to the final alternative within the brackets, as long as there are no
5614
    THEN's in the pattern, we can optimize by not recording a new backtracking
5615
    point. (Ideally we should test for a THEN within this group, but we don't
5616
    have that information.) Don't do this if we are at the very top level,
5617
    however, because that would make handling assertions and once-only brackets
5618
    messier when there is nothing to go back to. */
5619
5620
39.2M
#define Lframe_type    F->fields.op_bra.frame_type
5621
5622
12.0M
    case OP_BRA:
5623
12.0M
    if (mb->hasthen || Frdepth == 0)
5624
5.08M
      {
5625
5.08M
      Lframe_type = 0;
5626
5.08M
      goto GROUPLOOP;
5627
5.08M
      }
5628
5629
6.94M
    for (;;)
5630
7.22M
      {
5631
7.22M
      PCRE2_SPTR current_branch = Fecode;
5632
7.22M
      PCRE2_SPTR next_branch = current_branch + GET(current_branch, 1);
5633
5634
7.22M
      if (*next_branch != OP_ALT) break;
5635
5636
      /* This is never the final branch. We do not need to test for MATCH_THEN
5637
      here because this code is not used when there is a THEN in the pattern. */
5638
5639
296k
      Fecode = next_branch;
5640
296k
      PCRE2_ASSERT((*current_branch == OP_BRA || *current_branch == OP_ALT) &&
5641
296k
                   PRIV(OP_lengths)[OP_BRA] == 1 + LINK_SIZE &&
5642
296k
                   PRIV(OP_lengths)[OP_ALT] == 1 + LINK_SIZE);
5643
5644
296k
      RMATCH(current_branch + 1 + LINK_SIZE, RM1);
5645
282k
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5646
282k
      }
5647
5648
    /* Hit the start of the final branch. Continue at this level. */
5649
5650
6.92M
    PCRE2_ASSERT((*Fecode == OP_BRA || *Fecode == OP_ALT) &&
5651
6.92M
                 PRIV(OP_lengths)[OP_BRA] == 1 + LINK_SIZE &&
5652
6.92M
                 PRIV(OP_lengths)[OP_ALT] == 1 + LINK_SIZE);
5653
6.92M
    Fecode += 1 + LINK_SIZE;
5654
6.92M
    break;
5655
5656
5657
    /* ===================================================================== */
5658
    /* Handle a capturing bracket, other than those that are possessive with an
5659
    unlimited repeat. */
5660
5661
1.56M
    case OP_CBRA:
5662
1.68M
    case OP_SCBRA:
5663
1.68M
    Lframe_type = GF_CAPTURE | GET2(Fecode, 1+LINK_SIZE);
5664
1.68M
    goto GROUPLOOP;
5665
5666
5667
    /* ===================================================================== */
5668
    /* Atomic groups and non-capturing brackets that can match an empty string
5669
    must record a backtracking point and also set up a chained frame. */
5670
5671
350k
    case OP_ONCE:
5672
407k
    case OP_SCRIPT_RUN:
5673
500k
    case OP_SBRA:
5674
500k
    Lframe_type = GF_NOCAPTURE;
5675
5676
7.26M
    GROUPLOOP:
5677
7.26M
    for (;;)
5678
31.9M
      {
5679
31.9M
      group_frame_type = Lframe_type;
5680
31.9M
      RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM2);
5681
31.7M
      if (rrc == MATCH_THEN)
5682
85.8k
        {
5683
85.8k
        PCRE2_SPTR next_ecode = Fecode + GET(Fecode,1);
5684
85.8k
        if (mb->verb_ecode_ptr < next_ecode &&
5685
77.5k
            (*Fecode == OP_ALT || *next_ecode == OP_ALT))
5686
73.7k
          rrc = MATCH_NOMATCH;
5687
85.8k
        }
5688
31.7M
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5689
31.2M
      Fecode += GET(Fecode, 1);
5690
31.2M
      if (*Fecode != OP_ALT) RRETURN(MATCH_NOMATCH);
5691
31.2M
      }
5692
7.26M
    PCRE2_UNREACHABLE(); /* Control never reaches here */
5693
5694
0
#undef Lframe_type
5695
5696
5697
    /* ===================================================================== */
5698
    /* Pattern recursion either matches the current regex, or some
5699
    subexpression. The offset data is the offset to the starting bracket from
5700
    the start of the whole pattern. This is so that it works from duplicated
5701
    subpatterns. For a whole-pattern recursion, we have to infer the number
5702
    zero. */
5703
5704
1.82M
#define Lstart_branch  F->fields.op_recurse.start_branch
5705
1.07M
#define Lframe_type    F->fields.op_recurse.frame_type
5706
5707
412k
    case OP_RECURSE:
5708
412k
    bracode = mb->start_code + GET(Fecode, 1);
5709
412k
    number = (bracode == mb->start_code)? 0 : GET2(bracode, 1 + LINK_SIZE);
5710
5711
    /* If we are already in a pattern recursion, check for repeating the same
5712
    one without changing the subject pointer or the last referenced character
5713
    in the subject. This should catch convoluted mutual recursions; some
5714
    simple cases are caught at compile time. However, there are rare cases when
5715
    this check needs to be turned off. In this case, actual recursion loops
5716
    will be caught by the match or heap limits. */
5717
5718
412k
    if (Fcurrent_recurse != RECURSE_UNSET)
5719
254k
      {
5720
254k
      offset = Flast_group_offset;
5721
296k
      while (offset != PCRE2_UNSET)
5722
295k
        {
5723
295k
        N = (heapframe *)((char *)match_data->heapframes + offset);
5724
295k
        P = (heapframe *)((char *)N - frame_size);
5725
295k
        if (N->group_frame_type == (GF_RECURSE | number))
5726
253k
          {
5727
253k
          if (Feptr == P->eptr && mb->last_used_ptr == P->recurse_last_used &&
5728
159k
               (mb->moptions & PCRE2_DISABLE_RECURSELOOP_CHECK) == 0)
5729
0
            return PCRE2_ERROR_RECURSELOOP;
5730
253k
          break;
5731
253k
          }
5732
42.1k
        offset = P->last_group_offset;
5733
42.1k
        }
5734
254k
      }
5735
5736
    /* Remember the current last referenced character and then run the
5737
    recursion branch by branch. */
5738
5739
412k
    F->recurse_last_used = mb->last_used_ptr;
5740
412k
    Lstart_branch = bracode;
5741
412k
    Lframe_type = GF_RECURSE | number;
5742
5743
412k
    for (;;)
5744
656k
      {
5745
656k
      PCRE2_SPTR next_ecode;
5746
5747
656k
      group_frame_type = Lframe_type;
5748
656k
      RMATCH(Lstart_branch + PRIV(OP_lengths)[*Lstart_branch], RM11);
5749
479k
      next_ecode = Lstart_branch + GET(Lstart_branch,1);
5750
5751
      /* Handle backtracking verbs, which are defined in a range that can
5752
      easily be tested for. PCRE does not allow THEN, SKIP, PRUNE or COMMIT to
5753
      escape beyond a recursion; they cause a NOMATCH for the entire recursion.
5754
5755
      When one of these verbs triggers, the current recursion group number is
5756
      recorded. If it matches the recursion we are processing, the verb
5757
      happened within the recursion and we must deal with it. Otherwise it must
5758
      have happened after the recursion completed, and so has to be passed
5759
      back. See comment above about handling THEN. */
5760
5761
479k
      if (rrc >= MATCH_BACKTRACK_MIN && rrc <= MATCH_BACKTRACK_MAX &&
5762
8.30k
          mb->verb_current_recurse == (Lframe_type ^ GF_RECURSE))
5763
7.80k
        {
5764
7.80k
        if (rrc == MATCH_THEN && mb->verb_ecode_ptr < next_ecode &&
5765
5.59k
            (*Lstart_branch == OP_ALT || *next_ecode == OP_ALT))
5766
1.71k
          rrc = MATCH_NOMATCH;
5767
6.09k
        else RRETURN(MATCH_NOMATCH);
5768
7.80k
        }
5769
5770
      /* Note that carrying on after (*ACCEPT) in a recursion is handled in the
5771
      OP_ACCEPT code. Nothing needs to be done here. */
5772
5773
473k
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
5774
465k
      Lstart_branch = next_ecode;
5775
465k
      if (*Lstart_branch != OP_ALT) RRETURN(MATCH_NOMATCH);
5776
465k
      }
5777
412k
    PCRE2_UNREACHABLE(); /* Control never reaches here */
5778
5779
0
#undef Lstart_branch
5780
0
#undef Lframe_type
5781
5782
5783
    /* ===================================================================== */
5784
    /* Positive assertions are like other groups except that PCRE doesn't allow
5785
    the effect of (*THEN) to escape beyond an assertion; it is therefore
5786
    treated as NOMATCH. (*ACCEPT) is treated as successful assertion, with its
5787
    captures and mark retained. Any other return is an error. */
5788
5789
300k
    case OP_ASSERT:
5790
365k
    case OP_ASSERTBACK:
5791
451k
    case OP_ASSERT_NA:
5792
466k
    case OP_ASSERTBACK_NA:
5793
466k
    for (;;)
5794
889k
      {
5795
889k
      group_frame_type = GF_NOCAPTURE;
5796
889k
      RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM3);
5797
843k
      if (rrc == MATCH_ACCEPT)
5798
4.89k
        {
5799
4.89k
        memcpy(Fovector,
5800
4.89k
              (char *)assert_accept_frame + offsetof(heapframe, ovector),
5801
4.89k
              assert_accept_frame->offset_top * sizeof(PCRE2_SIZE));
5802
4.89k
        Foffset_top = assert_accept_frame->offset_top;
5803
4.89k
        Fmark = assert_accept_frame->mark;
5804
4.89k
        break;
5805
4.89k
        }
5806
838k
      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
5807
808k
      Fecode += GET(Fecode, 1);
5808
808k
      if (*Fecode != OP_ALT) RRETURN(MATCH_NOMATCH);
5809
808k
      }
5810
5811
14.0k
    do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT);
5812
4.89k
    Fecode += 1 + LINK_SIZE;
5813
4.89k
    break;
5814
5815
5816
    /* ===================================================================== */
5817
    /* Handle negative assertions. Loop for each non-matching branch as for
5818
    positive assertions. */
5819
5820
411k
    case OP_ASSERT_NOT:
5821
467k
    case OP_ASSERTBACK_NOT:
5822
467k
    for (;;)
5823
619k
      {
5824
619k
      group_frame_type = GF_NOCAPTURE;
5825
619k
      RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM4);
5826
615k
      switch(rrc)
5827
615k
        {
5828
919
        case MATCH_ACCEPT:   /* Assertion matched, therefore it fails. */
5829
31.2k
        case MATCH_MATCH:
5830
31.2k
        RRETURN (MATCH_NOMATCH);
5831
5832
573k
        case MATCH_NOMATCH:  /* Branch failed, try next if present. */
5833
575k
        case MATCH_THEN:
5834
575k
        Fecode += GET(Fecode, 1);
5835
575k
        if (*Fecode != OP_ALT) goto ASSERT_NOT_FAILED;
5836
151k
        break;
5837
5838
151k
        case MATCH_COMMIT:   /* Assertion forced to fail, therefore continue. */
5839
2.35k
        case MATCH_SKIP:
5840
7.15k
        case MATCH_PRUNE:
5841
14.4k
        do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT);
5842
7.15k
        goto ASSERT_NOT_FAILED;
5843
5844
1.56k
        default:             /* Pass back any other return */
5845
1.56k
        RRETURN(rrc);
5846
615k
        }
5847
615k
      }
5848
5849
    /* None of the branches have matched or there was a backtrack to (*COMMIT),
5850
    (*SKIP), (*PRUNE), or (*THEN) in the last branch. This is success for a
5851
    negative assertion, so carry on. */
5852
5853
430k
    ASSERT_NOT_FAILED:
5854
430k
    Fecode += 1 + LINK_SIZE;
5855
430k
    break;
5856
5857
5858
    /* ===================================================================== */
5859
    /* Handle scan substring operation. */
5860
5861
100k
#define Lsaved_end_subject   F->fields.op_assert_scs.saved_end_subject
5862
50.5k
#define Lsaved_eptr          F->fields.op_assert_scs.saved_eptr
5863
100k
#define Ltrue_end_extra      F->fields.op_assert_scs.true_end_extra
5864
0
#define Lextra_size          F->fields.op_assert_scs.extra_size
5865
100k
#define Lsaved_moptions      F->fields.op_assert_scs.saved_moptions
5866
5867
95.4k
    case OP_ASSERT_SCS:
5868
95.4k
    length = 0;
5869
95.4k
      {
5870
95.4k
      PCRE2_SPTR ecode = Fecode + 1 + LINK_SIZE;
5871
95.4k
      int count;
5872
95.4k
      PCRE2_SPTR slot;
5873
5874
      /* Disable compiler warning. */
5875
95.4k
      offset = 0;
5876
95.4k
      (void)offset;
5877
5878
95.4k
      for (;;)
5879
154k
        {
5880
154k
        if (*ecode == OP_CREF)
5881
69.9k
          {
5882
69.9k
          length += 1+IMM2_SIZE;
5883
69.9k
          offset = (GET2(ecode, 1) << 1) - 2;
5884
69.9k
          ecode += 1+IMM2_SIZE;
5885
69.9k
          if (offset < Foffset_top && Fovector[offset] != PCRE2_UNSET)
5886
35.1k
            goto SCS_OFFSET_FOUND;
5887
34.8k
          continue;
5888
69.9k
          }
5889
5890
84.5k
        if (*ecode != OP_DNCREF) RRETURN(MATCH_NOMATCH);
5891
5892
39.2k
        count = GET2(ecode, 1 + IMM2_SIZE);
5893
39.2k
        slot = mb->name_table + GET2(ecode, 1) * mb->name_entry_size;
5894
39.2k
        length += 1+2*IMM2_SIZE;
5895
39.2k
        ecode += 1+2*IMM2_SIZE;
5896
5897
105k
        while (count > 0)
5898
81.3k
          {
5899
81.3k
          offset = (GET2(slot, 0) << 1) - 2;
5900
81.3k
          if (offset < Foffset_top && Fovector[offset] != PCRE2_UNSET)
5901
15.0k
            goto SCS_OFFSET_FOUND;
5902
66.2k
          slot += mb->name_entry_size;
5903
66.2k
          count--;
5904
66.2k
          }
5905
39.2k
        }
5906
5907
50.1k
      SCS_OFFSET_FOUND:
5908
5909
      /* Skip remaining options. */
5910
50.1k
      for (;;)
5911
58.8k
        {
5912
58.8k
        if (*ecode == OP_CREF)
5913
8.70k
          {
5914
8.70k
          length += 1+IMM2_SIZE;
5915
8.70k
          ecode += 1+IMM2_SIZE;
5916
8.70k
          }
5917
50.1k
        else if (*ecode == OP_DNCREF)
5918
0
          {
5919
0
          length += 1+2*IMM2_SIZE;
5920
0
          ecode += 1+2*IMM2_SIZE;
5921
0
          }
5922
50.1k
        else break;
5923
58.8k
        }
5924
50.1k
      }
5925
5926
50.1k
    Lsaved_end_subject = mb->end_subject;
5927
50.1k
    Ltrue_end_extra = mb->true_end_subject - mb->end_subject;
5928
50.1k
    Lsaved_eptr = Feptr;
5929
50.1k
    Lsaved_moptions = mb->moptions;
5930
5931
50.1k
    Feptr = mb->start_subject + Fovector[offset];
5932
50.1k
    mb->true_end_subject = mb->end_subject =
5933
50.1k
      mb->start_subject + Fovector[offset + 1];
5934
50.1k
    mb->moptions &= ~PCRE2_NOTEOL;
5935
5936
50.1k
    for (;;)
5937
107k
      {
5938
107k
      group_frame_type = GF_NOCAPTURE;
5939
107k
      RMATCH(Fecode + 1 + LINK_SIZE + length, RM38);
5940
107k
      if (rrc == MATCH_ACCEPT)
5941
453
        {
5942
453
        memcpy(Fovector,
5943
453
              (char *)assert_accept_frame + offsetof(heapframe, ovector),
5944
453
              assert_accept_frame->offset_top * sizeof(PCRE2_SIZE));
5945
453
        Foffset_top = assert_accept_frame->offset_top;
5946
453
        Fmark = assert_accept_frame->mark;
5947
453
        mb->end_subject = Lsaved_end_subject;
5948
453
        mb->true_end_subject = mb->end_subject + Ltrue_end_extra;
5949
453
        mb->moptions = Lsaved_moptions;
5950
453
        break;
5951
453
        }
5952
5953
106k
      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
5954
788
        {
5955
788
        mb->end_subject = Lsaved_end_subject;
5956
788
        mb->true_end_subject = mb->end_subject + Ltrue_end_extra;
5957
788
        mb->moptions = Lsaved_moptions;
5958
788
        RRETURN(rrc);
5959
788
        }
5960
5961
106k
      Fecode += GET(Fecode, 1);
5962
106k
      if (*Fecode != OP_ALT)
5963
48.6k
        {
5964
48.6k
        mb->end_subject = Lsaved_end_subject;
5965
48.6k
        mb->true_end_subject = mb->end_subject + Ltrue_end_extra;
5966
48.6k
        mb->moptions = Lsaved_moptions;
5967
48.6k
        RRETURN(MATCH_NOMATCH);
5968
48.6k
        }
5969
57.3k
      length = 0;
5970
57.3k
      }
5971
5972
1.31k
    do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT);
5973
453
    Fecode += 1 + LINK_SIZE;
5974
453
    Feptr = Lsaved_eptr;
5975
453
    break;
5976
5977
0
#undef Lsaved_end_subject
5978
0
#undef Lsaved_eptr
5979
0
#undef Ltrue_end_extra
5980
0
#undef Lextra_size
5981
0
#undef Lsave_moptions
5982
5983
5984
    /* ===================================================================== */
5985
    /* The callout item calls an external function, if one is provided, passing
5986
    details of the match so far. This is mainly for debugging, though the
5987
    function is able to force a failure. */
5988
5989
1.02M
    case OP_CALLOUT:
5990
1.03M
    case OP_CALLOUT_STR:
5991
1.03M
    rrc = do_callout(F, mb, &length);
5992
1.03M
    if (rrc > 0) RRETURN(MATCH_NOMATCH);
5993
1.03M
    if (rrc < 0) RRETURN(rrc);
5994
1.02M
    Fecode += length;
5995
1.02M
    break;
5996
5997
5998
    /* ===================================================================== */
5999
    /* Conditional group: compilation checked that there are no more than two
6000
    branches. If the condition is false, skipping the first branch takes us
6001
    past the end of the item if there is only one branch, but that's exactly
6002
    what we want. */
6003
6004
2.93M
#define Lstart_branch  F->fields.op_cond.start_branch
6005
4.29M
#define Llength        F->fields.op_cond.length
6006
1.48M
#define Lpositive      F->byte1
6007
6008
883k
    case OP_COND:
6009
940k
    case OP_SCOND:
6010
6011
    /* The variable Llength will be added to Fecode when the condition is
6012
    false, to get to the second branch. Setting it to the offset to the ALT or
6013
    KET, then incrementing Fecode achieves this effect. However, if the second
6014
    branch is non-existent, we must point to the KET so that the end of the
6015
    group is correctly processed. We now have Fecode pointing to the condition
6016
    or callout. */
6017
6018
940k
    Llength = GET(Fecode, 1);    /* Offset to the second branch */
6019
940k
    if (Fecode[Llength] != OP_ALT) Llength -= 1 + LINK_SIZE;
6020
940k
    Fecode += 1 + LINK_SIZE;     /* From this opcode */
6021
6022
    /* Because of the way auto-callout works during compile, a callout item is
6023
    inserted between OP_COND and an assertion condition. Such a callout can
6024
    also be inserted manually. */
6025
6026
940k
    if (*Fecode == OP_CALLOUT || *Fecode == OP_CALLOUT_STR)
6027
4.47k
      {
6028
4.47k
      rrc = do_callout(F, mb, &length);
6029
4.47k
      if (rrc > 0) RRETURN(MATCH_NOMATCH);
6030
4.47k
      if (rrc < 0) RRETURN(rrc);
6031
6032
      /* Advance Fecode past the callout, so it now points to the condition. We
6033
      must adjust Llength so that the value of Fecode+Llength is unchanged. */
6034
6035
4.44k
      Fecode += length;
6036
4.44k
      Llength -= length;
6037
4.44k
      }
6038
6039
    /* Test the various possible conditions */
6040
6041
940k
    condition = FALSE;
6042
940k
    switch(*Fecode)
6043
940k
      {
6044
35.3k
      case OP_RREF:                  /* Group recursion test */
6045
35.3k
      if (Fcurrent_recurse != RECURSE_UNSET)
6046
15.4k
        {
6047
15.4k
        number = GET2(Fecode, 1);
6048
15.4k
        condition = (number == RREF_ANY || number == Fcurrent_recurse);
6049
15.4k
        }
6050
35.3k
      break;
6051
6052
9.63k
      case OP_DNRREF:       /* Duplicate named group recursion test */
6053
9.63k
      if (Fcurrent_recurse != RECURSE_UNSET)
6054
874
        {
6055
874
        int count = GET2(Fecode, 1 + IMM2_SIZE);
6056
874
        PCRE2_SPTR slot = mb->name_table + GET2(Fecode, 1) * mb->name_entry_size;
6057
2.76k
        while (count-- > 0)
6058
1.88k
          {
6059
1.88k
          number = GET2(slot, 0);
6060
1.88k
          condition = number == Fcurrent_recurse;
6061
1.88k
          if (condition) break;
6062
1.88k
          slot += mb->name_entry_size;
6063
1.88k
          }
6064
874
        }
6065
9.63k
      break;
6066
6067
11.2k
      case OP_CREF:                         /* Numbered group used test */
6068
11.2k
      offset = (GET2(Fecode, 1) << 1) - 2;  /* Doubled ref number */
6069
11.2k
      condition = offset < Foffset_top && Fovector[offset] != PCRE2_UNSET;
6070
11.2k
      break;
6071
6072
3.70k
      case OP_DNCREF:      /* Duplicate named group used test */
6073
3.70k
        {
6074
3.70k
        int count = GET2(Fecode, 1 + IMM2_SIZE);
6075
3.70k
        PCRE2_SPTR slot = mb->name_table + GET2(Fecode, 1) * mb->name_entry_size;
6076
10.7k
        while (count-- > 0)
6077
7.67k
          {
6078
7.67k
          offset = (GET2(slot, 0) << 1) - 2;
6079
7.67k
          condition = offset < Foffset_top && Fovector[offset] != PCRE2_UNSET;
6080
7.67k
          if (condition) break;
6081
7.02k
          slot += mb->name_entry_size;
6082
7.02k
          }
6083
3.70k
        }
6084
3.70k
      break;
6085
6086
10.1k
      case OP_FALSE:
6087
78.5k
      case OP_FAIL:   /* The assertion (?!) becomes OP_FAIL */
6088
78.5k
      break;
6089
6090
56.7k
      case OP_TRUE:
6091
56.7k
      condition = TRUE;
6092
56.7k
      break;
6093
6094
      /* The condition is an assertion. Run code similar to the assertion code
6095
      above. */
6096
6097
6098
744k
      default:
6099
744k
      Lpositive = (uint8_t)(*Fecode == OP_ASSERT || *Fecode == OP_ASSERTBACK);
6100
744k
      Lstart_branch = Fecode;
6101
6102
744k
      for (;;)
6103
1.11M
        {
6104
1.11M
        group_frame_type = GF_CONDASSERT;
6105
1.11M
        RMATCH(Lstart_branch + PRIV(OP_lengths)[*Lstart_branch], RM5);
6106
6107
1.11M
        switch(rrc)
6108
1.11M
          {
6109
393
          case MATCH_ACCEPT:  /* Save captures */
6110
393
          memcpy(Fovector,
6111
393
                (char *)assert_accept_frame + offsetof(heapframe, ovector),
6112
393
                assert_accept_frame->offset_top * sizeof(PCRE2_SIZE));
6113
393
          Foffset_top = assert_accept_frame->offset_top;
6114
6115
393
          PCRE2_FALLTHROUGH /* Fall through */
6116
          /* In the case of a match, the captures have already been put into
6117
          the current frame. */
6118
6119
15.3k
          case MATCH_MATCH:
6120
15.3k
          condition = Lpositive;   /* TRUE for positive assertion */
6121
15.3k
          break;
6122
6123
          /* PCRE doesn't allow the effect of (*THEN) to escape beyond an
6124
          assertion; it is therefore always treated as NOMATCH. */
6125
6126
1.08M
          case MATCH_NOMATCH:
6127
1.09M
          case MATCH_THEN:
6128
1.09M
          Lstart_branch += GET(Lstart_branch, 1);
6129
1.09M
          if (*Lstart_branch == OP_ALT) continue;  /* Try next branch */
6130
723k
          condition = !Lpositive;  /* TRUE for negative assertion */
6131
723k
          break;
6132
6133
          /* These force no match without checking other branches. */
6134
6135
684
          case MATCH_COMMIT:
6136
1.06k
          case MATCH_SKIP:
6137
1.95k
          case MATCH_PRUNE:
6138
1.95k
          condition = !Lpositive;
6139
1.95k
          break;
6140
6141
3.75k
          default:
6142
3.75k
          RRETURN(rrc);
6143
1.11M
          }
6144
740k
        break;  /* Out of the branch loop */
6145
1.11M
        }
6146
6147
      /* If the condition is true, find the end of the assertion so that
6148
      advancing past it gets us to the start of the first branch. */
6149
6150
740k
      if (condition)
6151
17.3k
        {
6152
51.2k
        do Fecode += GET(Fecode, 1); while (*Fecode == OP_ALT);
6153
17.3k
        }
6154
740k
      break;  /* End of assertion condition */
6155
940k
      }
6156
6157
    /* Choose branch according to the condition. */
6158
6159
935k
    Fecode += condition? PRIV(OP_lengths)[*Fecode] : Llength;
6160
6161
    /* If the opcode is OP_SCOND it means we are at a repeated conditional
6162
    group that might match an empty string. We must therefore descend a level
6163
    so that the start is remembered for checking. For OP_COND we can just
6164
    continue at this level. */
6165
6166
935k
    if (Fop == OP_SCOND)
6167
56.9k
      {
6168
56.9k
      group_frame_type = GF_NOCAPTURE;
6169
56.9k
      RMATCH(Fecode, RM35);
6170
56.9k
      RRETURN(rrc);
6171
56.9k
      }
6172
878k
    break;
6173
6174
878k
#undef Lstart_branch
6175
878k
#undef Llength
6176
878k
#undef Lpositive
6177
6178
6179
/* ========================================================================= */
6180
/*                  End of start of parenthesis opcodes                      */
6181
/* ========================================================================= */
6182
6183
6184
    /* ===================================================================== */
6185
    /* Move the subject pointer back by one fixed amount. This occurs at the
6186
    start of each branch that has a fixed length in a lookbehind assertion. If
6187
    we are too close to the start to move back, fail. When working with UTF-8
6188
    we move back a number of characters, not bytes. */
6189
6190
878k
    case OP_REVERSE:
6191
72.5k
    number = GET2(Fecode, 1);
6192
72.5k
#ifdef SUPPORT_UNICODE
6193
72.5k
    if (utf)
6194
18.8k
      {
6195
      /* We used to do a simpler `while (number-- > 0)` but that triggers
6196
      clang's unsigned integer overflow sanitizer. */
6197
325k
      while (number > 0)
6198
311k
        {
6199
311k
        --number;
6200
311k
        if (Feptr <= mb->check_subject) RRETURN(MATCH_NOMATCH);
6201
306k
        Feptr--;
6202
306k
        BACKCHAR(Feptr);
6203
306k
        }
6204
18.8k
      }
6205
53.6k
    else
6206
53.6k
#endif
6207
6208
    /* No UTF support, or not in UTF mode: count is code unit count */
6209
6210
53.6k
      {
6211
53.6k
      if ((ptrdiff_t)number > Feptr - mb->start_subject) RRETURN(MATCH_NOMATCH);
6212
38.9k
      Feptr -= number;
6213
38.9k
      }
6214
6215
    /* Save the earliest consulted character, then skip to next opcode */
6216
6217
52.5k
    if (Feptr < mb->start_used_ptr) mb->start_used_ptr = Feptr;
6218
52.5k
    Fecode += 1 + IMM2_SIZE;
6219
52.5k
    break;
6220
6221
6222
    /* ===================================================================== */
6223
    /* Move the subject pointer back by a variable amount. This occurs at the
6224
    start of each branch of a lookbehind assertion when the branch has a
6225
    variable, but limited, length. A loop is needed to try matching the branch
6226
    after moving back different numbers of characters. If we are too close to
6227
    the start to move back even the minimum amount, fail. When working with
6228
    UTF-8 we move back a number of characters, not bytes. */
6229
6230
940k
#define Lmin    F->fields.op_vreverse.min
6231
1.10M
#define Lmax    F->fields.op_vreverse.max
6232
6233
80.7k
    case OP_VREVERSE:
6234
80.7k
    Lmin = GET2(Fecode, 1);
6235
80.7k
    Lmax = GET2(Fecode, 1 + IMM2_SIZE);
6236
6237
    /* Move back by the maximum branch length and then work forwards. This
6238
    ensures that items such as \d{3,5} get the maximum length, which is
6239
    relevant for captures, and makes for Perl compatibility. */
6240
6241
80.7k
#ifdef SUPPORT_UNICODE
6242
80.7k
    if (utf)
6243
13.9k
      {
6244
104k
      for (i = 0; i < Lmax; i++)
6245
94.1k
        {
6246
94.1k
        if (Feptr <= mb->check_subject)
6247
3.64k
          {
6248
3.64k
          if (i < Lmin) RRETURN(MATCH_NOMATCH);
6249
1.29k
          Lmax = i;
6250
1.29k
          break;
6251
3.64k
          }
6252
90.4k
        Feptr--;
6253
90.4k
        BACKCHAR(Feptr);
6254
90.4k
        }
6255
13.9k
      }
6256
66.8k
    else
6257
66.8k
#endif
6258
6259
    /* No UTF support or not in UTF mode */
6260
6261
66.8k
      {
6262
66.8k
      ptrdiff_t diff = Feptr - mb->start_subject;
6263
66.8k
      uint32_t available = (diff > 65535)? 65535 : ((diff > 0)? (int)diff : 0);
6264
66.8k
      if (Lmin > available) RRETURN(MATCH_NOMATCH);
6265
56.1k
      if (Lmax > available) Lmax = available;
6266
56.1k
      Feptr -= Lmax;
6267
56.1k
      }
6268
6269
    /* Now try matching, moving forward one character on failure, until we
6270
    reach the minimum back length. */
6271
6272
67.7k
    for (;;)
6273
827k
      {
6274
827k
      RMATCH(Fecode + 1 + 2 * IMM2_SIZE, RM37);
6275
822k
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6276
789k
      if (Lmax-- <= Lmin) RRETURN(MATCH_NOMATCH);
6277
759k
      Feptr++;
6278
759k
#ifdef SUPPORT_UNICODE
6279
759k
      if (utf) { FORWARDCHARTEST(Feptr, mb->end_subject); }
6280
759k
#endif
6281
759k
      }
6282
67.7k
    PCRE2_UNREACHABLE(); /* Control never reaches here */
6283
6284
0
#undef Lmin
6285
0
#undef Lmax
6286
6287
6288
    /* ===================================================================== */
6289
    /* An alternation is the end of a branch; scan along to find the end of the
6290
    bracketed group. */
6291
6292
2.41M
    case OP_ALT:
6293
2.41M
    branch_end = Fecode;
6294
26.9M
    do Fecode += GET(Fecode,1); while (*Fecode == OP_ALT);
6295
2.41M
    break;
6296
6297
6298
    /* ===================================================================== */
6299
    /* The end of a parenthesized group. For all but OP_BRA and OP_COND, the
6300
    starting frame was added to the chained frames in order to remember the
6301
    starting subject position for the group. (Not true for OP_BRA when it's a
6302
    whole pattern recursion, but that is handled separately below.)*/
6303
6304
11.9M
    case OP_KET:
6305
11.9M
    case OP_KETRMIN:
6306
12.2M
    case OP_KETRMAX:
6307
12.3M
    case OP_KETRPOS:
6308
6309
12.3M
    bracode = Fecode - GET(Fecode, 1);
6310
6311
12.3M
    if (branch_end == NULL) branch_end = Fecode;
6312
12.3M
    branch_start = bracode;
6313
32.4M
    while (branch_start + GET(branch_start, 1) != branch_end)
6314
20.0M
      branch_start += GET(branch_start, 1);
6315
12.3M
    branch_end = NULL;
6316
6317
    /* Point N to the frame at the start of the most recent group, and P to its
6318
    predecessor. Remember the subject pointer at the start of the group. */
6319
6320
12.3M
    if (*bracode != OP_BRA && *bracode != OP_COND)
6321
2.92M
      {
6322
2.92M
      N = (heapframe *)((char *)match_data->heapframes + Flast_group_offset);
6323
2.92M
      P = (heapframe *)((char *)N - frame_size);
6324
2.92M
      Flast_group_offset = P->last_group_offset;
6325
6326
#ifdef DEBUG_SHOW_RMATCH
6327
      fprintf(stderr, "++ KET for frame=%d type=%x prev char offset=%lu\n",
6328
        N->rdepth, N->group_frame_type,
6329
        (char *)P->eptr - (char *)mb->start_subject);
6330
#endif
6331
6332
      /* If we are at the end of an assertion that is a condition, first check
6333
      to see if we are at the end of a variable-length branch in a lookbehind.
6334
      If this is the case and we have not landed on the current character,
6335
      return no match. Compare code below for non-condition lookbehinds. In
6336
      other cases, return a match, discarding any intermediate backtracking
6337
      points. Copy back the mark setting and the captures into the frame before
6338
      N so that they are set on return. Doing this for all assertions, both
6339
      positive and negative, seems to match what Perl does. */
6340
6341
2.92M
      if (N->group_frame_type == GF_CONDASSERT)
6342
15.4k
        {
6343
15.4k
        if ((*bracode == OP_ASSERTBACK || *bracode == OP_ASSERTBACK_NOT) &&
6344
5.01k
            branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr)
6345
503
          RRETURN(MATCH_NOMATCH);
6346
14.9k
        memcpy((char *)P + offsetof(heapframe, ovector), Fovector,
6347
14.9k
          Foffset_top * sizeof(PCRE2_SIZE));
6348
14.9k
        P->offset_top = Foffset_top;
6349
14.9k
        P->mark = Fmark;
6350
14.9k
        Fback_frame = (char *)F - (char *)P;
6351
14.9k
        RRETURN(MATCH_MATCH);
6352
14.9k
        }
6353
2.92M
      }
6354
9.42M
    else P = NULL;   /* Indicates starting frame not recorded */
6355
6356
    /* The group was not a conditional assertion. */
6357
6358
12.3M
    switch (*bracode)
6359
12.3M
      {
6360
      /* Whole pattern recursion is handled as a recursion into group 0, but
6361
      the entire pattern is wrapped in OP_BRA/OP_KET rather than a capturing
6362
      group - a design mistake: it should perhaps have been capture group 0.
6363
      Anyway, that means the end of such recursion must be handled here. It is
6364
      detected by checking for an immediately following OP_END when we are
6365
      recursing in group 0. If this is not the end of a whole-pattern
6366
      recursion, there is nothing to be done. */
6367
6368
8.81M
      case OP_BRA:
6369
8.81M
      if (Fcurrent_recurse != 0 || Fecode[1+LINK_SIZE] != OP_END) break;
6370
6371
      /* It is the end of whole-pattern recursion. */
6372
6373
79.2k
      offset = Flast_group_offset;
6374
6375
      /* Corrupted heapframes?. Trigger an assert and return an error */
6376
79.2k
      PCRE2_ASSERT(offset != PCRE2_UNSET);
6377
79.2k
      if (offset == PCRE2_UNSET) return PCRE2_ERROR_INTERNAL;
6378
6379
79.2k
      N = (heapframe *)((char *)match_data->heapframes + offset);
6380
79.2k
      P = (heapframe *)((char *)N - frame_size);
6381
79.2k
      Flast_group_offset = P->last_group_offset;
6382
6383
      /* Reinstate the previous set of captures and then carry on after the
6384
      recursion call. */
6385
6386
79.2k
      Fecode = P->ecode + 1 + LINK_SIZE;
6387
6388
79.2k
      if (*Fecode != OP_CREF)
6389
78.0k
        {
6390
78.0k
        memcpy(F->ovector, P->ovector, Foffset_top * sizeof(PCRE2_SIZE));
6391
78.0k
        Foffset_top = P->offset_top;
6392
78.0k
        }
6393
1.20k
      else
6394
1.20k
        recurse_update_offsets(F, P);
6395
6396
79.2k
      Fcapture_last = P->capture_last;
6397
79.2k
      Fcurrent_recurse = P->current_recurse;
6398
79.2k
      continue;  /* With next opcode */
6399
6400
610k
      case OP_COND:     /* No need to do anything for these */
6401
667k
      case OP_SCOND:
6402
667k
      break;
6403
6404
      /* Non-atomic positive assertions are like OP_BRA, except that the
6405
      subject pointer must be put back to where it was at the start of the
6406
      assertion. For a variable lookbehind, check its end point. */
6407
6408
16.5k
      case OP_ASSERTBACK_NA:
6409
16.5k
      if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr)
6410
4.13k
        RRETURN(MATCH_NOMATCH);
6411
12.4k
      PCRE2_FALLTHROUGH /* Fall through */
6412
12.4k
6413
23.6k
      case OP_ASSERT_NA:
6414
23.6k
      if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr;
6415
23.6k
      Feptr = P->eptr;
6416
23.6k
      break;
6417
6418
      /* Atomic positive assertions are like OP_ONCE, except that in addition
6419
      the subject pointer must be put back to where it was at the start of the
6420
      assertion. For a variable lookbehind, check its end point. */
6421
6422
27.8k
      case OP_ASSERTBACK:
6423
27.8k
      if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr)
6424
10.5k
        RRETURN(MATCH_NOMATCH);
6425
17.3k
      PCRE2_FALLTHROUGH /* Fall through */
6426
17.3k
6427
120k
      case OP_ASSERT:
6428
120k
      if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr;
6429
120k
      Feptr = P->eptr;
6430
120k
      PCRE2_FALLTHROUGH /* Fall through */
6431
6432
      /* For an atomic group, discard internal backtracking points. We must
6433
      also ensure that any remaining branches within the top-level of the group
6434
      are not tried. Do this by adjusting the code pointer within the backtrack
6435
      frame so that it points to the final branch. */
6436
6437
200k
      case OP_ONCE:
6438
200k
      Fback_frame = ((char *)F - (char *)P);
6439
200k
      for (;;)
6440
879k
        {
6441
879k
        uint32_t y = GET(P->ecode,1);
6442
879k
        if ((P->ecode)[y] != OP_ALT) break;
6443
679k
        P->ecode += y;
6444
679k
        }
6445
200k
      break;
6446
6447
      /* A matching negative assertion returns MATCH, which is turned into
6448
      NOMATCH at the assertion level. For a variable lookbehind, check its end
6449
      point. */
6450
6451
17.4k
      case OP_ASSERTBACK_NOT:
6452
17.4k
      if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr)
6453
3.05k
        RRETURN(MATCH_NOMATCH);
6454
14.3k
      PCRE2_FALLTHROUGH /* Fall through */
6455
14.3k
6456
30.3k
      case OP_ASSERT_NOT:
6457
30.3k
      RRETURN(MATCH_MATCH);
6458
6459
      /* A scan substring group must preserve the current end_subject,
6460
      and restore it before the backtracking is performed into its sub
6461
      pattern. */
6462
6463
4.35k
      case OP_ASSERT_SCS:
6464
4.35k
      F->fields.op_assert_scs.saved_end_subject = mb->end_subject;
6465
4.35k
      mb->end_subject = P->fields.op_assert_scs.saved_end_subject;
6466
4.35k
      mb->true_end_subject = mb->end_subject + P->fields.op_assert_scs.true_end_extra;
6467
4.35k
      Feptr = P->fields.op_assert_scs.saved_eptr;
6468
6469
4.35k
      RMATCH(Fecode + 1 + LINK_SIZE, RM39);
6470
6471
4.17k
      mb->end_subject = F->fields.op_assert_scs.saved_end_subject;
6472
4.17k
      mb->true_end_subject = mb->end_subject;
6473
4.17k
      RRETURN(rrc);
6474
0
      break;
6475
6476
      /* At the end of a script run, apply the script-checking rules. This code
6477
      will never by exercised if Unicode support it not compiled, because in
6478
      that environment script runs cause an error at compile time. */
6479
6480
102k
      case OP_SCRIPT_RUN:
6481
102k
      if (!PRIV(script_run)(P->eptr, Feptr, utf)) RRETURN(MATCH_NOMATCH);
6482
74.8k
      break;
6483
6484
      /* Whole-pattern recursion is coded as a recurse into group 0, and is
6485
      handled with OP_BRA above. Other recursion is handled here. */
6486
6487
2.17M
      case OP_CBRA:
6488
2.21M
      case OP_CBRAPOS:
6489
2.36M
      case OP_SCBRA:
6490
2.42M
      case OP_SCBRAPOS:
6491
2.42M
      number = GET2(bracode, 1+LINK_SIZE);
6492
6493
      /* Handle a recursively called group. We reinstate the previous set of
6494
      captures and then carry on after the recursion call. */
6495
6496
2.42M
      if (Fcurrent_recurse == number)
6497
78.0k
        {
6498
78.0k
        P = (heapframe *)((char *)N - frame_size);
6499
78.0k
        Fecode = P->ecode + 1 + LINK_SIZE;
6500
6501
78.0k
        if (*Fecode != OP_CREF)
6502
62.4k
          {
6503
62.4k
          memcpy(F->ovector, P->ovector, Foffset_top * sizeof(PCRE2_SIZE));
6504
62.4k
          Foffset_top = P->offset_top;
6505
62.4k
          }
6506
15.5k
        else
6507
15.5k
          recurse_update_offsets(F, P);
6508
6509
78.0k
        Fcapture_last = P->capture_last;
6510
78.0k
        Fcurrent_recurse = P->current_recurse;
6511
78.0k
        continue;  /* With next opcode */
6512
78.0k
        }
6513
6514
      /* Deal with actual capturing. */
6515
6516
2.34M
      offset = (number << 1) - 2;
6517
2.34M
      Fcapture_last = number;
6518
2.34M
      Fovector[offset] = P->eptr - mb->start_subject;
6519
2.34M
      Fovector[offset+1] = Feptr - mb->start_subject;
6520
2.34M
      if (offset >= Foffset_top) Foffset_top = offset + 2;
6521
2.34M
      break;
6522
12.3M
      }  /* End actions relating to the starting opcode */
6523
6524
    /* OP_KETRPOS is a possessive repeating ket. Remember the current position,
6525
    and return the MATCH_KETRPOS. This makes it possible to do the repeats one
6526
    at a time from the outer level. This must precede the empty string test -
6527
    in this case that test is done at the outer level. */
6528
6529
12.0M
    if (*Fecode == OP_KETRPOS)
6530
122k
      {
6531
122k
      memcpy((char *)P + offsetof(heapframe, eptr),
6532
122k
             (char *)F + offsetof(heapframe, eptr),
6533
122k
             frame_copy_size);
6534
122k
      RRETURN(MATCH_KETRPOS);
6535
122k
      }
6536
6537
    /* Handle the different kinds of closing brackets. A non-repeating ket
6538
    needs no special action, just continuing at this level. This also happens
6539
    for the repeating kets if the group matched no characters, in order to
6540
    forcibly break infinite loops. Otherwise, the repeating kets try the rest
6541
    of the pattern or restart from the preceding bracket, in the appropriate
6542
    order. */
6543
6544
11.9M
    if (Fop != OP_KET && (P == NULL || Feptr != P->eptr))
6545
41.2k
      {
6546
41.2k
      if (Fop == OP_KETRMIN)
6547
10.7k
        {
6548
10.7k
        RMATCH(Fecode + 1 + LINK_SIZE, RM6);
6549
10.6k
        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6550
10.3k
        Fecode -= GET(Fecode, 1);
6551
10.3k
        break;   /* End of ket processing */
6552
10.6k
        }
6553
6554
      /* Repeat the maximum number of times (KETRMAX) */
6555
6556
30.4k
      RMATCH(bracode, RM7);
6557
22.2k
      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6558
22.2k
      }
6559
6560
    /* Carry on at this level for a non-repeating ket, or after matching an
6561
    empty string, or after repeating for a maximum number of times. */
6562
6563
11.9M
    Fecode += 1 + LINK_SIZE;
6564
11.9M
    break;
6565
6566
6567
    /* ===================================================================== */
6568
    /* Start and end of line assertions, not multiline mode. */
6569
6570
2.01M
    case OP_CIRC:   /* Start of line, unless PCRE2_NOTBOL is set. */
6571
2.01M
    if (Feptr != mb->start_subject || (mb->moptions & PCRE2_NOTBOL) != 0)
6572
2.00M
      RRETURN(MATCH_NOMATCH);
6573
13.1k
    Fecode++;
6574
13.1k
    break;
6575
6576
43.6k
    case OP_SOD:    /* Unconditional start of subject */
6577
43.6k
    if (Feptr != mb->start_subject) RRETURN(MATCH_NOMATCH);
6578
3.67k
    Fecode++;
6579
3.67k
    break;
6580
6581
    /* When PCRE2_NOTEOL is unset, assert before the subject end, or a
6582
    terminating newline unless PCRE2_DOLLAR_ENDONLY is set. */
6583
6584
757k
    case OP_DOLL:
6585
757k
    if ((mb->moptions & PCRE2_NOTEOL) != 0) RRETURN(MATCH_NOMATCH);
6586
721k
    if ((mb->poptions & PCRE2_DOLLAR_ENDONLY) == 0) goto ASSERT_NL_OR_EOS;
6587
6588
29.1k
    PCRE2_FALLTHROUGH /* Fall through */
6589
29.1k
    /* Unconditional end of subject assertion (\z). */
6590
29.1k
6591
228k
    case OP_EOD:
6592
228k
    if (Feptr < mb->true_end_subject) RRETURN(MATCH_NOMATCH);
6593
10.6k
    if (mb->partial != 0)
6594
5.32k
      {
6595
5.32k
      mb->hitend = TRUE;
6596
5.32k
      if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
6597
5.32k
      }
6598
10.5k
    Fecode++;
6599
10.5k
    break;
6600
6601
    /* End of subject or ending \n assertion (\Z) */
6602
6603
90.0k
    case OP_EODN:
6604
782k
    ASSERT_NL_OR_EOS:
6605
782k
    if (Feptr < mb->true_end_subject &&
6606
734k
        (!IS_NEWLINE(Feptr) || Feptr != mb->true_end_subject - mb->nllen))
6607
730k
      {
6608
730k
      if (mb->partial != 0 &&
6609
302k
          Feptr + 1 >= mb->end_subject &&
6610
3.92k
          NLBLOCK->nltype == NLTYPE_FIXED &&
6611
3.92k
          NLBLOCK->nllen == 2 &&
6612
0
          *Feptr == NLBLOCK->nl[0])
6613
0
        {
6614
0
        mb->hitend = TRUE;
6615
0
        if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
6616
0
        }
6617
730k
      RRETURN(MATCH_NOMATCH);
6618
730k
      }
6619
6620
    /* Either at end of string or \n before end. */
6621
6622
51.6k
    if (mb->partial != 0)
6623
34.1k
      {
6624
34.1k
      mb->hitend = TRUE;
6625
34.1k
      if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
6626
34.1k
      }
6627
51.5k
    Fecode++;
6628
51.5k
    break;
6629
6630
6631
    /* ===================================================================== */
6632
    /* Start and end of line assertions, multiline mode. */
6633
6634
    /* Start of subject unless notbol, or after any newline except for one at
6635
    the very end, unless PCRE2_ALT_CIRCUMFLEX is set. */
6636
6637
225k
    case OP_CIRCM:
6638
225k
    if ((mb->moptions & PCRE2_NOTBOL) != 0 && Feptr == mb->start_subject)
6639
1.14k
      RRETURN(MATCH_NOMATCH);
6640
224k
    if (Feptr != mb->start_subject &&
6641
220k
        ((Feptr == mb->end_subject &&
6642
5.24k
           (mb->poptions & PCRE2_ALT_CIRCUMFLEX) == 0) ||
6643
219k
         !WAS_NEWLINE(Feptr)))
6644
218k
      RRETURN(MATCH_NOMATCH);
6645
6.18k
    Fecode++;
6646
6.18k
    break;
6647
6648
    /* Assert before any newline, or before end of subject unless noteol is
6649
    set. */
6650
6651
180k
    case OP_DOLLM:
6652
180k
    if (Feptr < mb->end_subject)
6653
169k
      {
6654
169k
      if (!IS_NEWLINE(Feptr))
6655
166k
        {
6656
166k
        if (mb->partial != 0 &&
6657
50.2k
            Feptr + 1 >= mb->end_subject &&
6658
1.34k
            NLBLOCK->nltype == NLTYPE_FIXED &&
6659
1.34k
            NLBLOCK->nllen == 2 &&
6660
0
            *Feptr == NLBLOCK->nl[0])
6661
0
          {
6662
0
          mb->hitend = TRUE;
6663
0
          if (mb->partial > 1) return PCRE2_ERROR_PARTIAL;
6664
0
          }
6665
166k
        RRETURN(MATCH_NOMATCH);
6666
166k
        }
6667
169k
      }
6668
11.0k
    else
6669
11.0k
      {
6670
11.0k
      if ((mb->moptions & PCRE2_NOTEOL) != 0) RRETURN(MATCH_NOMATCH);
6671
10.3k
      SCHECK_PARTIAL();
6672
10.3k
      }
6673
12.8k
    Fecode++;
6674
12.8k
    break;
6675
6676
6677
    /* ===================================================================== */
6678
    /* Start of match assertion */
6679
6680
39.1k
    case OP_SOM:
6681
39.1k
    if (Feptr != mb->start_subject + mb->start_offset) RRETURN(MATCH_NOMATCH);
6682
930
    Fecode++;
6683
930
    break;
6684
6685
6686
    /* ===================================================================== */
6687
    /* Reset the start of match point */
6688
6689
14.2k
    case OP_SET_SOM:
6690
14.2k
    Fstart_match = Feptr;
6691
14.2k
    Fecode++;
6692
14.2k
    break;
6693
6694
6695
    /* ===================================================================== */
6696
    /* Word boundary assertions. Find out if the previous and current
6697
    characters are "word" characters. It takes a bit more work in UTF mode.
6698
    Characters > 255 are assumed to be "non-word" characters when PCRE2_UCP is
6699
    not set. When it is set, use Unicode properties if available, even when not
6700
    in UTF mode. Remember the earliest and latest consulted characters. */
6701
6702
280k
    case OP_NOT_WORD_BOUNDARY:
6703
377k
    case OP_WORD_BOUNDARY:
6704
925k
    case OP_NOT_UCP_WORD_BOUNDARY:
6705
985k
    case OP_UCP_WORD_BOUNDARY:
6706
985k
    if (Feptr == mb->check_subject) prev_is_word = FALSE; else
6707
977k
      {
6708
977k
      PCRE2_SPTR lastptr = Feptr - 1;
6709
977k
#ifdef SUPPORT_UNICODE
6710
977k
      if (utf)
6711
157k
        {
6712
157k
        BACKCHAR(lastptr);
6713
157k
        GETCHAR(fc, lastptr);
6714
157k
        }
6715
820k
      else
6716
820k
#endif  /* SUPPORT_UNICODE */
6717
820k
      fc = *lastptr;
6718
977k
      if (lastptr < mb->start_used_ptr) mb->start_used_ptr = lastptr;
6719
977k
#ifdef SUPPORT_UNICODE
6720
977k
      if (Fop == OP_UCP_WORD_BOUNDARY || Fop == OP_NOT_UCP_WORD_BOUNDARY)
6721
606k
        {
6722
606k
        int chartype = UCD_CHARTYPE(fc);
6723
606k
        int category = PRIV(ucp_gentype)[chartype];
6724
606k
        prev_is_word = (category == ucp_L || category == ucp_N ||
6725
150k
          chartype == ucp_Mn || chartype == ucp_Pc);
6726
606k
        }
6727
371k
      else
6728
371k
#endif  /* SUPPORT_UNICODE */
6729
371k
      prev_is_word = CHMAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0;
6730
977k
      }
6731
6732
    /* Get status of next character */
6733
6734
985k
    if (Feptr >= mb->end_subject)
6735
37.9k
      {
6736
37.9k
      SCHECK_PARTIAL();
6737
37.9k
      cur_is_word = FALSE;
6738
37.9k
      }
6739
947k
    else
6740
947k
      {
6741
947k
      PCRE2_SPTR nextptr = Feptr + 1;
6742
947k
#ifdef SUPPORT_UNICODE
6743
947k
      if (utf)
6744
152k
        {
6745
152k
        FORWARDCHARTEST(nextptr, mb->end_subject);
6746
152k
        GETCHAR(fc, Feptr);
6747
152k
        }
6748
795k
      else
6749
795k
#endif  /* SUPPORT_UNICODE */
6750
795k
      fc = *Feptr;
6751
947k
      if (nextptr > mb->last_used_ptr) mb->last_used_ptr = nextptr;
6752
947k
#ifdef SUPPORT_UNICODE
6753
947k
      if (Fop == OP_UCP_WORD_BOUNDARY || Fop == OP_NOT_UCP_WORD_BOUNDARY)
6754
600k
        {
6755
600k
        int chartype = UCD_CHARTYPE(fc);
6756
600k
        int category = PRIV(ucp_gentype)[chartype];
6757
600k
        cur_is_word = (category == ucp_L || category == ucp_N ||
6758
159k
          chartype == ucp_Mn || chartype == ucp_Pc);
6759
600k
        }
6760
347k
      else
6761
347k
#endif  /* SUPPORT_UNICODE */
6762
347k
      cur_is_word = CHMAX_255(fc) && (mb->ctypes[fc] & ctype_word) != 0;
6763
947k
      }
6764
6765
    /* Now see if the situation is what we want */
6766
6767
985k
    if ((*Fecode++ == OP_WORD_BOUNDARY || Fop == OP_UCP_WORD_BOUNDARY)?
6768
828k
         cur_is_word == prev_is_word : cur_is_word != prev_is_word)
6769
275k
      RRETURN(MATCH_NOMATCH);
6770
709k
    break;
6771
6772
6773
    /* ===================================================================== */
6774
    /* Backtracking (*VERB)s, with and without arguments. Note that if the
6775
    pattern is successfully matched, we do not come back from RMATCH. */
6776
6777
709k
    case OP_MARK:
6778
155k
    Fmark = mb->nomatch_mark = Fecode + 2;
6779
155k
    RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM12);
6780
6781
    /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an
6782
    argument, and we must check whether that argument matches this MARK's
6783
    argument. It is passed back in mb->verb_skip_ptr. If it does match, we
6784
    return MATCH_SKIP with mb->verb_skip_ptr now pointing to the subject
6785
    position that corresponds to this mark. Otherwise, pass back the return
6786
    code unaltered. */
6787
6788
155k
    if (rrc == MATCH_SKIP_ARG &&
6789
5.39k
             PRIV(strcmp)(Fecode + 2, mb->verb_skip_ptr) == 0)
6790
695
      {
6791
695
      mb->verb_skip_ptr = Feptr;   /* Pass back current position */
6792
695
      RRETURN(MATCH_SKIP);
6793
695
      }
6794
154k
    RRETURN(rrc);
6795
6796
61.7k
    case OP_FAIL:
6797
61.7k
    RRETURN(MATCH_NOMATCH);
6798
6799
    /* Record the current recursing group number in mb->verb_current_recurse
6800
    when a backtracking return such as MATCH_COMMIT is given. This enables the
6801
    recurse processing to catch verbs from within the recursion. */
6802
6803
5.21k
    case OP_COMMIT:
6804
5.21k
    RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM13);
6805
4.03k
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6806
1.68k
    mb->verb_current_recurse = Fcurrent_recurse;
6807
1.68k
    RRETURN(MATCH_COMMIT);
6808
6809
2.36k
    case OP_COMMIT_ARG:
6810
2.36k
    Fmark = mb->nomatch_mark = Fecode + 2;
6811
2.36k
    RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM36);
6812
2.32k
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6813
1.42k
    mb->verb_current_recurse = Fcurrent_recurse;
6814
1.42k
    RRETURN(MATCH_COMMIT);
6815
6816
37.5k
    case OP_PRUNE:
6817
37.5k
    RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM14);
6818
37.0k
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6819
34.1k
    mb->verb_current_recurse = Fcurrent_recurse;
6820
34.1k
    RRETURN(MATCH_PRUNE);
6821
6822
5.53k
    case OP_PRUNE_ARG:
6823
5.53k
    Fmark = mb->nomatch_mark = Fecode + 2;
6824
5.53k
    RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM15);
6825
5.47k
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6826
3.47k
    mb->verb_current_recurse = Fcurrent_recurse;
6827
3.47k
    RRETURN(MATCH_PRUNE);
6828
6829
70.8k
    case OP_SKIP:
6830
70.8k
    RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM16);
6831
70.6k
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6832
69.7k
    mb->verb_skip_ptr = Feptr;   /* Pass back current position */
6833
69.7k
    mb->verb_current_recurse = Fcurrent_recurse;
6834
69.7k
    RRETURN(MATCH_SKIP);
6835
6836
    /* Note that, for Perl compatibility, SKIP with an argument does NOT set
6837
    nomatch_mark. When a pattern match ends with a SKIP_ARG for which there was
6838
    not a matching mark, we have to re-run the match, ignoring the SKIP_ARG
6839
    that failed and any that precede it (either they also failed, or were not
6840
    triggered). To do this, we maintain a count of executed SKIP_ARGs. If a
6841
    SKIP_ARG gets to top level, the match is re-run with mb->ignore_skip_arg
6842
    set to the count of the one that failed. */
6843
6844
4.07M
    case OP_SKIP_ARG:
6845
4.07M
    mb->skip_arg_count++;
6846
4.07M
    if (mb->skip_arg_count <= mb->ignore_skip_arg)
6847
3.69M
      {
6848
3.69M
      Fecode += PRIV(OP_lengths)[*Fecode] + Fecode[1];
6849
3.69M
      break;
6850
3.69M
      }
6851
385k
    RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM17);
6852
385k
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6853
6854
    /* Pass back the current skip name and return the special MATCH_SKIP_ARG
6855
    return code. This will either be caught by a matching MARK, or get to the
6856
    top, where it causes a rematch with mb->ignore_skip_arg set to the value of
6857
    mb->skip_arg_count. */
6858
6859
372k
    mb->verb_skip_ptr = Fecode + 2;
6860
372k
    mb->verb_current_recurse = Fcurrent_recurse;
6861
372k
    RRETURN(MATCH_SKIP_ARG);
6862
6863
    /* For THEN (and THEN_ARG) we pass back the address of the opcode, so that
6864
    the branch in which it occurs can be determined. */
6865
6866
109k
    case OP_THEN:
6867
109k
    RMATCH(Fecode + PRIV(OP_lengths)[*Fecode], RM18);
6868
109k
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6869
90.7k
    mb->verb_ecode_ptr = Fecode;
6870
90.7k
    mb->verb_current_recurse = Fcurrent_recurse;
6871
90.7k
    RRETURN(MATCH_THEN);
6872
6873
6.97k
    case OP_THEN_ARG:
6874
6.97k
    Fmark = mb->nomatch_mark = Fecode + 2;
6875
6.97k
    RMATCH(Fecode + PRIV(OP_lengths)[*Fecode] + Fecode[1], RM19);
6876
6.87k
    if (rrc != MATCH_NOMATCH) RRETURN(rrc);
6877
1.06k
    mb->verb_ecode_ptr = Fecode;
6878
1.06k
    mb->verb_current_recurse = Fcurrent_recurse;
6879
1.06k
    RRETURN(MATCH_THEN);
6880
6881
6882
    /* ===================================================================== */
6883
    /* There's been some horrible disaster. Arrival here can only mean there is
6884
    something seriously wrong in the code above or the OP_xxx definitions. */
6885
6886
    /* LCOV_EXCL_START */
6887
33
    default:
6888
33
    PCRE2_DEBUG_UNREACHABLE();
6889
33
    return PCRE2_ERROR_INTERNAL;
6890
    /* LCOV_EXCL_STOP */
6891
130M
    }
6892
6893
  /* Do not insert any code in here without much thought; it is assumed
6894
  that "continue" in the code above comes out to here to repeat the main
6895
  loop. */
6896
6897
130M
  }  /* End of main loop */
6898
6899
0
PCRE2_DEBUG_UNREACHABLE(); /* Control should never reach here */
6900
6901
/* ========================================================================= */
6902
/* The RRETURN() macro jumps here. The number that is saved in Freturn_id
6903
indicates which label we actually want to return to. The value in Frdepth is
6904
the index number of the frame in the vector. The return value has been placed
6905
in rrc. */
6906
6907
59.3M
#define LBL(val) case val: goto L_RM##val;
6908
6909
64.3M
RETURN_SWITCH:
6910
64.3M
if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr;
6911
64.3M
if (Frdepth == 0) return rrc;                     /* Exit from the top level */
6912
59.3M
F = (heapframe *)((char *)F - Fback_frame);       /* Backtrack */
6913
59.3M
mb->cb->callout_flags |= PCRE2_CALLOUT_BACKTRACK; /* Note for callouts */
6914
6915
#ifdef DEBUG_SHOW_RMATCH
6916
fprintf(stderr, "++ RETURN %d to RM%d\n", rrc, Freturn_id);
6917
#endif
6918
6919
59.3M
switch (Freturn_id)
6920
59.3M
  {
6921
31.7M
  LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
6922
479k
  LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(16)
6923
1.76M
  LBL(17) LBL(18) LBL(19) LBL(20) LBL(21) LBL(22) LBL(23) LBL(24)
6924
909k
  LBL(25) LBL(26) LBL(27) LBL(28) LBL(29) LBL(30) LBL(31) LBL(32)
6925
4.49M
  LBL(33) LBL(34) LBL(35) LBL(36) LBL(37) LBL(38) LBL(39)
6926
6927
0
#ifdef SUPPORT_WIDE_CHARS
6928
1.11M
  LBL(100) LBL(101) LBL(102) LBL(103)
6929
0
#endif
6930
6931
0
#ifdef SUPPORT_UNICODE
6932
262k
  LBL(200) LBL(201) LBL(202) LBL(203) LBL(204) LBL(205) LBL(206)
6933
855k
  LBL(207) LBL(208) LBL(209) LBL(210) LBL(211) LBL(212) LBL(213)
6934
1.63M
  LBL(214) LBL(215) LBL(216) LBL(217) LBL(218) LBL(219) LBL(220)
6935
2.19M
  LBL(221) LBL(222) LBL(223) LBL(224)
6936
0
#endif
6937
6938
  /* LCOV_EXCL_START */
6939
0
  default:
6940
0
  PCRE2_DEBUG_UNREACHABLE();
6941
0
  return PCRE2_ERROR_INTERNAL;
6942
  /* LCOV_EXCL_STOP */
6943
59.3M
  }
6944
59.3M
#undef LBL
6945
59.3M
}
6946
6947
6948
/*************************************************
6949
*           Match a Regular Expression           *
6950
*************************************************/
6951
6952
/* This function applies a compiled pattern to a subject string and picks out
6953
portions of the string if it matches. Two elements in the vector are set for
6954
each substring: the offsets to the start and end of the substring.
6955
6956
Arguments:
6957
  code            points to the compiled expression
6958
  subject         points to the subject string
6959
  length          length of subject string (may contain binary zeros)
6960
  start_offset    where to start in the subject string
6961
  options         option bits
6962
  match_data      points to a match_data block
6963
  mcontext        points a PCRE2 context
6964
6965
Returns:          > 0 => success; value is the number of ovector pairs filled
6966
                  = 0 => success, but ovector is not big enough
6967
                  = -1 => failed to match (PCRE2_ERROR_NOMATCH)
6968
                  = -2 => partial match (PCRE2_ERROR_PARTIAL)
6969
                  < -2 => some kind of unexpected problem
6970
*/
6971
6972
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
6973
pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length,
6974
  PCRE2_SIZE start_offset, uint32_t options, pcre2_match_data *match_data,
6975
  pcre2_match_context *mcontext)
6976
169k
{
6977
169k
int rc;
6978
169k
const uint8_t *start_bits = NULL;
6979
169k
const pcre2_real_code *re = (const pcre2_real_code *)code;
6980
169k
uint32_t original_options = options;
6981
6982
169k
BOOL anchored;
6983
169k
BOOL firstline;
6984
169k
BOOL has_first_cu = FALSE;
6985
169k
BOOL has_req_cu = FALSE;
6986
169k
BOOL startline;
6987
6988
169k
#if PCRE2_CODE_UNIT_WIDTH == 8
6989
169k
PCRE2_SPTR memchr_found_first_cu;
6990
169k
PCRE2_SPTR memchr_found_first_cu2;
6991
169k
#endif
6992
6993
169k
PCRE2_UCHAR first_cu = 0;
6994
169k
PCRE2_UCHAR first_cu2 = 0;
6995
169k
PCRE2_UCHAR req_cu = 0;
6996
169k
PCRE2_UCHAR req_cu2 = 0;
6997
6998
169k
PCRE2_UCHAR null_str[1] = { 0xcd };
6999
169k
PCRE2_SPTR original_subject = subject;
7000
169k
PCRE2_SPTR bumpalong_limit;
7001
169k
PCRE2_SPTR end_subject;
7002
169k
PCRE2_SPTR true_end_subject;
7003
169k
PCRE2_SPTR start_match;
7004
169k
PCRE2_SPTR req_cu_ptr;
7005
169k
PCRE2_SPTR start_partial;
7006
169k
PCRE2_SPTR match_partial;
7007
7008
/* This flag is needed even when Unicode is not supported for convenience
7009
(it is used by the IS_NEWLINE macro). */
7010
7011
169k
BOOL utf = FALSE;
7012
7013
169k
#ifdef SUPPORT_UNICODE
7014
169k
BOOL ucp = FALSE;
7015
169k
BOOL allow_invalid;
7016
169k
uint32_t fragment_options = 0;
7017
169k
#endif  /* SUPPORT_UNICODE */
7018
7019
169k
PCRE2_SIZE frame_size;
7020
169k
PCRE2_SIZE heapframes_size;
7021
7022
/* We need to have mb as a pointer to a match block, because the IS_NEWLINE
7023
macro is used below, and it expects NLBLOCK to be defined as a pointer. */
7024
7025
169k
pcre2_callout_block cb;
7026
169k
match_block actual_match_block;
7027
169k
match_block *mb = &actual_match_block;
7028
7029
/* Recognize NULL, length 0 as an empty string. */
7030
7031
169k
if (subject == NULL && length == 0) subject = null_str;
7032
7033
/* Plausibility checks */
7034
7035
169k
if (match_data == NULL) return PCRE2_ERROR_NULL;
7036
169k
if (code == NULL || subject == NULL)
7037
0
  return match_data->rc = PCRE2_ERROR_NULL;
7038
169k
if ((options & ~PUBLIC_MATCH_OPTIONS) != 0)
7039
0
  return match_data->rc = PCRE2_ERROR_BADOPTION;
7040
7041
169k
start_match = subject + start_offset;
7042
169k
req_cu_ptr = start_match - 1;
7043
169k
if (length == PCRE2_ZERO_TERMINATED)
7044
0
  {
7045
0
  length = PRIV(strlen)(subject);
7046
0
  }
7047
169k
true_end_subject = end_subject = subject + length;
7048
7049
169k
if (start_offset > length) return match_data->rc = PCRE2_ERROR_BADOFFSET;
7050
7051
/* Check that the first field in the block is the magic number. */
7052
7053
169k
if (re->magic_number != MAGIC_NUMBER)
7054
0
  return match_data->rc = PCRE2_ERROR_BADMAGIC;
7055
7056
/* Check the code unit width. */
7057
7058
169k
if ((re->flags & PCRE2_MODE_MASK) != PCRE2_CODE_UNIT_WIDTH/8)
7059
0
  return match_data->rc = PCRE2_ERROR_BADMODE;
7060
7061
/* PCRE2_NOTEMPTY and PCRE2_NOTEMPTY_ATSTART are match-time flags in the
7062
options variable for this function. Users of PCRE2 who are not calling the
7063
function directly would like to have a way of setting these flags, in the same
7064
way that they can set pcre2_compile() flags like PCRE2_NO_AUTO_POSSESS with
7065
constructions like (*NO_AUTOPOSSESS). To enable this, (*NOTEMPTY) and
7066
(*NOTEMPTY_ATSTART) set bits in the pattern's "flag" function which we now
7067
transfer to the options for this function. The bits are guaranteed to be
7068
adjacent, but do not have the same values. This bit of Boolean trickery assumes
7069
that the match-time bits are not more significant than the flag bits. If by
7070
accident this is not the case, a compile-time division by zero error will
7071
occur. */
7072
7073
507k
#define FF (PCRE2_NOTEMPTY_SET|PCRE2_NE_ATST_SET)
7074
338k
#define OO (PCRE2_NOTEMPTY|PCRE2_NOTEMPTY_ATSTART)
7075
169k
options |= (re->flags & FF) / ((FF & (~FF+1)) / (OO & (~OO+1)));
7076
169k
#undef FF
7077
169k
#undef OO
7078
7079
/* Initialize UTF/UCP parameters. */
7080
7081
169k
#ifdef SUPPORT_UNICODE
7082
169k
utf = (re->overall_options & PCRE2_UTF) != 0;
7083
169k
allow_invalid = (re->overall_options & PCRE2_MATCH_INVALID_UTF) != 0;
7084
169k
ucp = (re->overall_options & PCRE2_UCP) != 0;
7085
169k
#endif  /* SUPPORT_UNICODE */
7086
7087
/* Convert the partial matching flags into an integer. */
7088
7089
169k
mb->partial = ((options & PCRE2_PARTIAL_HARD) != 0)? 2 :
7090
169k
              ((options & PCRE2_PARTIAL_SOFT) != 0)? 1 : 0;
7091
7092
/* Partial matching and PCRE2_ENDANCHORED are currently not allowed at the same
7093
time. */
7094
7095
169k
if (mb->partial != 0 &&
7096
27.9k
   ((re->overall_options | options) & PCRE2_ENDANCHORED) != 0)
7097
0
  return match_data->rc = PCRE2_ERROR_BADOPTION;
7098
7099
/* It is an error to set an offset limit without setting the flag at compile
7100
time. */
7101
7102
169k
if (mcontext != NULL && mcontext->offset_limit != PCRE2_UNSET &&
7103
0
     (re->overall_options & PCRE2_USE_OFFSET_LIMIT) == 0)
7104
0
  return match_data->rc = PCRE2_ERROR_BADOFFSETLIMIT;
7105
7106
/* If the match data block was previously used with PCRE2_COPY_MATCHED_SUBJECT,
7107
free the memory that was obtained. Set the field to NULL for match error
7108
cases. */
7109
7110
169k
if ((match_data->flags & PCRE2_MD_COPIED_SUBJECT) != 0)
7111
0
  {
7112
0
  match_data->memctl.free((void *)match_data->subject,
7113
0
    match_data->memctl.memory_data);
7114
0
  match_data->flags &= ~PCRE2_MD_COPIED_SUBJECT;
7115
0
  }
7116
169k
match_data->subject = NULL;
7117
7118
/* Zero the error offset in case the first code unit is invalid UTF. */
7119
7120
169k
match_data->startchar = 0;
7121
7122
7123
/* ============================= JIT matching ============================== */
7124
7125
/* If the pattern was successfully studied with JIT support, we will run the
7126
JIT executable instead of the rest of this function. Most options must be set
7127
at compile time for the JIT code to be usable. */
7128
7129
169k
#ifdef SUPPORT_JIT
7130
169k
if (re->executable_jit != NULL &&
7131
158k
    (options & ~PUBLIC_JIT_MATCH_OPTIONS) == 0 &&
7132
0
    PRIV(jit_check_exec)(re->executable_jit, options))
7133
0
  {
7134
  /* Prepare for JIT matching. Check a UTF string for validity unless no check
7135
  is requested or invalid UTF can be handled. We check only the portion of the
7136
  subject that might be be inspected during matching - from the offset minus
7137
  the maximum lookbehind to the given length. This saves time when a small part
7138
  of a large subject is being matched by the use of a starting offset. Note that
7139
  the maximum lookbehind is a number of characters, not code units. */
7140
7141
0
#ifdef SUPPORT_UNICODE
7142
0
  if (utf && (options & PCRE2_NO_UTF_CHECK) == 0 && !allow_invalid)
7143
0
    {
7144
    /* For 8-bit and 16-bit UTF, check that the first code unit is a valid
7145
    character start. */
7146
7147
0
#if PCRE2_CODE_UNIT_WIDTH != 32
7148
0
    if (start_match < end_subject && NOT_FIRSTCU(*start_match))
7149
0
      {
7150
0
      if (start_offset > 0) return match_data->rc = PCRE2_ERROR_BADUTFOFFSET;
7151
0
#if PCRE2_CODE_UNIT_WIDTH == 8
7152
0
      return match_data->rc = PCRE2_ERROR_UTF8_ERR20;  /* Isolated 0x80 byte */
7153
#else
7154
      return match_data->rc = PCRE2_ERROR_UTF16_ERR3;  /* Isolated low surrogate */
7155
#endif
7156
0
      }
7157
0
#endif  /* WIDTH != 32 */
7158
7159
    /* Move back by the maximum lookbehind, just in case it happens at the very
7160
    start of matching. */
7161
7162
0
#if PCRE2_CODE_UNIT_WIDTH != 32
7163
0
    for (unsigned int i = re->max_lookbehind; i > 0 && start_match > subject; i--)
7164
0
      {
7165
0
      start_match--;
7166
0
      while (start_match > subject &&
7167
0
#if PCRE2_CODE_UNIT_WIDTH == 8
7168
0
      (*start_match & 0xc0) == 0x80)
7169
#else  /* 16-bit */
7170
      (*start_match & 0xfc00) == 0xdc00)
7171
#endif
7172
0
        start_match--;
7173
0
      }
7174
#else  /* PCRE2_CODE_UNIT_WIDTH != 32 */
7175
7176
    /* In the 32-bit library, one code unit equals one character. However,
7177
    we cannot just subtract the lookbehind and then compare pointers, because
7178
    a very large lookbehind could create an invalid pointer. */
7179
7180
    if (start_offset >= re->max_lookbehind)
7181
      start_match -= re->max_lookbehind;
7182
    else
7183
      start_match = subject;
7184
#endif  /* PCRE2_CODE_UNIT_WIDTH != 32 */
7185
7186
    /* Validate the relevant portion of the subject. Adjust the offset of an
7187
    invalid code point to be an absolute offset in the whole string. */
7188
7189
0
    rc = PRIV(valid_utf)(start_match,
7190
0
      length - (start_match - subject), &(match_data->startchar));
7191
0
    if (rc != 0)
7192
0
      {
7193
0
      match_data->startchar += start_match - subject;
7194
0
      return match_data->rc = rc;
7195
0
      }
7196
0
    }
7197
0
#endif  /* SUPPORT_UNICODE */
7198
7199
0
  rc = pcre2_jit_match(code, subject, length, start_offset, options,
7200
0
    match_data, mcontext);
7201
  /* JIT must be able to perform the match. */
7202
0
  PCRE2_ASSERT(rc != PCRE2_ERROR_JIT_BADOPTION);
7203
7204
0
  match_data->options = original_options;
7205
0
  if (rc >= 0 && (options & PCRE2_COPY_MATCHED_SUBJECT) != 0)
7206
0
    {
7207
0
    if (length != 0)
7208
0
      {
7209
0
      match_data->subject = match_data->memctl.malloc(CU2BYTES(length),
7210
0
        match_data->memctl.memory_data);
7211
0
      if (match_data->subject == NULL)
7212
0
        return match_data->rc = PCRE2_ERROR_NOMEMORY;
7213
0
      memcpy((void *)match_data->subject, subject, CU2BYTES(length));
7214
0
      }
7215
0
    else
7216
0
      match_data->subject = NULL;
7217
0
    match_data->flags |= PCRE2_MD_COPIED_SUBJECT;
7218
0
    }
7219
0
  else
7220
0
    {
7221
    /* When pcre2_jit_match sets the subject, it doesn't know what the
7222
    original passed-in pointer was. */
7223
0
    if (match_data->subject != NULL) match_data->subject = original_subject;
7224
0
    }
7225
0
  return rc;
7226
0
  }
7227
169k
#endif  /* SUPPORT_JIT */
7228
7229
/* ========================= End of JIT matching ========================== */
7230
7231
7232
/* Proceed with non-JIT matching. The default is to allow lookbehinds to the
7233
start of the subject. A UTF check when there is a non-zero offset may change
7234
this. */
7235
7236
169k
mb->check_subject = subject;
7237
7238
/* Check the validity of UTF subject strings. The check happens only when
7239
PCRE2_NO_CHECK_UTF is unset.
7240
7241
We check only the portion of the subject that might be be inspected during
7242
matching - from the offset minus the maximum lookbehind to the given length.
7243
This saves time when a small part of a large subject is being matched by the
7244
use of a starting offset. Note that the maximum lookbehind is a number of
7245
characters, not code units.
7246
7247
Note also that support for invalid UTF forces a check, overriding the setting
7248
of PCRE2_NO_CHECK_UTF. */
7249
7250
169k
#ifdef SUPPORT_UNICODE
7251
169k
if (utf && ((options & PCRE2_NO_UTF_CHECK) == 0 || allow_invalid))
7252
43.9k
  {
7253
43.9k
#if PCRE2_CODE_UNIT_WIDTH != 32
7254
43.9k
  BOOL skipped_bad_start = FALSE;
7255
43.9k
#endif
7256
7257
  /* For 8-bit and 16-bit UTF, check that the first code unit is a valid
7258
  character start. If we are handling invalid UTF, just skip over such code
7259
  units. Otherwise, give an appropriate error. */
7260
7261
43.9k
#if PCRE2_CODE_UNIT_WIDTH != 32
7262
43.9k
  if (allow_invalid)
7263
0
    {
7264
0
    while (start_match < end_subject && NOT_FIRSTCU(*start_match))
7265
0
      {
7266
0
      start_match++;
7267
0
      skipped_bad_start = TRUE;
7268
0
      }
7269
0
    }
7270
43.9k
  else if (start_match < end_subject && NOT_FIRSTCU(*start_match))
7271
0
    {
7272
0
    if (start_offset > 0) return match_data->rc = PCRE2_ERROR_BADUTFOFFSET;
7273
0
#if PCRE2_CODE_UNIT_WIDTH == 8
7274
0
    return match_data->rc = PCRE2_ERROR_UTF8_ERR20;  /* Isolated 0x80 byte */
7275
#else
7276
    return match_data->rc = PCRE2_ERROR_UTF16_ERR3;  /* Isolated low surrogate */
7277
#endif
7278
0
    }
7279
43.9k
#endif  /* WIDTH != 32 */
7280
7281
  /* The mb->check_subject field points to the start of UTF checking;
7282
  lookbehinds can go back no further than this. */
7283
7284
43.9k
  mb->check_subject = start_match;
7285
7286
  /* Move back by the maximum lookbehind, just in case it happens at the very
7287
  start of matching, but don't do this if we skipped bad 8-bit or 16-bit code
7288
  units above. */
7289
7290
43.9k
#if PCRE2_CODE_UNIT_WIDTH != 32
7291
43.9k
  if (!skipped_bad_start)
7292
43.9k
    {
7293
43.9k
    unsigned int i;
7294
43.9k
    for (i = re->max_lookbehind; i > 0 && mb->check_subject > subject; i--)
7295
0
      {
7296
0
      mb->check_subject--;
7297
0
      while (mb->check_subject > subject &&
7298
0
#if PCRE2_CODE_UNIT_WIDTH == 8
7299
0
      (*mb->check_subject & 0xc0) == 0x80)
7300
#else  /* 16-bit */
7301
      (*mb->check_subject & 0xfc00) == 0xdc00)
7302
#endif
7303
0
        mb->check_subject--;
7304
0
      }
7305
43.9k
    }
7306
#else  /* PCRE2_CODE_UNIT_WIDTH != 32 */
7307
7308
  /* In the 32-bit library, one code unit equals one character. However,
7309
  we cannot just subtract the lookbehind and then compare pointers, because
7310
  a very large lookbehind could create an invalid pointer. */
7311
7312
  if (start_offset >= re->max_lookbehind)
7313
    mb->check_subject -= re->max_lookbehind;
7314
  else
7315
    mb->check_subject = subject;
7316
#endif  /* PCRE2_CODE_UNIT_WIDTH != 32 */
7317
7318
  /* Validate the relevant portion of the subject. There's a loop in case we
7319
  encounter bad UTF in the characters preceding start_match which we are
7320
  scanning because of a lookbehind. */
7321
7322
43.9k
  for (;;)
7323
43.9k
    {
7324
43.9k
    rc = PRIV(valid_utf)(mb->check_subject,
7325
43.9k
      length - (mb->check_subject - subject), &(match_data->startchar));
7326
7327
43.9k
    if (rc == 0) break;   /* Valid UTF string */
7328
7329
    /* Invalid UTF string. Adjust the offset to be an absolute offset in the
7330
    whole string. If we are handling invalid UTF strings, set end_subject to
7331
    stop before the bad code unit, and set the options to "not end of line".
7332
    Otherwise return the error. */
7333
7334
73
    match_data->startchar += mb->check_subject - subject;
7335
73
    if (!allow_invalid || rc > 0) return match_data->rc = rc;
7336
0
    end_subject = subject + match_data->startchar;
7337
7338
    /* If the end precedes start_match, it means there is invalid UTF in the
7339
    extra code units we reversed over because of a lookbehind. Advance past the
7340
    first bad code unit, and then skip invalid character starting code units in
7341
    8-bit and 16-bit modes, and try again with the original end point. */
7342
7343
0
    if (end_subject < start_match)
7344
0
      {
7345
0
      mb->check_subject = end_subject + 1;
7346
0
#if PCRE2_CODE_UNIT_WIDTH != 32
7347
0
      while (mb->check_subject < start_match && NOT_FIRSTCU(*mb->check_subject))
7348
0
        mb->check_subject++;
7349
0
#endif
7350
0
      end_subject = true_end_subject;
7351
0
      }
7352
7353
    /* Otherwise, set the not end of line option, and do the match. */
7354
7355
0
    else
7356
0
      {
7357
0
      fragment_options = PCRE2_NOTEOL;
7358
0
      break;
7359
0
      }
7360
0
    }
7361
43.9k
  }
7362
168k
#endif  /* SUPPORT_UNICODE */
7363
7364
/* A NULL match context means "use a default context", but we take the memory
7365
control functions from the pattern. */
7366
7367
168k
if (mcontext == NULL)
7368
0
  {
7369
0
  mcontext = (pcre2_match_context *)(&PRIV(default_match_context));
7370
0
  mb->memctl = re->memctl;
7371
0
  }
7372
168k
else mb->memctl = mcontext->memctl;
7373
7374
168k
anchored = ((re->overall_options | options) & PCRE2_ANCHORED) != 0;
7375
168k
firstline = !anchored && (re->overall_options & PCRE2_FIRSTLINE) != 0;
7376
168k
startline = (re->flags & PCRE2_STARTLINE) != 0;
7377
168k
bumpalong_limit = (mcontext->offset_limit == PCRE2_UNSET)?
7378
168k
  true_end_subject : subject + mcontext->offset_limit;
7379
7380
/* Initialize and set up the fixed fields in the callout block, with a pointer
7381
in the match block. */
7382
7383
168k
mb->cb = &cb;
7384
168k
cb.version = 2;
7385
168k
cb.subject = subject;
7386
168k
cb.subject_length = (PCRE2_SIZE)(end_subject - subject);
7387
168k
cb.callout_flags = 0;
7388
7389
/* Fill in the remaining fields in the match block, except for moptions, which
7390
gets set later. */
7391
7392
168k
mb->callout = mcontext->callout;
7393
168k
mb->callout_data = mcontext->callout_data;
7394
7395
168k
mb->start_subject = subject;
7396
168k
mb->start_offset = start_offset;
7397
168k
mb->end_subject = end_subject;
7398
168k
mb->true_end_subject = true_end_subject;
7399
168k
mb->hasthen = (re->flags & PCRE2_HASTHEN) != 0;
7400
168k
mb->hasbsk = (re->flags & PCRE2_HASBSK) != 0;
7401
168k
mb->allowemptypartial = (re->max_lookbehind > 0) ||
7402
133k
    (re->flags & PCRE2_MATCH_EMPTY) != 0;
7403
168k
mb->allowlookaroundbsk =
7404
168k
  (re->extra_options & PCRE2_EXTRA_ALLOW_LOOKAROUND_BSK) != 0;
7405
168k
mb->poptions = re->overall_options;          /* Pattern options */
7406
168k
mb->ignore_skip_arg = 0;
7407
168k
mb->mark = mb->nomatch_mark = NULL;          /* In case never set */
7408
7409
/* The name table is needed for finding all the numbers associated with a
7410
given name, for condition testing. The code follows the name table. */
7411
7412
168k
mb->name_table = (PCRE2_SPTR)((const uint8_t *)re + sizeof(pcre2_real_code));
7413
168k
mb->name_count = re->name_count;
7414
168k
mb->name_entry_size = re->name_entry_size;
7415
168k
mb->start_code = (PCRE2_SPTR)((const uint8_t *)re + re->code_start);
7416
7417
/* Process the \R and newline settings. */
7418
7419
168k
mb->bsr_convention = re->bsr_convention;
7420
168k
mb->nltype = NLTYPE_FIXED;
7421
168k
switch(re->newline_convention)
7422
168k
  {
7423
22
  case PCRE2_NEWLINE_CR:
7424
22
  mb->nllen = 1;
7425
22
  mb->nl[0] = CHAR_CR;
7426
22
  break;
7427
7428
168k
  case PCRE2_NEWLINE_LF:
7429
168k
  mb->nllen = 1;
7430
168k
  mb->nl[0] = CHAR_NL;
7431
168k
  break;
7432
7433
0
  case PCRE2_NEWLINE_NUL:
7434
0
  mb->nllen = 1;
7435
0
  mb->nl[0] = CHAR_NUL;
7436
0
  break;
7437
7438
0
  case PCRE2_NEWLINE_CRLF:
7439
0
  mb->nllen = 2;
7440
0
  mb->nl[0] = CHAR_CR;
7441
0
  mb->nl[1] = CHAR_NL;
7442
0
  break;
7443
7444
0
  case PCRE2_NEWLINE_ANY:
7445
0
  mb->nltype = NLTYPE_ANY;
7446
0
  break;
7447
7448
0
  case PCRE2_NEWLINE_ANYCRLF:
7449
0
  mb->nltype = NLTYPE_ANYCRLF;
7450
0
  break;
7451
7452
  /* LCOV_EXCL_START */
7453
0
  default:
7454
0
  PCRE2_DEBUG_UNREACHABLE();
7455
0
  return match_data->rc = PCRE2_ERROR_INTERNAL;
7456
  /* LCOV_EXCL_STOP */
7457
168k
  }
7458
7459
/* The backtracking frames have fixed data at the front, and a PCRE2_SIZE
7460
vector at the end, whose size depends on the number of capturing parentheses in
7461
the pattern. It is not used at all if there are no capturing parentheses.
7462
7463
  frame_size                   is the total size of each frame
7464
  match_data->heapframes       is the pointer to the frames vector
7465
  match_data->heapframes_size  is the allocated size of the vector
7466
7467
We must pad the frame_size for alignment to ensure subsequent frames are as
7468
aligned as heapframe. Whilst ovector is word-aligned due to being a PCRE2_SIZE
7469
array, that does not guarantee it is suitably aligned for pointers, as some
7470
architectures have pointers that are larger than a size_t. */
7471
7472
168k
frame_size = (offsetof(heapframe, ovector) +
7473
168k
  re->top_bracket * 2 * sizeof(PCRE2_SIZE) + HEAPFRAME_ALIGNMENT - 1) &
7474
168k
  ~(HEAPFRAME_ALIGNMENT - 1);
7475
7476
/* Limits set in the pattern override the match context only if they are
7477
smaller. */
7478
7479
168k
mb->heap_limit = ((mcontext->heap_limit < re->limit_heap)?
7480
168k
  mcontext->heap_limit : re->limit_heap);
7481
7482
168k
mb->match_limit = (mcontext->match_limit < re->limit_match)?
7483
168k
  mcontext->match_limit : re->limit_match;
7484
7485
168k
mb->match_limit_depth = (mcontext->depth_limit < re->limit_depth)?
7486
168k
  mcontext->depth_limit : re->limit_depth;
7487
7488
/* If a pattern has very many capturing parentheses, the frame size may be very
7489
large. Set the initial frame vector size to ensure that there are at least 10
7490
available frames, but enforce a minimum of START_FRAMES_SIZE. If this is
7491
greater than the heap limit, get as large a vector as possible. */
7492
7493
168k
heapframes_size = frame_size * 10;
7494
168k
if (heapframes_size < START_FRAMES_SIZE) heapframes_size = START_FRAMES_SIZE;
7495
168k
if (heapframes_size / 1024 > mb->heap_limit)
7496
0
  {
7497
0
  PCRE2_SIZE max_size = 1024 * mb->heap_limit;
7498
0
  if (max_size < frame_size) return match_data->rc = PCRE2_ERROR_HEAPLIMIT;
7499
0
  heapframes_size = max_size;
7500
0
  }
7501
7502
/* If an existing frame vector in the match_data block is large enough, we can
7503
use it. Otherwise, free any pre-existing vector and get a new one. */
7504
7505
168k
if (match_data->heapframes_size < heapframes_size)
7506
48.8k
  {
7507
48.8k
  match_data->memctl.free(match_data->heapframes,
7508
48.8k
    match_data->memctl.memory_data);
7509
48.8k
  match_data->heapframes = match_data->memctl.malloc(heapframes_size,
7510
48.8k
    match_data->memctl.memory_data);
7511
48.8k
  if (match_data->heapframes == NULL)
7512
0
    {
7513
0
    match_data->heapframes_size = 0;
7514
0
    return match_data->rc = PCRE2_ERROR_NOMEMORY;
7515
0
    }
7516
48.8k
  match_data->heapframes_size = heapframes_size;
7517
48.8k
  }
7518
7519
/* Write to the ovector within the first frame to mark every capture unset and
7520
to avoid uninitialized memory read errors when it is copied to a new frame. */
7521
7522
168k
memset((char *)(match_data->heapframes) + offsetof(heapframe, ovector), 0xff,
7523
168k
  frame_size - offsetof(heapframe, ovector));
7524
7525
/* Pointers to the individual character tables */
7526
7527
168k
mb->lcc = re->tables + lcc_offset;
7528
168k
mb->fcc = re->tables + fcc_offset;
7529
168k
mb->ctypes = re->tables + ctypes_offset;
7530
7531
/* Set up the first code unit to match, if available. If there's no first code
7532
unit there may be a bitmap of possible first characters. */
7533
7534
168k
if ((re->flags & PCRE2_FIRSTSET) != 0)
7535
42.6k
  {
7536
42.6k
  has_first_cu = TRUE;
7537
42.6k
  first_cu = first_cu2 = (PCRE2_UCHAR)(re->first_codeunit);
7538
42.6k
  if ((re->flags & PCRE2_FIRSTCASELESS) != 0)
7539
2.72k
    {
7540
2.72k
    first_cu2 = TABLE_GET(first_cu, mb->fcc, first_cu);
7541
2.72k
#ifdef SUPPORT_UNICODE
7542
2.72k
#if PCRE2_CODE_UNIT_WIDTH == 8
7543
2.72k
    if (first_cu > 127 && ucp && !utf) first_cu2 = UCD_OTHERCASE(first_cu);
7544
#else
7545
    if (first_cu > 127 && (utf || ucp)) first_cu2 = UCD_OTHERCASE(first_cu);
7546
#endif
7547
2.72k
#endif  /* SUPPORT_UNICODE */
7548
2.72k
    }
7549
42.6k
  }
7550
126k
else
7551
126k
  if (!startline && (re->flags & PCRE2_FIRSTMAPSET) != 0)
7552
31.4k
    start_bits = re->start_bitmap;
7553
7554
/* There may also be a "last known required character" set. */
7555
7556
168k
if ((re->flags & PCRE2_LASTSET) != 0)
7557
62.1k
  {
7558
62.1k
  has_req_cu = TRUE;
7559
62.1k
  req_cu = req_cu2 = (PCRE2_UCHAR)(re->last_codeunit);
7560
62.1k
  if ((re->flags & PCRE2_LASTCASELESS) != 0)
7561
3.82k
    {
7562
3.82k
    req_cu2 = TABLE_GET(req_cu, mb->fcc, req_cu);
7563
3.82k
#ifdef SUPPORT_UNICODE
7564
3.82k
#if PCRE2_CODE_UNIT_WIDTH == 8
7565
3.82k
    if (req_cu > 127 && ucp && !utf) req_cu2 = UCD_OTHERCASE(req_cu);
7566
#else
7567
    if (req_cu > 127 && (utf || ucp)) req_cu2 = UCD_OTHERCASE(req_cu);
7568
#endif
7569
3.82k
#endif  /* SUPPORT_UNICODE */
7570
3.82k
    }
7571
62.1k
  }
7572
7573
7574
/* ==========================================================================*/
7575
7576
/* Loop for handling unanchored repeated matching attempts; for anchored regexs
7577
the loop runs just once. */
7578
7579
168k
#ifdef SUPPORT_UNICODE
7580
168k
FRAGMENT_RESTART:
7581
168k
#endif
7582
7583
168k
start_partial = match_partial = NULL;
7584
168k
mb->hitend = FALSE;
7585
7586
168k
#if PCRE2_CODE_UNIT_WIDTH == 8
7587
168k
memchr_found_first_cu = NULL;
7588
168k
memchr_found_first_cu2 = NULL;
7589
168k
#endif
7590
7591
168k
for(;;)
7592
5.12M
  {
7593
5.12M
  PCRE2_SPTR new_start_match;
7594
7595
  /* ----------------- Start of match optimizations ---------------- */
7596
7597
  /* There are some optimizations that avoid running the match if a known
7598
  starting point is not found, or if a known later code unit is not present.
7599
  However, there is an option (settable at compile time) that disables these,
7600
  for testing and for ensuring that all callouts do actually occur. */
7601
7602
5.12M
  if ((re->optimization_flags & PCRE2_OPTIM_START_OPTIMIZE) != 0)
7603
3.82M
    {
7604
    /* If firstline is TRUE, the start of the match is constrained to the first
7605
    line of a multiline string. That is, the match must be before or at the
7606
    first newline following the start of matching. Temporarily adjust
7607
    end_subject so that we stop the scans for a first code unit at a newline.
7608
    If the match fails at the newline, later code breaks the loop. */
7609
7610
3.82M
    if (firstline)
7611
673k
      {
7612
673k
      PCRE2_SPTR t = start_match;
7613
673k
#ifdef SUPPORT_UNICODE
7614
673k
      if (utf)
7615
205k
        {
7616
26.5M
        while (t < end_subject && !IS_NEWLINE(t))
7617
26.3M
          {
7618
26.3M
          t++;
7619
26.3M
          ACROSSCHAR(t < end_subject, t, t++);
7620
26.3M
          }
7621
205k
        }
7622
467k
      else
7623
467k
#endif
7624
179M
      while (t < end_subject && !IS_NEWLINE(t)) t++;
7625
673k
      end_subject = t;
7626
673k
      }
7627
7628
    /* Anchored: check the first code unit if one is recorded. This may seem
7629
    pointless but it can help in detecting a no match case without scanning for
7630
    the required code unit. */
7631
7632
3.82M
    if (anchored)
7633
18.2k
      {
7634
18.2k
      if (has_first_cu || start_bits != NULL)
7635
10.8k
        {
7636
10.8k
        BOOL ok = start_match < end_subject;
7637
10.8k
        if (ok)
7638
10.8k
          {
7639
10.8k
          PCRE2_UCHAR c = *start_match;
7640
10.8k
          ok = has_first_cu && (c == first_cu || c == first_cu2);
7641
10.8k
          if (!ok && start_bits != NULL)
7642
4.12k
            {
7643
#if PCRE2_CODE_UNIT_WIDTH != 8
7644
            if (c > 255) c = 255;
7645
#endif
7646
4.12k
            ok = (start_bits[c/8] & (1u << (c&7))) != 0;
7647
4.12k
            }
7648
10.8k
          }
7649
10.8k
        if (!ok)
7650
3.06k
          {
7651
3.06k
          rc = MATCH_NOMATCH;
7652
3.06k
          break;
7653
3.06k
          }
7654
10.8k
        }
7655
18.2k
      }
7656
7657
    /* Not anchored. Advance to a unique first code unit if there is one. */
7658
7659
3.80M
    else
7660
3.80M
      {
7661
3.80M
      if (has_first_cu)
7662
209k
        {
7663
209k
        if (first_cu != first_cu2)  /* Caseless */
7664
10.6k
          {
7665
          /* In 16-bit and 32_bit modes we have to do our own search, so can
7666
          look for both cases at once. */
7667
7668
#if PCRE2_CODE_UNIT_WIDTH != 8
7669
          PCRE2_UCHAR smc;
7670
          while (start_match < end_subject &&
7671
                (smc = *start_match) != first_cu &&
7672
                 smc != first_cu2)
7673
            start_match++;
7674
#else
7675
          /* In 8-bit mode, the use of memchr() gives a big speed up, even
7676
          though we have to call it twice in order to find the earliest
7677
          occurrence of the code unit in either of its cases. Caching is used
7678
          to remember the positions of previously found code units. This can
7679
          make a huge difference when the strings are very long and only one
7680
          case is actually present. */
7681
7682
10.6k
          PCRE2_SPTR pp1 = NULL;
7683
10.6k
          PCRE2_SPTR pp2 = NULL;
7684
10.6k
          PCRE2_SIZE searchlength = end_subject - start_match;
7685
7686
          /* If we haven't got a previously found position for first_cu, or if
7687
          the current starting position is later, we need to do a search. If
7688
          the code unit is not found, set it to the end. */
7689
7690
10.6k
          if (memchr_found_first_cu == NULL ||
7691
8.58k
              start_match > memchr_found_first_cu)
7692
7.82k
            {
7693
7.82k
            pp1 = memchr(start_match, first_cu, searchlength);
7694
7.82k
            memchr_found_first_cu = (pp1 == NULL)? end_subject : pp1;
7695
7.82k
            }
7696
7697
          /* If the start is before a previously found position, use the
7698
          previous position, or NULL if a previous search failed. */
7699
7700
2.77k
          else pp1 = (memchr_found_first_cu == end_subject)? NULL :
7701
2.77k
            memchr_found_first_cu;
7702
7703
          /* Do the same thing for the other case. */
7704
7705
10.6k
          if (memchr_found_first_cu2 == NULL ||
7706
8.58k
              start_match > memchr_found_first_cu2)
7707
4.00k
            {
7708
4.00k
            pp2 = memchr(start_match, first_cu2, searchlength);
7709
4.00k
            memchr_found_first_cu2 = (pp2 == NULL)? end_subject : pp2;
7710
4.00k
            }
7711
7712
6.60k
          else pp2 = (memchr_found_first_cu2 == end_subject)? NULL :
7713
6.60k
            memchr_found_first_cu2;
7714
7715
          /* Set the start to the end of the subject if neither case was found.
7716
          Otherwise, use the earlier found point. */
7717
7718
10.6k
          if (pp1 == NULL)
7719
2.45k
            start_match = (pp2 == NULL)? end_subject : pp2;
7720
8.15k
          else
7721
8.15k
            start_match = (pp2 == NULL || pp1 < pp2)? pp1 : pp2;
7722
7723
10.6k
#endif  /* 8-bit handling */
7724
10.6k
          }
7725
7726
        /* The caseful case is much simpler. */
7727
7728
199k
        else
7729
199k
          {
7730
#if PCRE2_CODE_UNIT_WIDTH != 8
7731
          while (start_match < end_subject && *start_match !=
7732
                 first_cu)
7733
            start_match++;
7734
#else
7735
199k
          start_match = memchr(start_match, first_cu, end_subject - start_match);
7736
199k
          if (start_match == NULL) start_match = end_subject;
7737
199k
#endif
7738
199k
          }
7739
7740
        /* If we can't find the required first code unit, having reached the
7741
        true end of the subject, break the bumpalong loop, to force a match
7742
        failure, except when doing partial matching, when we let the next cycle
7743
        run at the end of the subject. To see why, consider the pattern
7744
        /(?<=abc)def/, which partially matches "abc", even though the string
7745
        does not contain the starting character "d". If we have not reached the
7746
        true end of the subject (PCRE2_FIRSTLINE caused end_subject to be
7747
        temporarily modified) we also let the cycle run, because the matching
7748
        string is legitimately allowed to start with the first code unit of a
7749
        newline. */
7750
7751
209k
        if (mb->partial == 0 && start_match >= mb->end_subject)
7752
14.6k
          {
7753
14.6k
          rc = MATCH_NOMATCH;
7754
14.6k
          break;
7755
14.6k
          }
7756
209k
        }
7757
7758
      /* If there's no first code unit, advance to just after a linebreak for a
7759
      multiline match if required. */
7760
7761
3.59M
      else if (startline)
7762
4.19k
        {
7763
4.19k
        if (start_match > mb->start_subject + start_offset)
7764
2.61k
          {
7765
2.61k
#ifdef SUPPORT_UNICODE
7766
2.61k
          if (utf)
7767
1.11k
            {
7768
10.5k
            while (start_match < end_subject && !WAS_NEWLINE(start_match))
7769
9.41k
              {
7770
9.41k
              start_match++;
7771
9.41k
              ACROSSCHAR(start_match < end_subject, start_match, start_match++);
7772
9.41k
              }
7773
1.11k
            }
7774
1.50k
          else
7775
1.50k
#endif
7776
11.8k
          while (start_match < end_subject && !WAS_NEWLINE(start_match))
7777
10.3k
            start_match++;
7778
7779
          /* If we have just passed a CR and the newline option is ANY or
7780
          ANYCRLF, and we are now at a LF, advance the match position by one
7781
          more code unit. */
7782
7783
2.61k
          if (start_match[-1] == CHAR_CR &&
7784
20
               (mb->nltype == NLTYPE_ANY || mb->nltype == NLTYPE_ANYCRLF) &&
7785
0
               start_match < end_subject &&
7786
0
               *start_match == CHAR_NL)
7787
0
            start_match++;
7788
2.61k
          }
7789
4.19k
        }
7790
7791
      /* If there's no first code unit or a requirement for a multiline line
7792
      start, advance to a non-unique first code unit if any have been
7793
      identified. The bitmap contains only 256 bits. When code units are 16 or
7794
      32 bits wide, all code units greater than 254 set the 255 bit. */
7795
7796
3.59M
      else if (start_bits != NULL)
7797
704k
        {
7798
1.97M
        while (start_match < end_subject)
7799
1.97M
          {
7800
1.97M
          uint32_t c = *start_match;
7801
#if PCRE2_CODE_UNIT_WIDTH != 8
7802
          if (c > 255) c = 255;
7803
#endif
7804
1.97M
          if ((start_bits[c/8] & (1u << (c&7))) != 0) break;
7805
1.27M
          start_match++;
7806
1.27M
          }
7807
7808
        /* See comment above in first_cu checking about the next few lines. */
7809
7810
704k
        if (mb->partial == 0 && start_match >= mb->end_subject)
7811
6.16k
          {
7812
6.16k
          rc = MATCH_NOMATCH;
7813
6.16k
          break;
7814
6.16k
          }
7815
704k
        }
7816
3.80M
      }   /* End first code unit handling */
7817
7818
    /* Restore fudged end_subject */
7819
7820
3.80M
    end_subject = mb->end_subject;
7821
7822
    /* The following two optimizations must be disabled for partial matching. */
7823
7824
3.80M
    if (mb->partial == 0)
7825
2.63M
      {
7826
2.63M
      PCRE2_SPTR p;
7827
7828
      /* The minimum matching length is a lower bound; no string of that length
7829
      may actually match the pattern. Although the value is, strictly, in
7830
      characters, we treat it as code units to avoid spending too much time in
7831
      this optimization. */
7832
7833
2.63M
      if (end_subject - start_match < re->minlength)
7834
27.9k
        {
7835
27.9k
        rc = MATCH_NOMATCH;
7836
27.9k
        break;
7837
27.9k
        }
7838
7839
      /* If req_cu is set, we know that that code unit must appear in the
7840
      subject for the (non-partial) match to succeed. If the first code unit is
7841
      set, req_cu must be later in the subject; otherwise the test starts at
7842
      the match point. This optimization can save a huge amount of backtracking
7843
      in patterns with nested unlimited repeats that aren't going to match.
7844
      Writing separate code for caseful/caseless versions makes it go faster,
7845
      as does using an autoincrement and backing off on a match. As in the case
7846
      of the first code unit, using memchr() in the 8-bit library gives a big
7847
      speed up. Unlike the first_cu check above, we do not need to call
7848
      memchr() twice in the caseless case because we only need to check for the
7849
      presence of the character in either case, not find the first occurrence.
7850
7851
      The search can be skipped if the code unit was found later than the
7852
      current starting point in a previous iteration of the bumpalong loop.
7853
7854
      HOWEVER: when the subject string is very, very long, searching to its end
7855
      can take a long time, and give bad performance on quite ordinary
7856
      anchored patterns. This showed up when somebody was matching something
7857
      like /^\d+C/ on a 32-megabyte string... so we don't do this when the
7858
      string is sufficiently long, but it's worth searching a lot more for
7859
      unanchored patterns. */
7860
7861
2.60M
      p = start_match + (has_first_cu? 1:0);
7862
2.60M
      if (has_req_cu && p > req_cu_ptr)
7863
78.7k
        {
7864
78.7k
        PCRE2_SIZE check_length = end_subject - start_match;
7865
7866
78.7k
        if (check_length < REQ_CU_MAX ||
7867
0
              (!anchored && check_length < REQ_CU_MAX * 1000))
7868
78.7k
          {
7869
78.7k
          if (req_cu != req_cu2)  /* Caseless */
7870
5.25k
            {
7871
#if PCRE2_CODE_UNIT_WIDTH != 8
7872
            while (p < end_subject)
7873
              {
7874
              uint32_t pp = *p++;
7875
              if (pp == req_cu || pp == req_cu2) { p--; break; }
7876
              }
7877
#else  /* 8-bit code units */
7878
5.25k
            PCRE2_SPTR pp = p;
7879
5.25k
            p = memchr(pp, req_cu, end_subject - pp);
7880
5.25k
            if (p == NULL)
7881
539
              {
7882
539
              p = memchr(pp, req_cu2, end_subject - pp);
7883
539
              if (p == NULL) p = end_subject;
7884
539
              }
7885
5.25k
#endif /* PCRE2_CODE_UNIT_WIDTH != 8 */
7886
5.25k
            }
7887
7888
          /* The caseful case */
7889
7890
73.5k
          else
7891
73.5k
            {
7892
#if PCRE2_CODE_UNIT_WIDTH != 8
7893
            while (p < end_subject)
7894
              {
7895
              if (*p++ == req_cu) { p--; break; }
7896
              }
7897
7898
#else  /* 8-bit code units */
7899
73.5k
            p = memchr(p, req_cu, end_subject - p);
7900
73.5k
            if (p == NULL) p = end_subject;
7901
73.5k
#endif
7902
73.5k
            }
7903
7904
          /* If we can't find the required code unit, break the bumpalong loop,
7905
          forcing a match failure. */
7906
7907
78.7k
          if (p >= end_subject)
7908
2.50k
            {
7909
2.50k
            rc = MATCH_NOMATCH;
7910
2.50k
            break;
7911
2.50k
            }
7912
7913
          /* If we have found the required code unit, save the point where we
7914
          found it, so that we don't search again next time round the bumpalong
7915
          loop if the start hasn't yet passed this code unit. */
7916
7917
76.2k
          req_cu_ptr = p;
7918
76.2k
          }
7919
78.7k
        }
7920
2.60M
      }
7921
3.80M
    }
7922
7923
  /* ------------ End of start of match optimizations ------------ */
7924
7925
  /* Give no match if we have passed the bumpalong limit. */
7926
7927
5.07M
  if (start_match > bumpalong_limit)
7928
0
    {
7929
0
    rc = MATCH_NOMATCH;
7930
0
    break;
7931
0
    }
7932
7933
  /* OK, we can now run the match. If "hitend" is set afterwards, remember the
7934
  first starting point for which a partial match was found. */
7935
7936
5.07M
  cb.start_match = (PCRE2_SIZE)(start_match - subject);
7937
5.07M
  cb.callout_flags |= PCRE2_CALLOUT_STARTMATCH;
7938
7939
5.07M
  mb->start_used_ptr = start_match;
7940
5.07M
  mb->last_used_ptr = start_match;
7941
5.07M
#ifdef SUPPORT_UNICODE
7942
5.07M
  mb->moptions = options | fragment_options;
7943
#else
7944
  mb->moptions = options;
7945
#endif
7946
5.07M
  mb->match_call_count = 0;
7947
5.07M
  mb->end_offset_top = 0;
7948
5.07M
  mb->skip_arg_count = 0;
7949
7950
#ifdef DEBUG_SHOW_OPS
7951
  fprintf(stderr, "++ Calling match()\n");
7952
#endif
7953
7954
5.07M
  rc = match(start_match, mb->start_code, re->top_bracket, frame_size,
7955
5.07M
    match_data, mb);
7956
7957
#ifdef DEBUG_SHOW_OPS
7958
  fprintf(stderr, "++ match() returned %d\n\n", rc);
7959
#endif
7960
7961
5.07M
  if (mb->hitend && start_partial == NULL)
7962
15.6k
    {
7963
15.6k
    start_partial = mb->start_used_ptr;
7964
15.6k
    match_partial = start_match;
7965
15.6k
    }
7966
7967
5.07M
  switch(rc)
7968
5.07M
    {
7969
    /* If MATCH_SKIP_ARG reaches this level it means that a MARK that matched
7970
    the SKIP's arg was not found. In this circumstance, Perl ignores the SKIP
7971
    entirely. The only way we can do that is to re-do the match at the same
7972
    point, with a flag to force SKIP with an argument to be ignored. Just
7973
    treating this case as NOMATCH does not work because it does not check other
7974
    alternatives in patterns such as A(*SKIP:A)B|AC when the subject is AC. */
7975
7976
371k
    case MATCH_SKIP_ARG:
7977
371k
    new_start_match = start_match;
7978
371k
    mb->ignore_skip_arg = mb->skip_arg_count;
7979
371k
    break;
7980
7981
    /* SKIP passes back the next starting point explicitly, but if it is no
7982
    greater than the match we have just done, treat it as NOMATCH. */
7983
7984
69.5k
    case MATCH_SKIP:
7985
69.5k
    if (mb->verb_skip_ptr > start_match)
7986
64.8k
      {
7987
64.8k
      new_start_match = mb->verb_skip_ptr;
7988
64.8k
      break;
7989
64.8k
      }
7990
4.62k
    PCRE2_FALLTHROUGH /* Fall through */
7991
4.62k
7992
4.62k
    /* NOMATCH and PRUNE advance by one character. THEN at this level acts
7993
4.62k
    exactly like PRUNE. Unset ignore SKIP-with-argument. */
7994
4.62k
7995
4.52M
    case MATCH_NOMATCH:
7996
4.55M
    case MATCH_PRUNE:
7997
4.56M
    case MATCH_THEN:
7998
4.56M
    mb->ignore_skip_arg = 0;
7999
4.56M
    new_start_match = start_match + 1;
8000
4.56M
#ifdef SUPPORT_UNICODE
8001
4.56M
    if (utf)
8002
1.15M
      ACROSSCHAR(new_start_match < end_subject, new_start_match,
8003
4.56M
        new_start_match++);
8004
4.56M
#endif
8005
4.56M
    break;
8006
8007
    /* COMMIT disables the bumpalong, but otherwise behaves as NOMATCH. */
8008
8009
460
    case MATCH_COMMIT:
8010
460
    rc = MATCH_NOMATCH;
8011
460
    goto ENDLOOP;
8012
8013
    /* Any other return is either a match, or some kind of error. */
8014
8015
74.5k
    default:
8016
74.5k
    goto ENDLOOP;
8017
5.07M
    }
8018
8019
  /* Control reaches here for the various types of "no match at this point"
8020
  result. Reset the code to MATCH_NOMATCH for subsequent checking. */
8021
8022
4.99M
  rc = MATCH_NOMATCH;
8023
8024
  /* If PCRE2_FIRSTLINE is set, the match must happen before or at the first
8025
  newline in the subject (though it may continue over the newline). Therefore,
8026
  if we have just failed to match, starting at a newline, do not continue. */
8027
8028
4.99M
  if (firstline && IS_NEWLINE(start_match)) break;
8029
8030
  /* Advance to new matching position */
8031
8032
4.99M
  start_match = new_start_match;
8033
8034
  /* Break the loop if the pattern is anchored or if we have passed the end of
8035
  the subject. */
8036
8037
4.99M
  if (anchored || start_match > end_subject) break;
8038
8039
  /* If we have just passed a CR and we are now at a LF, and the pattern does
8040
  not contain any explicit matches for \r or \n, and the newline option is CRLF
8041
  or ANY or ANYCRLF, advance the match position by one more code unit. In
8042
  normal matching start_match will aways be greater than the first position at
8043
  this stage, but a failed *SKIP can cause a return at the same point, which is
8044
  why the first test exists. */
8045
8046
4.95M
  if (start_match > subject + start_offset &&
8047
4.95M
      start_match[-1] == CHAR_CR &&
8048
24.4k
      start_match < end_subject &&
8049
23.9k
      *start_match == CHAR_NL &&
8050
2.45k
      (re->flags & PCRE2_HASCRORLF) == 0 &&
8051
738
        (mb->nltype == NLTYPE_ANY ||
8052
738
         mb->nltype == NLTYPE_ANYCRLF ||
8053
738
         mb->nllen == 2))
8054
0
    start_match++;
8055
8056
4.95M
  mb->mark = NULL;   /* Reset for start of next match attempt */
8057
4.95M
  }                  /* End of for(;;) "bumpalong" loop */
8058
8059
/* ==========================================================================*/
8060
8061
/* When we reach here, one of the following stopping conditions is true:
8062
8063
(1) The match succeeded, either completely, or partially;
8064
8065
(2) The pattern is anchored or the match was failed after (*COMMIT);
8066
8067
(3) We are past the end of the subject or the bumpalong limit;
8068
8069
(4) PCRE2_FIRSTLINE is set and we have failed to match at a newline, because
8070
    this option requests that a match occur at or before the first newline in
8071
    the subject.
8072
8073
(5) Some kind of error occurred.
8074
8075
*/
8076
8077
168k
ENDLOOP:
8078
8079
/* If end_subject != true_end_subject, it means we are handling invalid UTF,
8080
and have just processed a non-terminal fragment. If this resulted in no match
8081
or a partial match we must carry on to the next fragment (a partial match is
8082
returned to the caller only at the very end of the subject). A loop is used to
8083
avoid trying to match against empty fragments; if the pattern can match an
8084
empty string it would have done so already. */
8085
8086
168k
#ifdef SUPPORT_UNICODE
8087
168k
if (utf && end_subject != true_end_subject &&
8088
0
    (rc == MATCH_NOMATCH || rc == PCRE2_ERROR_PARTIAL))
8089
0
  {
8090
0
  for (;;)
8091
0
    {
8092
    /* Advance past the first bad code unit, and then skip invalid character
8093
    starting code units in 8-bit and 16-bit modes. */
8094
8095
0
    start_match = end_subject + 1;
8096
8097
0
#if PCRE2_CODE_UNIT_WIDTH != 32
8098
0
    while (start_match < true_end_subject && NOT_FIRSTCU(*start_match))
8099
0
      start_match++;
8100
0
#endif
8101
8102
    /* If we have hit the end of the subject, there isn't another non-empty
8103
    fragment, so give up. */
8104
8105
0
    if (start_match >= true_end_subject)
8106
0
      {
8107
0
      rc = MATCH_NOMATCH;  /* In case it was partial */
8108
0
      match_partial = NULL;
8109
0
      break;
8110
0
      }
8111
8112
    /* Check the rest of the subject */
8113
8114
0
    mb->check_subject = start_match;
8115
0
    rc = PRIV(valid_utf)(start_match, length - (start_match - subject),
8116
0
      &(match_data->startchar));
8117
8118
    /* The rest of the subject is valid UTF. */
8119
8120
0
    if (rc == 0)
8121
0
      {
8122
0
      mb->end_subject = end_subject = true_end_subject;
8123
0
      fragment_options = PCRE2_NOTBOL;
8124
0
      goto FRAGMENT_RESTART;
8125
0
      }
8126
8127
    /* A subsequent UTF error has been found; if the next fragment is
8128
    non-empty, set up to process it. Otherwise, let the loop advance. */
8129
8130
0
    else if (rc < 0)
8131
0
      {
8132
0
      mb->end_subject = end_subject = start_match + match_data->startchar;
8133
0
      if (end_subject > start_match)
8134
0
        {
8135
0
        fragment_options = PCRE2_NOTBOL|PCRE2_NOTEOL;
8136
0
        goto FRAGMENT_RESTART;
8137
0
        }
8138
0
      }
8139
0
    }
8140
0
  }
8141
168k
#endif  /* SUPPORT_UNICODE */
8142
8143
/* Fill in fields that are always returned in the match data. */
8144
8145
168k
match_data->code = re;
8146
168k
match_data->mark = mb->mark;
8147
168k
match_data->matchedby = PCRE2_MATCHEDBY_INTERPRETER;
8148
168k
match_data->options = original_options;
8149
8150
/* Handle a fully successful match. Set the return code to the number of
8151
captured strings, or 0 if there were too many to fit into the ovector, and then
8152
set the remaining returned values before returning. Make a copy of the subject
8153
string if requested. */
8154
8155
168k
if (rc == MATCH_MATCH)
8156
42.7k
  {
8157
42.7k
  match_data->rc = ((int)mb->end_offset_top >= 2 * match_data->oveccount)?
8158
42.7k
    0 : (int)mb->end_offset_top/2 + 1;
8159
42.7k
  match_data->subject_length = length;
8160
42.7k
  match_data->start_offset = start_offset;
8161
42.7k
  match_data->startchar = start_match - subject;
8162
42.7k
  match_data->leftchar = mb->start_used_ptr - subject;
8163
42.7k
  match_data->rightchar = ((mb->last_used_ptr > mb->end_match_ptr)?
8164
35.7k
    mb->last_used_ptr : mb->end_match_ptr) - subject;
8165
42.7k
  if ((options & PCRE2_COPY_MATCHED_SUBJECT) != 0)
8166
0
    {
8167
0
    if (length != 0)
8168
0
      {
8169
0
      match_data->subject = match_data->memctl.malloc(CU2BYTES(length),
8170
0
        match_data->memctl.memory_data);
8171
0
      if (match_data->subject == NULL)
8172
0
        return match_data->rc = PCRE2_ERROR_NOMEMORY;
8173
0
      memcpy((void *)match_data->subject, subject, CU2BYTES(length));
8174
0
      }
8175
0
    else
8176
0
      match_data->subject = NULL;
8177
0
    match_data->flags |= PCRE2_MD_COPIED_SUBJECT;
8178
0
    }
8179
42.7k
  else match_data->subject = original_subject;
8180
8181
42.7k
  return match_data->rc;
8182
42.7k
  }
8183
8184
/* Control gets here if there has been a partial match, an error, or if the
8185
overall match attempt has failed at all permitted starting positions. Any mark
8186
data is in the nomatch_mark field. */
8187
8188
126k
match_data->mark = mb->nomatch_mark;
8189
8190
/* For anything other than nomatch or partial match, just return the code. */
8191
8192
126k
if (rc != MATCH_NOMATCH && rc != PCRE2_ERROR_PARTIAL) match_data->rc = rc;
8193
8194
/* Handle a partial match. If a "soft" partial match was requested, searching
8195
for a complete match will have continued, and the value of rc at this point
8196
will be MATCH_NOMATCH. For a "hard" partial match, it will already be
8197
PCRE2_ERROR_PARTIAL. */
8198
8199
100k
else if (match_partial != NULL)
8200
12.8k
  {
8201
12.8k
  match_data->subject = original_subject;
8202
12.8k
  match_data->subject_length = length;
8203
12.8k
  match_data->start_offset = start_offset;
8204
12.8k
  match_data->ovector[0] = match_partial - subject;
8205
12.8k
  match_data->ovector[1] = end_subject - subject;
8206
12.8k
  match_data->startchar = match_partial - subject;
8207
12.8k
  match_data->leftchar = start_partial - subject;
8208
12.8k
  match_data->rightchar = end_subject - subject;
8209
12.8k
  match_data->rc = PCRE2_ERROR_PARTIAL;
8210
12.8k
  }
8211
8212
/* Else this is the classic nomatch case. */
8213
8214
87.4k
else
8215
87.4k
  {
8216
87.4k
  match_data->subject = original_subject;
8217
87.4k
  match_data->subject_length = length;
8218
87.4k
  match_data->start_offset = start_offset;
8219
87.4k
  match_data->rc = PCRE2_ERROR_NOMATCH;
8220
87.4k
  }
8221
8222
126k
return match_data->rc;
8223
168k
}
8224
8225
/* These #undefs are here to enable unity builds with CMake. */
8226
8227
#undef NLBLOCK /* Block containing newline information */
8228
#undef PSSTART /* Field containing processed string start */
8229
#undef PSEND   /* Field containing processed string end */
8230
8231
/* End of pcre2_match.c */