• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSRegularExpression segfault
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSRegularExpression segfault


  • Subject: Re: NSRegularExpression segfault
  • From: "Stephen J. Butler" <email@hidden>
  • Date: Mon, 15 Dec 2014 11:09:26 -0600

If you read the ICU docs on regular expressions you'll see that it sets an
8MB limit on head size when evaluating. My guess is that you've run into
this and NSRegularExpression misses a return code somewhere.

But your pattern is really suboptimal for what you're trying to accomplish.
For example, this pattern is functionally equivalent and doesn't cause a
crash for me:

    @"(([0-9a])\\2*)"

That matches a single character, and then the same character 0 or more
times.

On Mon, Dec 15, 2014 at 10:38 AM, ecir hana <email@hidden> wrote:
>
> Hi!
>
> I recently needed to match some patterns but I encountered a problematic
> situation.
>
> Please, can anyone explain to me why does the following program
> consistently segfault after 50000 characters? I'm running 10.9.5...
>
>     #import <Cocoa/Cocoa.h>
>
>     int main () {
>         NSString *pattern =
> @"(1+)|(2+)|(3+)|(4+)|(5+)|(6+)|(7+)|(8+)|(9+)|(0+)|(a+)";
>         NSRegularExpression *expression = [NSRegularExpression
> regularExpressionWithPattern:pattern options:0 error:nil];
>         for (NSUInteger i = 0; i < 100000; i += 10000) {
>             NSString *string = [@"" stringByPaddingToLength:i withString:@
> "a"
> startingAtIndex:0];
>             NSTextCheckingResult *result = [expression
> firstMatchInString:string options:0 range:NSMakeRange(0, i)];
>             NSLog(@"%@", NSStringFromRange([result range]));
>         }
>         return 0;
>     }
>
> It says:
>
>     {0, 0}
>     {0, 10000}
>     {0, 20000}
>     {0, 30000}
>     {0, 40000}
>     {0, 50000}
>     Segmentation fault: 11
>
> Thanks in advance!
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
>
> This email sent to email@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSRegularExpression segfault
      • From: ecir hana <email@hidden>
References: 
 >NSRegularExpression segfault (From: ecir hana <email@hidden>)

  • Prev by Date: Re: NSRegularExpression segfault
  • Next by Date: Re: NSRegularExpression segfault
  • Previous by thread: Re: NSRegularExpression segfault
  • Next by thread: Re: NSRegularExpression segfault
  • Index(es):
    • Date
    • Thread