pcre2_auto_possess.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. /*************************************************
  2. * Perl-Compatible Regular Expressions *
  3. *************************************************/
  4. /* PCRE is a library of functions to support regular expressions whose syntax
  5. and semantics are as close as possible to those of the Perl 5 language.
  6. Written by Philip Hazel
  7. Original API code Copyright (c) 1997-2012 University of Cambridge
  8. New API code Copyright (c) 2016-2017 University of Cambridge
  9. -----------------------------------------------------------------------------
  10. Redistribution and use in source and binary forms, with or without
  11. modification, are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. * Neither the name of the University of Cambridge nor the names of its
  18. contributors may be used to endorse or promote products derived from
  19. this software without specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  24. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  25. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  26. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  28. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  30. POSSIBILITY OF SUCH DAMAGE.
  31. -----------------------------------------------------------------------------
  32. */
  33. /* This module contains functions that scan a compiled pattern and change
  34. repeats into possessive repeats where possible. */
  35. #ifdef HAVE_CONFIG_H
  36. #include "config.h"
  37. #endif
  38. #include "pcre2_internal.h"
  39. /*************************************************
  40. * Tables for auto-possessification *
  41. *************************************************/
  42. /* This table is used to check whether auto-possessification is possible
  43. between adjacent character-type opcodes. The left-hand (repeated) opcode is
  44. used to select the row, and the right-hand opcode is use to select the column.
  45. A value of 1 means that auto-possessification is OK. For example, the second
  46. value in the first row means that \D+\d can be turned into \D++\d.
  47. The Unicode property types (\P and \p) have to be present to fill out the table
  48. because of what their opcode values are, but the table values should always be
  49. zero because property types are handled separately in the code. The last four
  50. columns apply to items that cannot be repeated, so there is no need to have
  51. rows for them. Note that OP_DIGIT etc. are generated only when PCRE_UCP is
  52. *not* set. When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */
  53. #define APTROWS (LAST_AUTOTAB_LEFT_OP - FIRST_AUTOTAB_OP + 1)
  54. #define APTCOLS (LAST_AUTOTAB_RIGHT_OP - FIRST_AUTOTAB_OP + 1)
  55. static const uint8_t autoposstab[APTROWS][APTCOLS] = {
  56. /* \D \d \S \s \W \w . .+ \C \P \p \R \H \h \V \v \X \Z \z $ $M */
  57. { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* \D */
  58. { 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1 }, /* \d */
  59. { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1 }, /* \S */
  60. { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* \s */
  61. { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* \W */
  62. { 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1 }, /* \w */
  63. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* . */
  64. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* .+ */
  65. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }, /* \C */
  66. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* \P */
  67. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* \p */
  68. { 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 }, /* \R */
  69. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 }, /* \H */
  70. { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0 }, /* \h */
  71. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0 }, /* \V */
  72. { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0 }, /* \v */
  73. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 } /* \X */
  74. };
  75. #ifdef SUPPORT_UNICODE
  76. /* This table is used to check whether auto-possessification is possible
  77. between adjacent Unicode property opcodes (OP_PROP and OP_NOTPROP). The
  78. left-hand (repeated) opcode is used to select the row, and the right-hand
  79. opcode is used to select the column. The values are as follows:
  80. 0 Always return FALSE (never auto-possessify)
  81. 1 Character groups are distinct (possessify if both are OP_PROP)
  82. 2 Check character categories in the same group (general or particular)
  83. 3 TRUE if the two opcodes are not the same (PROP vs NOTPROP)
  84. 4 Check left general category vs right particular category
  85. 5 Check right general category vs left particular category
  86. 6 Left alphanum vs right general category
  87. 7 Left space vs right general category
  88. 8 Left word vs right general category
  89. 9 Right alphanum vs left general category
  90. 10 Right space vs left general category
  91. 11 Right word vs left general category
  92. 12 Left alphanum vs right particular category
  93. 13 Left space vs right particular category
  94. 14 Left word vs right particular category
  95. 15 Right alphanum vs left particular category
  96. 16 Right space vs left particular category
  97. 17 Right word vs left particular category
  98. */
  99. static const uint8_t propposstab[PT_TABSIZE][PT_TABSIZE] = {
  100. /* ANY LAMP GC PC SC ALNUM SPACE PXSPACE WORD CLIST UCNC */
  101. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* PT_ANY */
  102. { 0, 3, 0, 0, 0, 3, 1, 1, 0, 0, 0 }, /* PT_LAMP */
  103. { 0, 0, 2, 4, 0, 9, 10, 10, 11, 0, 0 }, /* PT_GC */
  104. { 0, 0, 5, 2, 0, 15, 16, 16, 17, 0, 0 }, /* PT_PC */
  105. { 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0 }, /* PT_SC */
  106. { 0, 3, 6, 12, 0, 3, 1, 1, 0, 0, 0 }, /* PT_ALNUM */
  107. { 0, 1, 7, 13, 0, 1, 3, 3, 1, 0, 0 }, /* PT_SPACE */
  108. { 0, 1, 7, 13, 0, 1, 3, 3, 1, 0, 0 }, /* PT_PXSPACE */
  109. { 0, 0, 8, 14, 0, 0, 1, 1, 3, 0, 0 }, /* PT_WORD */
  110. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* PT_CLIST */
  111. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3 } /* PT_UCNC */
  112. };
  113. /* This table is used to check whether auto-possessification is possible
  114. between adjacent Unicode property opcodes (OP_PROP and OP_NOTPROP) when one
  115. specifies a general category and the other specifies a particular category. The
  116. row is selected by the general category and the column by the particular
  117. category. The value is 1 if the particular category is not part of the general
  118. category. */
  119. static const uint8_t catposstab[7][30] = {
  120. /* Cc Cf Cn Co Cs Ll Lm Lo Lt Lu Mc Me Mn Nd Nl No Pc Pd Pe Pf Pi Po Ps Sc Sk Sm So Zl Zp Zs */
  121. { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* C */
  122. { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* L */
  123. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* M */
  124. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* N */
  125. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }, /* P */
  126. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1 }, /* S */
  127. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 } /* Z */
  128. };
  129. /* This table is used when checking ALNUM, (PX)SPACE, SPACE, and WORD against
  130. a general or particular category. The properties in each row are those
  131. that apply to the character set in question. Duplication means that a little
  132. unnecessary work is done when checking, but this keeps things much simpler
  133. because they can all use the same code. For more details see the comment where
  134. this table is used.
  135. Note: SPACE and PXSPACE used to be different because Perl excluded VT from
  136. "space", but from Perl 5.18 it's included, so both categories are treated the
  137. same here. */
  138. static const uint8_t posspropstab[3][4] = {
  139. { ucp_L, ucp_N, ucp_N, ucp_Nl }, /* ALNUM, 3rd and 4th values redundant */
  140. { ucp_Z, ucp_Z, ucp_C, ucp_Cc }, /* SPACE and PXSPACE, 2nd value redundant */
  141. { ucp_L, ucp_N, ucp_P, ucp_Po } /* WORD */
  142. };
  143. #endif /* SUPPORT_UNICODE */
  144. #ifdef SUPPORT_UNICODE
  145. /*************************************************
  146. * Check a character and a property *
  147. *************************************************/
  148. /* This function is called by compare_opcodes() when a property item is
  149. adjacent to a fixed character.
  150. Arguments:
  151. c the character
  152. ptype the property type
  153. pdata the data for the type
  154. negated TRUE if it's a negated property (\P or \p{^)
  155. Returns: TRUE if auto-possessifying is OK
  156. */
  157. static BOOL
  158. check_char_prop(uint32_t c, unsigned int ptype, unsigned int pdata,
  159. BOOL negated)
  160. {
  161. const uint32_t *p;
  162. const ucd_record *prop = GET_UCD(c);
  163. switch(ptype)
  164. {
  165. case PT_LAMP:
  166. return (prop->chartype == ucp_Lu ||
  167. prop->chartype == ucp_Ll ||
  168. prop->chartype == ucp_Lt) == negated;
  169. case PT_GC:
  170. return (pdata == PRIV(ucp_gentype)[prop->chartype]) == negated;
  171. case PT_PC:
  172. return (pdata == prop->chartype) == negated;
  173. case PT_SC:
  174. return (pdata == prop->script) == negated;
  175. /* These are specials */
  176. case PT_ALNUM:
  177. return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
  178. PRIV(ucp_gentype)[prop->chartype] == ucp_N) == negated;
  179. /* Perl space used to exclude VT, but from Perl 5.18 it is included, which
  180. means that Perl space and POSIX space are now identical. PCRE was changed
  181. at release 8.34. */
  182. case PT_SPACE: /* Perl space */
  183. case PT_PXSPACE: /* POSIX space */
  184. switch(c)
  185. {
  186. HSPACE_CASES:
  187. VSPACE_CASES:
  188. return negated;
  189. default:
  190. return (PRIV(ucp_gentype)[prop->chartype] == ucp_Z) == negated;
  191. }
  192. break; /* Control never reaches here */
  193. case PT_WORD:
  194. return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
  195. PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
  196. c == CHAR_UNDERSCORE) == negated;
  197. case PT_CLIST:
  198. p = PRIV(ucd_caseless_sets) + prop->caseset;
  199. for (;;)
  200. {
  201. if (c < *p) return !negated;
  202. if (c == *p++) return negated;
  203. }
  204. break; /* Control never reaches here */
  205. }
  206. return FALSE;
  207. }
  208. #endif /* SUPPORT_UNICODE */
  209. /*************************************************
  210. * Base opcode of repeated opcodes *
  211. *************************************************/
  212. /* Returns the base opcode for repeated single character type opcodes. If the
  213. opcode is not a repeated character type, it returns with the original value.
  214. Arguments: c opcode
  215. Returns: base opcode for the type
  216. */
  217. static PCRE2_UCHAR
  218. get_repeat_base(PCRE2_UCHAR c)
  219. {
  220. return (c > OP_TYPEPOSUPTO)? c :
  221. (c >= OP_TYPESTAR)? OP_TYPESTAR :
  222. (c >= OP_NOTSTARI)? OP_NOTSTARI :
  223. (c >= OP_NOTSTAR)? OP_NOTSTAR :
  224. (c >= OP_STARI)? OP_STARI :
  225. OP_STAR;
  226. }
  227. /*************************************************
  228. * Fill the character property list *
  229. *************************************************/
  230. /* Checks whether the code points to an opcode that can take part in auto-
  231. possessification, and if so, fills a list with its properties.
  232. Arguments:
  233. code points to start of expression
  234. utf TRUE if in UTF mode
  235. fcc points to the case-flipping table
  236. list points to output list
  237. list[0] will be filled with the opcode
  238. list[1] will be non-zero if this opcode
  239. can match an empty character string
  240. list[2..7] depends on the opcode
  241. Returns: points to the start of the next opcode if *code is accepted
  242. NULL if *code is not accepted
  243. */
  244. static PCRE2_SPTR
  245. get_chr_property_list(PCRE2_SPTR code, BOOL utf, const uint8_t *fcc,
  246. uint32_t *list)
  247. {
  248. PCRE2_UCHAR c = *code;
  249. PCRE2_UCHAR base;
  250. PCRE2_SPTR end;
  251. uint32_t chr;
  252. #ifdef SUPPORT_UNICODE
  253. uint32_t *clist_dest;
  254. const uint32_t *clist_src;
  255. #else
  256. (void)utf; /* Suppress "unused parameter" compiler warning */
  257. #endif
  258. list[0] = c;
  259. list[1] = FALSE;
  260. code++;
  261. if (c >= OP_STAR && c <= OP_TYPEPOSUPTO)
  262. {
  263. base = get_repeat_base(c);
  264. c -= (base - OP_STAR);
  265. if (c == OP_UPTO || c == OP_MINUPTO || c == OP_EXACT || c == OP_POSUPTO)
  266. code += IMM2_SIZE;
  267. list[1] = (c != OP_PLUS && c != OP_MINPLUS && c != OP_EXACT &&
  268. c != OP_POSPLUS);
  269. switch(base)
  270. {
  271. case OP_STAR:
  272. list[0] = OP_CHAR;
  273. break;
  274. case OP_STARI:
  275. list[0] = OP_CHARI;
  276. break;
  277. case OP_NOTSTAR:
  278. list[0] = OP_NOT;
  279. break;
  280. case OP_NOTSTARI:
  281. list[0] = OP_NOTI;
  282. break;
  283. case OP_TYPESTAR:
  284. list[0] = *code;
  285. code++;
  286. break;
  287. }
  288. c = list[0];
  289. }
  290. switch(c)
  291. {
  292. case OP_NOT_DIGIT:
  293. case OP_DIGIT:
  294. case OP_NOT_WHITESPACE:
  295. case OP_WHITESPACE:
  296. case OP_NOT_WORDCHAR:
  297. case OP_WORDCHAR:
  298. case OP_ANY:
  299. case OP_ALLANY:
  300. case OP_ANYNL:
  301. case OP_NOT_HSPACE:
  302. case OP_HSPACE:
  303. case OP_NOT_VSPACE:
  304. case OP_VSPACE:
  305. case OP_EXTUNI:
  306. case OP_EODN:
  307. case OP_EOD:
  308. case OP_DOLL:
  309. case OP_DOLLM:
  310. return code;
  311. case OP_CHAR:
  312. case OP_NOT:
  313. GETCHARINCTEST(chr, code);
  314. list[2] = chr;
  315. list[3] = NOTACHAR;
  316. return code;
  317. case OP_CHARI:
  318. case OP_NOTI:
  319. list[0] = (c == OP_CHARI) ? OP_CHAR : OP_NOT;
  320. GETCHARINCTEST(chr, code);
  321. list[2] = chr;
  322. #ifdef SUPPORT_UNICODE
  323. if (chr < 128 || (chr < 256 && !utf))
  324. list[3] = fcc[chr];
  325. else
  326. list[3] = UCD_OTHERCASE(chr);
  327. #elif defined SUPPORT_WIDE_CHARS
  328. list[3] = (chr < 256) ? fcc[chr] : chr;
  329. #else
  330. list[3] = fcc[chr];
  331. #endif
  332. /* The othercase might be the same value. */
  333. if (chr == list[3])
  334. list[3] = NOTACHAR;
  335. else
  336. list[4] = NOTACHAR;
  337. return code;
  338. #ifdef SUPPORT_UNICODE
  339. case OP_PROP:
  340. case OP_NOTPROP:
  341. if (code[0] != PT_CLIST)
  342. {
  343. list[2] = code[0];
  344. list[3] = code[1];
  345. return code + 2;
  346. }
  347. /* Convert only if we have enough space. */
  348. clist_src = PRIV(ucd_caseless_sets) + code[1];
  349. clist_dest = list + 2;
  350. code += 2;
  351. do {
  352. if (clist_dest >= list + 8)
  353. {
  354. /* Early return if there is not enough space. This should never
  355. happen, since all clists are shorter than 5 character now. */
  356. list[2] = code[0];
  357. list[3] = code[1];
  358. return code;
  359. }
  360. *clist_dest++ = *clist_src;
  361. }
  362. while(*clist_src++ != NOTACHAR);
  363. /* All characters are stored. The terminating NOTACHAR is copied from the
  364. clist itself. */
  365. list[0] = (c == OP_PROP) ? OP_CHAR : OP_NOT;
  366. return code;
  367. #endif
  368. case OP_NCLASS:
  369. case OP_CLASS:
  370. #ifdef SUPPORT_WIDE_CHARS
  371. case OP_XCLASS:
  372. if (c == OP_XCLASS)
  373. end = code + GET(code, 0) - 1;
  374. else
  375. #endif
  376. end = code + 32 / sizeof(PCRE2_UCHAR);
  377. switch(*end)
  378. {
  379. case OP_CRSTAR:
  380. case OP_CRMINSTAR:
  381. case OP_CRQUERY:
  382. case OP_CRMINQUERY:
  383. case OP_CRPOSSTAR:
  384. case OP_CRPOSQUERY:
  385. list[1] = TRUE;
  386. end++;
  387. break;
  388. case OP_CRPLUS:
  389. case OP_CRMINPLUS:
  390. case OP_CRPOSPLUS:
  391. end++;
  392. break;
  393. case OP_CRRANGE:
  394. case OP_CRMINRANGE:
  395. case OP_CRPOSRANGE:
  396. list[1] = (GET2(end, 1) == 0);
  397. end += 1 + 2 * IMM2_SIZE;
  398. break;
  399. }
  400. list[2] = (uint32_t)(end - code);
  401. return end;
  402. }
  403. return NULL; /* Opcode not accepted */
  404. }
  405. /*************************************************
  406. * Scan further character sets for match *
  407. *************************************************/
  408. /* Checks whether the base and the current opcode have a common character, in
  409. which case the base cannot be possessified.
  410. Arguments:
  411. code points to the byte code
  412. utf TRUE in UTF mode
  413. cb compile data block
  414. base_list the data list of the base opcode
  415. base_end the end of the data list
  416. rec_limit points to recursion depth counter
  417. Returns: TRUE if the auto-possessification is possible
  418. */
  419. static BOOL
  420. compare_opcodes(PCRE2_SPTR code, BOOL utf, const compile_block *cb,
  421. const uint32_t *base_list, PCRE2_SPTR base_end, int *rec_limit)
  422. {
  423. PCRE2_UCHAR c;
  424. uint32_t list[8];
  425. const uint32_t *chr_ptr;
  426. const uint32_t *ochr_ptr;
  427. const uint32_t *list_ptr;
  428. PCRE2_SPTR next_code;
  429. #ifdef SUPPORT_WIDE_CHARS
  430. PCRE2_SPTR xclass_flags;
  431. #endif
  432. const uint8_t *class_bitset;
  433. const uint8_t *set1, *set2, *set_end;
  434. uint32_t chr;
  435. BOOL accepted, invert_bits;
  436. BOOL entered_a_group = FALSE;
  437. if (--(*rec_limit) <= 0) return FALSE; /* Recursion has gone too deep */
  438. /* Note: the base_list[1] contains whether the current opcode has a greedy
  439. (represented by a non-zero value) quantifier. This is a different from
  440. other character type lists, which store here that the character iterator
  441. matches to an empty string (also represented by a non-zero value). */
  442. for(;;)
  443. {
  444. /* All operations move the code pointer forward.
  445. Therefore infinite recursions are not possible. */
  446. c = *code;
  447. /* Skip over callouts */
  448. if (c == OP_CALLOUT)
  449. {
  450. code += PRIV(OP_lengths)[c];
  451. continue;
  452. }
  453. if (c == OP_CALLOUT_STR)
  454. {
  455. code += GET(code, 1 + 2*LINK_SIZE);
  456. continue;
  457. }
  458. /* At the end of a branch, skip to the end of the group. */
  459. if (c == OP_ALT)
  460. {
  461. do code += GET(code, 1); while (*code == OP_ALT);
  462. c = *code;
  463. }
  464. /* Inspect the next opcode. */
  465. switch(c)
  466. {
  467. /* We can always possessify a greedy iterator at the end of the pattern,
  468. which is reached after skipping over the final OP_KET. A non-greedy
  469. iterator must never be possessified. */
  470. case OP_END:
  471. return base_list[1] != 0;
  472. /* When an iterator is at the end of certain kinds of group we can inspect
  473. what follows the group by skipping over the closing ket. Note that this
  474. does not apply to OP_KETRMAX or OP_KETRMIN because what follows any given
  475. iteration is variable (could be another iteration or could be the next
  476. item). As these two opcodes are not listed in the next switch, they will
  477. end up as the next code to inspect, and return FALSE by virtue of being
  478. unsupported. */
  479. case OP_KET:
  480. case OP_KETRPOS:
  481. /* The non-greedy case cannot be converted to a possessive form. */
  482. if (base_list[1] == 0) return FALSE;
  483. /* If the bracket is capturing it might be referenced by an OP_RECURSE
  484. so its last iterator can never be possessified if the pattern contains
  485. recursions. (This could be improved by keeping a list of group numbers that
  486. are called by recursion.) */
  487. switch(*(code - GET(code, 1)))
  488. {
  489. case OP_CBRA:
  490. case OP_SCBRA:
  491. case OP_CBRAPOS:
  492. case OP_SCBRAPOS:
  493. if (cb->had_recurse) return FALSE;
  494. break;
  495. /* Atomic sub-patterns and assertions can always auto-possessify their
  496. last iterator. However, if the group was entered as a result of checking
  497. a previous iterator, this is not possible. */
  498. case OP_ASSERT:
  499. case OP_ASSERT_NOT:
  500. case OP_ASSERTBACK:
  501. case OP_ASSERTBACK_NOT:
  502. case OP_ONCE:
  503. return !entered_a_group;
  504. }
  505. /* Skip over the bracket and inspect what comes next. */
  506. code += PRIV(OP_lengths)[c];
  507. continue;
  508. /* Handle cases where the next item is a group. */
  509. case OP_ONCE:
  510. case OP_BRA:
  511. case OP_CBRA:
  512. next_code = code + GET(code, 1);
  513. code += PRIV(OP_lengths)[c];
  514. /* Check each branch. We have to recurse a level for all but the last
  515. branch. */
  516. while (*next_code == OP_ALT)
  517. {
  518. if (!compare_opcodes(code, utf, cb, base_list, base_end, rec_limit))
  519. return FALSE;
  520. code = next_code + 1 + LINK_SIZE;
  521. next_code += GET(next_code, 1);
  522. }
  523. entered_a_group = TRUE;
  524. continue;
  525. case OP_BRAZERO:
  526. case OP_BRAMINZERO:
  527. next_code = code + 1;
  528. if (*next_code != OP_BRA && *next_code != OP_CBRA &&
  529. *next_code != OP_ONCE) return FALSE;
  530. do next_code += GET(next_code, 1); while (*next_code == OP_ALT);
  531. /* The bracket content will be checked by the OP_BRA/OP_CBRA case above. */
  532. next_code += 1 + LINK_SIZE;
  533. if (!compare_opcodes(next_code, utf, cb, base_list, base_end, rec_limit))
  534. return FALSE;
  535. code += PRIV(OP_lengths)[c];
  536. continue;
  537. /* The next opcode does not need special handling; fall through and use it
  538. to see if the base can be possessified. */
  539. default:
  540. break;
  541. }
  542. /* We now have the next appropriate opcode to compare with the base. Check
  543. for a supported opcode, and load its properties. */
  544. code = get_chr_property_list(code, utf, cb->fcc, list);
  545. if (code == NULL) return FALSE; /* Unsupported */
  546. /* If either opcode is a small character list, set pointers for comparing
  547. characters from that list with another list, or with a property. */
  548. if (base_list[0] == OP_CHAR)
  549. {
  550. chr_ptr = base_list + 2;
  551. list_ptr = list;
  552. }
  553. else if (list[0] == OP_CHAR)
  554. {
  555. chr_ptr = list + 2;
  556. list_ptr = base_list;
  557. }
  558. /* Character bitsets can also be compared to certain opcodes. */
  559. else if (base_list[0] == OP_CLASS || list[0] == OP_CLASS
  560. #if PCRE2_CODE_UNIT_WIDTH == 8
  561. /* In 8 bit, non-UTF mode, OP_CLASS and OP_NCLASS are the same. */
  562. || (!utf && (base_list[0] == OP_NCLASS || list[0] == OP_NCLASS))
  563. #endif
  564. )
  565. {
  566. #if PCRE2_CODE_UNIT_WIDTH == 8
  567. if (base_list[0] == OP_CLASS || (!utf && base_list[0] == OP_NCLASS))
  568. #else
  569. if (base_list[0] == OP_CLASS)
  570. #endif
  571. {
  572. set1 = (uint8_t *)(base_end - base_list[2]);
  573. list_ptr = list;
  574. }
  575. else
  576. {
  577. set1 = (uint8_t *)(code - list[2]);
  578. list_ptr = base_list;
  579. }
  580. invert_bits = FALSE;
  581. switch(list_ptr[0])
  582. {
  583. case OP_CLASS:
  584. case OP_NCLASS:
  585. set2 = (uint8_t *)
  586. ((list_ptr == list ? code : base_end) - list_ptr[2]);
  587. break;
  588. #ifdef SUPPORT_WIDE_CHARS
  589. case OP_XCLASS:
  590. xclass_flags = (list_ptr == list ? code : base_end) - list_ptr[2] + LINK_SIZE;
  591. if ((*xclass_flags & XCL_HASPROP) != 0) return FALSE;
  592. if ((*xclass_flags & XCL_MAP) == 0)
  593. {
  594. /* No bits are set for characters < 256. */
  595. if (list[1] == 0) return TRUE;
  596. /* Might be an empty repeat. */
  597. continue;
  598. }
  599. set2 = (uint8_t *)(xclass_flags + 1);
  600. break;
  601. #endif
  602. case OP_NOT_DIGIT:
  603. invert_bits = TRUE;
  604. /* Fall through */
  605. case OP_DIGIT:
  606. set2 = (uint8_t *)(cb->cbits + cbit_digit);
  607. break;
  608. case OP_NOT_WHITESPACE:
  609. invert_bits = TRUE;
  610. /* Fall through */
  611. case OP_WHITESPACE:
  612. set2 = (uint8_t *)(cb->cbits + cbit_space);
  613. break;
  614. case OP_NOT_WORDCHAR:
  615. invert_bits = TRUE;
  616. /* Fall through */
  617. case OP_WORDCHAR:
  618. set2 = (uint8_t *)(cb->cbits + cbit_word);
  619. break;
  620. default:
  621. return FALSE;
  622. }
  623. /* Because the bit sets are unaligned bytes, we need to perform byte
  624. comparison here. */
  625. set_end = set1 + 32;
  626. if (invert_bits)
  627. {
  628. do
  629. {
  630. if ((*set1++ & ~(*set2++)) != 0) return FALSE;
  631. }
  632. while (set1 < set_end);
  633. }
  634. else
  635. {
  636. do
  637. {
  638. if ((*set1++ & *set2++) != 0) return FALSE;
  639. }
  640. while (set1 < set_end);
  641. }
  642. if (list[1] == 0) return TRUE;
  643. /* Might be an empty repeat. */
  644. continue;
  645. }
  646. /* Some property combinations also acceptable. Unicode property opcodes are
  647. processed specially; the rest can be handled with a lookup table. */
  648. else
  649. {
  650. uint32_t leftop, rightop;
  651. leftop = base_list[0];
  652. rightop = list[0];
  653. #ifdef SUPPORT_UNICODE
  654. accepted = FALSE; /* Always set in non-unicode case. */
  655. if (leftop == OP_PROP || leftop == OP_NOTPROP)
  656. {
  657. if (rightop == OP_EOD)
  658. accepted = TRUE;
  659. else if (rightop == OP_PROP || rightop == OP_NOTPROP)
  660. {
  661. int n;
  662. const uint8_t *p;
  663. BOOL same = leftop == rightop;
  664. BOOL lisprop = leftop == OP_PROP;
  665. BOOL risprop = rightop == OP_PROP;
  666. BOOL bothprop = lisprop && risprop;
  667. /* There's a table that specifies how each combination is to be
  668. processed:
  669. 0 Always return FALSE (never auto-possessify)
  670. 1 Character groups are distinct (possessify if both are OP_PROP)
  671. 2 Check character categories in the same group (general or particular)
  672. 3 Return TRUE if the two opcodes are not the same
  673. ... see comments below
  674. */
  675. n = propposstab[base_list[2]][list[2]];
  676. switch(n)
  677. {
  678. case 0: break;
  679. case 1: accepted = bothprop; break;
  680. case 2: accepted = (base_list[3] == list[3]) != same; break;
  681. case 3: accepted = !same; break;
  682. case 4: /* Left general category, right particular category */
  683. accepted = risprop && catposstab[base_list[3]][list[3]] == same;
  684. break;
  685. case 5: /* Right general category, left particular category */
  686. accepted = lisprop && catposstab[list[3]][base_list[3]] == same;
  687. break;
  688. /* This code is logically tricky. Think hard before fiddling with it.
  689. The posspropstab table has four entries per row. Each row relates to
  690. one of PCRE's special properties such as ALNUM or SPACE or WORD.
  691. Only WORD actually needs all four entries, but using repeats for the
  692. others means they can all use the same code below.
  693. The first two entries in each row are Unicode general categories, and
  694. apply always, because all the characters they include are part of the
  695. PCRE character set. The third and fourth entries are a general and a
  696. particular category, respectively, that include one or more relevant
  697. characters. One or the other is used, depending on whether the check
  698. is for a general or a particular category. However, in both cases the
  699. category contains more characters than the specials that are defined
  700. for the property being tested against. Therefore, it cannot be used
  701. in a NOTPROP case.
  702. Example: the row for WORD contains ucp_L, ucp_N, ucp_P, ucp_Po.
  703. Underscore is covered by ucp_P or ucp_Po. */
  704. case 6: /* Left alphanum vs right general category */
  705. case 7: /* Left space vs right general category */
  706. case 8: /* Left word vs right general category */
  707. p = posspropstab[n-6];
  708. accepted = risprop && lisprop ==
  709. (list[3] != p[0] &&
  710. list[3] != p[1] &&
  711. (list[3] != p[2] || !lisprop));
  712. break;
  713. case 9: /* Right alphanum vs left general category */
  714. case 10: /* Right space vs left general category */
  715. case 11: /* Right word vs left general category */
  716. p = posspropstab[n-9];
  717. accepted = lisprop && risprop ==
  718. (base_list[3] != p[0] &&
  719. base_list[3] != p[1] &&
  720. (base_list[3] != p[2] || !risprop));
  721. break;
  722. case 12: /* Left alphanum vs right particular category */
  723. case 13: /* Left space vs right particular category */
  724. case 14: /* Left word vs right particular category */
  725. p = posspropstab[n-12];
  726. accepted = risprop && lisprop ==
  727. (catposstab[p[0]][list[3]] &&
  728. catposstab[p[1]][list[3]] &&
  729. (list[3] != p[3] || !lisprop));
  730. break;
  731. case 15: /* Right alphanum vs left particular category */
  732. case 16: /* Right space vs left particular category */
  733. case 17: /* Right word vs left particular category */
  734. p = posspropstab[n-15];
  735. accepted = lisprop && risprop ==
  736. (catposstab[p[0]][base_list[3]] &&
  737. catposstab[p[1]][base_list[3]] &&
  738. (base_list[3] != p[3] || !risprop));
  739. break;
  740. }
  741. }
  742. }
  743. else
  744. #endif /* SUPPORT_UNICODE */
  745. accepted = leftop >= FIRST_AUTOTAB_OP && leftop <= LAST_AUTOTAB_LEFT_OP &&
  746. rightop >= FIRST_AUTOTAB_OP && rightop <= LAST_AUTOTAB_RIGHT_OP &&
  747. autoposstab[leftop - FIRST_AUTOTAB_OP][rightop - FIRST_AUTOTAB_OP];
  748. if (!accepted) return FALSE;
  749. if (list[1] == 0) return TRUE;
  750. /* Might be an empty repeat. */
  751. continue;
  752. }
  753. /* Control reaches here only if one of the items is a small character list.
  754. All characters are checked against the other side. */
  755. do
  756. {
  757. chr = *chr_ptr;
  758. switch(list_ptr[0])
  759. {
  760. case OP_CHAR:
  761. ochr_ptr = list_ptr + 2;
  762. do
  763. {
  764. if (chr == *ochr_ptr) return FALSE;
  765. ochr_ptr++;
  766. }
  767. while(*ochr_ptr != NOTACHAR);
  768. break;
  769. case OP_NOT:
  770. ochr_ptr = list_ptr + 2;
  771. do
  772. {
  773. if (chr == *ochr_ptr)
  774. break;
  775. ochr_ptr++;
  776. }
  777. while(*ochr_ptr != NOTACHAR);
  778. if (*ochr_ptr == NOTACHAR) return FALSE; /* Not found */
  779. break;
  780. /* Note that OP_DIGIT etc. are generated only when PCRE2_UCP is *not*
  781. set. When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */
  782. case OP_DIGIT:
  783. if (chr < 256 && (cb->ctypes[chr] & ctype_digit) != 0) return FALSE;
  784. break;
  785. case OP_NOT_DIGIT:
  786. if (chr > 255 || (cb->ctypes[chr] & ctype_digit) == 0) return FALSE;
  787. break;
  788. case OP_WHITESPACE:
  789. if (chr < 256 && (cb->ctypes[chr] & ctype_space) != 0) return FALSE;
  790. break;
  791. case OP_NOT_WHITESPACE:
  792. if (chr > 255 || (cb->ctypes[chr] & ctype_space) == 0) return FALSE;
  793. break;
  794. case OP_WORDCHAR:
  795. if (chr < 255 && (cb->ctypes[chr] & ctype_word) != 0) return FALSE;
  796. break;
  797. case OP_NOT_WORDCHAR:
  798. if (chr > 255 || (cb->ctypes[chr] & ctype_word) == 0) return FALSE;
  799. break;
  800. case OP_HSPACE:
  801. switch(chr)
  802. {
  803. HSPACE_CASES: return FALSE;
  804. default: break;
  805. }
  806. break;
  807. case OP_NOT_HSPACE:
  808. switch(chr)
  809. {
  810. HSPACE_CASES: break;
  811. default: return FALSE;
  812. }
  813. break;
  814. case OP_ANYNL:
  815. case OP_VSPACE:
  816. switch(chr)
  817. {
  818. VSPACE_CASES: return FALSE;
  819. default: break;
  820. }
  821. break;
  822. case OP_NOT_VSPACE:
  823. switch(chr)
  824. {
  825. VSPACE_CASES: break;
  826. default: return FALSE;
  827. }
  828. break;
  829. case OP_DOLL:
  830. case OP_EODN:
  831. switch (chr)
  832. {
  833. case CHAR_CR:
  834. case CHAR_LF:
  835. case CHAR_VT:
  836. case CHAR_FF:
  837. case CHAR_NEL:
  838. #ifndef EBCDIC
  839. case 0x2028:
  840. case 0x2029:
  841. #endif /* Not EBCDIC */
  842. return FALSE;
  843. }
  844. break;
  845. case OP_EOD: /* Can always possessify before \z */
  846. break;
  847. #ifdef SUPPORT_UNICODE
  848. case OP_PROP:
  849. case OP_NOTPROP:
  850. if (!check_char_prop(chr, list_ptr[2], list_ptr[3],
  851. list_ptr[0] == OP_NOTPROP))
  852. return FALSE;
  853. break;
  854. #endif
  855. case OP_NCLASS:
  856. if (chr > 255) return FALSE;
  857. /* Fall through */
  858. case OP_CLASS:
  859. if (chr > 255) break;
  860. class_bitset = (uint8_t *)
  861. ((list_ptr == list ? code : base_end) - list_ptr[2]);
  862. if ((class_bitset[chr >> 3] & (1 << (chr & 7))) != 0) return FALSE;
  863. break;
  864. #ifdef SUPPORT_WIDE_CHARS
  865. case OP_XCLASS:
  866. if (PRIV(xclass)(chr, (list_ptr == list ? code : base_end) -
  867. list_ptr[2] + LINK_SIZE, utf)) return FALSE;
  868. break;
  869. #endif
  870. default:
  871. return FALSE;
  872. }
  873. chr_ptr++;
  874. }
  875. while(*chr_ptr != NOTACHAR);
  876. /* At least one character must be matched from this opcode. */
  877. if (list[1] == 0) return TRUE;
  878. }
  879. /* Control never reaches here. There used to be a fail-save return FALSE; here,
  880. but some compilers complain about an unreachable statement. */
  881. }
  882. /*************************************************
  883. * Scan compiled regex for auto-possession *
  884. *************************************************/
  885. /* Replaces single character iterations with their possessive alternatives
  886. if appropriate. This function modifies the compiled opcode! Hitting a
  887. non-existent opcode may indicate a bug in PCRE2, but it can also be caused if a
  888. bad UTF string was compiled with PCRE2_NO_UTF_CHECK. The rec_limit catches
  889. overly complicated or large patterns. In these cases, the check just stops,
  890. leaving the remainder of the pattern unpossessified.
  891. Arguments:
  892. code points to start of the byte code
  893. utf TRUE in UTF mode
  894. cb compile data block
  895. Returns: 0 for success
  896. -1 if a non-existant opcode is encountered
  897. */
  898. int
  899. PRIV(auto_possessify)(PCRE2_UCHAR *code, BOOL utf, const compile_block *cb)
  900. {
  901. PCRE2_UCHAR c;
  902. PCRE2_SPTR end;
  903. PCRE2_UCHAR *repeat_opcode;
  904. uint32_t list[8];
  905. int rec_limit = 1000; /* Was 10,000 but clang+ASAN uses a lot of stack. */
  906. for (;;)
  907. {
  908. c = *code;
  909. if (c >= OP_TABLE_LENGTH) return -1; /* Something gone wrong */
  910. if (c >= OP_STAR && c <= OP_TYPEPOSUPTO)
  911. {
  912. c -= get_repeat_base(c) - OP_STAR;
  913. end = (c <= OP_MINUPTO) ?
  914. get_chr_property_list(code, utf, cb->fcc, list) : NULL;
  915. list[1] = c == OP_STAR || c == OP_PLUS || c == OP_QUERY || c == OP_UPTO;
  916. if (end != NULL && compare_opcodes(end, utf, cb, list, end, &rec_limit))
  917. {
  918. switch(c)
  919. {
  920. case OP_STAR:
  921. *code += OP_POSSTAR - OP_STAR;
  922. break;
  923. case OP_MINSTAR:
  924. *code += OP_POSSTAR - OP_MINSTAR;
  925. break;
  926. case OP_PLUS:
  927. *code += OP_POSPLUS - OP_PLUS;
  928. break;
  929. case OP_MINPLUS:
  930. *code += OP_POSPLUS - OP_MINPLUS;
  931. break;
  932. case OP_QUERY:
  933. *code += OP_POSQUERY - OP_QUERY;
  934. break;
  935. case OP_MINQUERY:
  936. *code += OP_POSQUERY - OP_MINQUERY;
  937. break;
  938. case OP_UPTO:
  939. *code += OP_POSUPTO - OP_UPTO;
  940. break;
  941. case OP_MINUPTO:
  942. *code += OP_POSUPTO - OP_MINUPTO;
  943. break;
  944. }
  945. }
  946. c = *code;
  947. }
  948. else if (c == OP_CLASS || c == OP_NCLASS || c == OP_XCLASS)
  949. {
  950. #ifdef SUPPORT_WIDE_CHARS
  951. if (c == OP_XCLASS)
  952. repeat_opcode = code + GET(code, 1);
  953. else
  954. #endif
  955. repeat_opcode = code + 1 + (32 / sizeof(PCRE2_UCHAR));
  956. c = *repeat_opcode;
  957. if (c >= OP_CRSTAR && c <= OP_CRMINRANGE)
  958. {
  959. /* end must not be NULL. */
  960. end = get_chr_property_list(code, utf, cb->fcc, list);
  961. list[1] = (c & 1) == 0;
  962. if (compare_opcodes(end, utf, cb, list, end, &rec_limit))
  963. {
  964. switch (c)
  965. {
  966. case OP_CRSTAR:
  967. case OP_CRMINSTAR:
  968. *repeat_opcode = OP_CRPOSSTAR;
  969. break;
  970. case OP_CRPLUS:
  971. case OP_CRMINPLUS:
  972. *repeat_opcode = OP_CRPOSPLUS;
  973. break;
  974. case OP_CRQUERY:
  975. case OP_CRMINQUERY:
  976. *repeat_opcode = OP_CRPOSQUERY;
  977. break;
  978. case OP_CRRANGE:
  979. case OP_CRMINRANGE:
  980. *repeat_opcode = OP_CRPOSRANGE;
  981. break;
  982. }
  983. }
  984. }
  985. c = *code;
  986. }
  987. switch(c)
  988. {
  989. case OP_END:
  990. return 0;
  991. case OP_TYPESTAR:
  992. case OP_TYPEMINSTAR:
  993. case OP_TYPEPLUS:
  994. case OP_TYPEMINPLUS:
  995. case OP_TYPEQUERY:
  996. case OP_TYPEMINQUERY:
  997. case OP_TYPEPOSSTAR:
  998. case OP_TYPEPOSPLUS:
  999. case OP_TYPEPOSQUERY:
  1000. if (code[1] == OP_PROP || code[1] == OP_NOTPROP) code += 2;
  1001. break;
  1002. case OP_TYPEUPTO:
  1003. case OP_TYPEMINUPTO:
  1004. case OP_TYPEEXACT:
  1005. case OP_TYPEPOSUPTO:
  1006. if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
  1007. code += 2;
  1008. break;
  1009. case OP_CALLOUT_STR:
  1010. code += GET(code, 1 + 2*LINK_SIZE);
  1011. break;
  1012. #ifdef SUPPORT_WIDE_CHARS
  1013. case OP_XCLASS:
  1014. code += GET(code, 1);
  1015. break;
  1016. #endif
  1017. case OP_MARK:
  1018. case OP_PRUNE_ARG:
  1019. case OP_SKIP_ARG:
  1020. case OP_THEN_ARG:
  1021. code += code[1];
  1022. break;
  1023. }
  1024. /* Add in the fixed length from the table */
  1025. code += PRIV(OP_lengths)[c];
  1026. /* In UTF-8 and UTF-16 modes, opcodes that are followed by a character may be
  1027. followed by a multi-byte character. The length in the table is a minimum, so
  1028. we have to arrange to skip the extra code units. */
  1029. #ifdef MAYBE_UTF_MULTI
  1030. if (utf) switch(c)
  1031. {
  1032. case OP_CHAR:
  1033. case OP_CHARI:
  1034. case OP_NOT:
  1035. case OP_NOTI:
  1036. case OP_STAR:
  1037. case OP_MINSTAR:
  1038. case OP_PLUS:
  1039. case OP_MINPLUS:
  1040. case OP_QUERY:
  1041. case OP_MINQUERY:
  1042. case OP_UPTO:
  1043. case OP_MINUPTO:
  1044. case OP_EXACT:
  1045. case OP_POSSTAR:
  1046. case OP_POSPLUS:
  1047. case OP_POSQUERY:
  1048. case OP_POSUPTO:
  1049. case OP_STARI:
  1050. case OP_MINSTARI:
  1051. case OP_PLUSI:
  1052. case OP_MINPLUSI:
  1053. case OP_QUERYI:
  1054. case OP_MINQUERYI:
  1055. case OP_UPTOI:
  1056. case OP_MINUPTOI:
  1057. case OP_EXACTI:
  1058. case OP_POSSTARI:
  1059. case OP_POSPLUSI:
  1060. case OP_POSQUERYI:
  1061. case OP_POSUPTOI:
  1062. case OP_NOTSTAR:
  1063. case OP_NOTMINSTAR:
  1064. case OP_NOTPLUS:
  1065. case OP_NOTMINPLUS:
  1066. case OP_NOTQUERY:
  1067. case OP_NOTMINQUERY:
  1068. case OP_NOTUPTO:
  1069. case OP_NOTMINUPTO:
  1070. case OP_NOTEXACT:
  1071. case OP_NOTPOSSTAR:
  1072. case OP_NOTPOSPLUS:
  1073. case OP_NOTPOSQUERY:
  1074. case OP_NOTPOSUPTO:
  1075. case OP_NOTSTARI:
  1076. case OP_NOTMINSTARI:
  1077. case OP_NOTPLUSI:
  1078. case OP_NOTMINPLUSI:
  1079. case OP_NOTQUERYI:
  1080. case OP_NOTMINQUERYI:
  1081. case OP_NOTUPTOI:
  1082. case OP_NOTMINUPTOI:
  1083. case OP_NOTEXACTI:
  1084. case OP_NOTPOSSTARI:
  1085. case OP_NOTPOSPLUSI:
  1086. case OP_NOTPOSQUERYI:
  1087. case OP_NOTPOSUPTOI:
  1088. if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]);
  1089. break;
  1090. }
  1091. #else
  1092. (void)(utf); /* Keep compiler happy by referencing function argument */
  1093. #endif /* SUPPORT_WIDE_CHARS */
  1094. }
  1095. }
  1096. /* End of pcre2_auto_possess.c */