Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
(?# # Adapted for PHP by Paul Buonopane of NamePros https://www.namepros.com/ # Based heavily on the following works: # - https://manishearth.github.io/blog/2018/02/15/picking-apart-the-crashing-ios-string/ # - https://github.com/hackbunny/viramarama # # This PHP regex will match any string that contains Indic character # combinations known to crash many iOS applications as of 11.2.5 and certain # macOS combinations as of 10.13.3. # # IMPORTANT: This will only work if you use the `x` and `u` modifiers. # Example: "/regex-goes-here/xu" # # COMPATIBILITY: While PHP does use PCRE, the `u` modifier isn't technically # Perl-compatible. For this to work without the `u` modifier, # the regex would need to be adapted to use | instead of [], # as all of these characters are multibyte in all popular web # encodings, e.g. UTF-8. # # Tracked By: rdar://37458268 # https://openradar.appspot.com/37458268 # Date Originated: 2018-02-12 # CVE ID: Unknown as of writing #) (?(DEFINE) (?<zwnj> (?# You can't see me, but I'm here!)) (?<devanagari_virama> ) (?<devanagari_consonants> [कखगघङहचछजझञयशटठडढणरषतथदधनलसपफबभमव]) (?<devanagari_sj_consonants> []) (?<devanagari_pj_pairs> (?&devanagari_virama)) (?<devanagari_vowels> [ऺऻािीुूृॄॅॆेैॉॊोौॎॏॕॖॗॢॣ]) (?<bengali_virama> ) (?<bengali_consonants> [কখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরৰলৱশষসহ]) (?<bengali_sj_consonants> [যর]) (?<bengali_pj_pairs> [রৰ](?&bengali_virama)) (?<bengali_vowels> [ািীুূৃৄেৈৢৣ]) (?<telugu_virama> ) (?<telugu_consonants> [కఖగఘఙచఛజఝఞటఠడఢణతథదధనపఫబభమయరలవళశషసహఱ]) (?<telugu_sj_consonants> (?&telugu_consonants)) (?<telugu_vowels> [ాిీుూృౄెేొోౌౢౣ]) ) (?!(?&devanagari_pj_pairs)) (?&devanagari_consonants) (?&devanagari_virama) (?&devanagari_sj_consonants) (?&zwnj) (?&devanagari_vowels) | (?!(?&bengali_pj_pairs)) (?&bengali_consonants) (?&bengali_virama) (?&bengali_sj_consonants) (?&zwnj) (?&bengali_vowels) | (?&telugu_consonants) (?&telugu_virama) (?&telugu_sj_consonants) (?&zwnj) (?&telugu_vowels)
/
xu

Description

This PHP regex will match any string that contains Indic character combinations known to crash many iOS applications as of 11.2.5 and certain macOS combinations as of 10.13.3. The crash occurs in CoreText.

Notes

This regex will only work if you use the x and u modifiers. Example: "/regex-goes-here/xu"

While PHP does use PCRE, the u modifier isn't technically Perl-compatible. For this to work without the u modifier, the regex would need to be adapted to use | instead of [], as all of these characters are multibyte in all popular web encodings, e.g. UTF-8.

Vuln info

Tracked By: rdar://37458268 Date Originated: 2018-02-12 CVE ID: Unknown as of writing

Credits

Adapted for PHP by Paul Buonopane of NamePros.

Based heavily on the following works:

License

The license for the work on which this regex is based is provided below, with an additional note regarding adaptation.

Copyright 2018 hackbunny <hackbunny@gmail.com> Adapted for PHP by Paul Buonopane

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Submitted by Paul Buonopane @ NamePros - 7 years ago