Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System loop for pattern match #16598

Closed
p5pRT opened this issue Jun 25, 2018 · 5 comments
Closed

System loop for pattern match #16598

p5pRT opened this issue Jun 25, 2018 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 25, 2018

Migrated from rt.perl.org#133302 (status was 'open')

Searchable as RT133302$

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2018

From ph10@hermes.cam.ac.uk

Created by ph10@hermes.cam.ac.uk

While testing PCRE2 I was considering this crazy pattern sent by a user​:

  /(?<=\K.)/g
 
It was being matched against the string "ab". I wanted to see what Perl made of
it, so I fed it to the Perl script I use for comparing Perl output to PCRE2
output. My machine (Arch Linux 4.14.35-1-lts x86_64) went into a tight loop
from which the only way out was a power cycle. I would normally try a pattern
in a simple freestanding Perl script before reporting a bug, but I don't fancy
getting screwed again.

Philip Hazel, PCRE2 developer

Perl Info

Flags:
    category=core
    severity=high

Site configuration information for perl 5.26.2:

Configured by builduser at Wed Apr 18 22:20:25 CEST 2018.

Summary of my perl5 (revision 5 version 26 subversion 2) configuration:
   
  Platform:
    osname=linux
    osvers=4.15.15-1-arch
    archname=x86_64-linux-thread-multi
    uname='linux flo-64 4.15.15-1-arch #1 smp preempt sat mar 31 23:59:25 utc 2018 x86_64 gnulinux '
    config_args='-des -Dusethreads -Duseshrplib -Doptimize=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -Dprefix=/usr -Dvendorprefix=/usr -Dprivlib=/usr/share/perl5/core_perl -Darchlib=/usr/lib/perl5/5.26/core_perl -Dsitelib=/usr/share/perl5/site_perl -Dsitearch=/usr/lib/perl5/5.26/site_perl -Dvendorlib=/usr/share/perl5/vendor_perl -Dvendorarch=/usr/lib/perl5/5.26/vendor_perl -Dscriptdir=/usr/bin/core_perl -Dsitescript=/usr/bin/site_perl -Dvendorscript=/usr/bin/vendor_perl -Dinc_version_list=none -Dman1ext=1perl -Dman3ext=3perl -Dcccdlflags='-fPIC' -Dlddlflags=-shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -Dldflags=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='7.3.1 20180312'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags ='-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.1/include-fixed /usr/lib /lib/../lib /usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.26.so
    so=so
    useshrplib=true
    libperl=libperl.so
    gnulibc_version='2.26'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.26/core_perl/CORE'
    cccdlflags='-fPIC'
    lddlflags='-shared -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -L/usr/local/lib -fstack-protector-strong'



@INC for perl 5.26.2:
    /usr/lib/perl5/5.26/site_perl
    /usr/share/perl5/site_perl
    /usr/lib/perl5/5.26/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib/perl5/5.26/core_perl
    /usr/share/perl5/core_perl


Environment for perl 5.26.2:
    HOME=/home/ph10
    LANG=en_GB.utf8
    LANGUAGE=en_GB.utf8
    LC_ALL=C
    LC_COLLATE=C
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/ph10/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/sbin:.:/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2018

From @Abigail

On Mon, Jun 25, 2018 at 09​:23​:54AM -0700, Philip Hazel (via RT) wrote​:

# New Ticket Created by Philip Hazel
# Please include the string​: [perl #133302]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=133302 >

This is a bug report for perl from ph10@​hermes.cam.ac.uk,
generated with the help of perlbug 1.40 running under perl 5.26.2.

-----------------------------------------------------------------
[Please describe your issue here]

While testing PCRE2 I was considering this crazy pattern sent by a user​:

/(?<=\K.)/g

It was being matched against the string "ab". I wanted to see what Perl made of
it, so I fed it to the Perl script I use for comparing Perl output to PCRE2
output. My machine (Arch Linux 4.14.35-1-lts x86_64) went into a tight loop
from which the only way out was a power cycle. I would normally try a pattern
in a simple freestanding Perl script before reporting a bug, but I don't fancy
getting screwed again.

Philip Hazel, PCRE2 developer

You didn't indicate in which context you were running the match --
for /g, this matters.

Using 5.26.2 on MacOS, I get​:

  $ perl -wE '"ab" =~ /(?<=\K.)/g and say "[$&]"'
  [a]
  $

  $ perl -wE 'say "[$&]" while "ab" =~ /(?<=\K.)/g'
  [a]
  [a]
  [a]
  [a]
  [a]
  [a]
  ^C
  $

  $ perl -wE '@​a = "ab" =~ /(?<=\K.)/g; say "[$_]" for @​a'
  # Time passes...
  ^C
  $

And while the latter two seem to be stuck in a loop, I could easily
kill the programs by sending it a SIGINT.

I agree though that getting stuck in a loop isn't the most useful
behaviour though.

Abigail

@p5pRT
Copy link
Author

p5pRT commented Jun 25, 2018

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jun 26, 2018

From ph10@hermes.cam.ac.uk

On Mon, 25 Jun 2018, Abigail via RT wrote​:

You didn't indicate in which context you were running the match --
for /g, this matters.

I have a shell script which includes a Perl script which mimics the
behaviour of the pcre2test program, reading patterns and subject texts
from a file and applying them. I use this to check PCRE2's compatibility
with Perl. So it's a bit contorted, and ends up with an "eval" to run
the match. This may be why my loop was unbreakable by SIGINT. The script
is available here, should you wish to look it it and/or try it out​:

https://vcs.pcre.org/pcre2/code/trunk/perltest.sh?revision=936&view=markup

The input file contained just two lines

/(?<=\K.)/g
ab

It's also possible my environment (though it's supposedly straighforward
Arch Linux) contributed to the stuck loop.

I agree though that getting stuck in a loop isn't the most useful
behaviour though.

Yes, it would be nice if it didn't do that!

Regards,
Philip

--
Philip Hazel

@khwilliamson
Copy link
Contributor

This has been solved by forbidding \K in a lookaround assertion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants