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

Large number of string evals makes interpreter emit syntax error #11112

Closed
p5pRT opened this issue Feb 4, 2011 · 8 comments
Closed

Large number of string evals makes interpreter emit syntax error #11112

p5pRT opened this issue Feb 4, 2011 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Feb 4, 2011

Migrated from rt.perl.org#83364 (status was 'resolved')

Searchable as RT83364$

@p5pRT
Copy link
Author

p5pRT commented Feb 4, 2011

From andreas@faafeng.com

Created by aff@affdesktop.domain.local

The perl interpreter will eventually emit an error as if the running
code contains a syntax error after having executed a very large number
of eval'ed statements. The problem is reproducible on multiple version
of perl and on multiple operating systems, including

  perl v5.8.8, x86_64-linux-thread-multi, Linux 2.6.18
  perl v5.10.0, x86_64-linux, Linux 2.6.18
  perl v5.10.1, MSWin32-x86-multi-thread, Windows XP
  perl v5.13.9-206-g3dcd47c, x86_64-linux

The problem may be related to PL_evalseq overflow but this has not been
confirmed.

Note that it requires significant CPU time to reproduce this bug
(Typically 2 to 8 wall clock hours).

Typical error messages are :

  Variable "$self" will not stay shared at (eval 999973501) line 15.
  Variable "$self" will not stay shared at (eval 999975201) line 15.
  Global symbol "$i" requires explicit package name at (eval
  999977609) line 42.
  Global symbol "$abc" requires explicit package name at (eval
  1073741766) line 1.

Example code​:

$ cat eval.pl
use strict;
use warnings;
my $c;

print 'start​: ' . scalar localtime();

for ($c = 0; !$@​; $c++) {
  eval 'my $abc = 1; $abc++; ';
}

print $c . ' ' . $@​;
print 'end : ' . scalar localtime();

__END__

$ perl eval.pl
start​: Wed Feb 2 12​:17​:52 2011
499999923 Global symbol "$abc" requires explicit package name at (eval
499999923) line 1.
end : Wed Feb 2 13​:49​:17 2011
$ perl -v

This is perl, v5.8.8 built for x86_64-linux-thread-multi

-------------------------------------------------------------------------------

$ perl eval.pl
start​: Wed Feb 2 13​:05​:24 2011
499999942 Global symbol "$abc" requires explicit package name at (eval
499999942) line 1.
end : Wed Feb 2 14​:36​:33 2011
$ perl -v

This is perl, v5.8.8 built for x86_64-linux-thread-multi

-------------------------------------------------------------------------------

$ ./perl -Ilib -l eval.pl
start​: Wed Feb 2 12​:18​:17 2011
1073741766 Global symbol "$abc" requires explicit package name at (eval
1073741766) line 1.
end : Wed Feb 2 15​:50​:44 2011

$ ./perl -v

This is perl 5, version 13, subversion 9 (v5.13.9-206-g3dcd47c) built
for x86_64-linux

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl 5.10.0:

Configured by aff at Wed Mar  4 14:29:33 CET 2009.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.18-92.1.22.el5, archname=x86_64-linux
    uname='linux affdesktop 2.6.18-92.1.22.el5 #1 smp tue dec 16
11:57:43 est 2008 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Dprefix=/opt/perl -Dnoextensions=ODBM_File
-Accflags=-fPIC -Dinstallprefix=/opt/perl -Dcc=gcc'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-fPIC -fno-strict-aliasing -pipe
-I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
-I/usr/include/gdbm',
    optimize='-O2',
    cppflags='-fPIC -fno-strict-aliasing -pipe -I/usr/local/include
-I/usr/include/gdbm'
    ccversion='', gccversion='4.1.2 20071124 (Red Hat 4.1.2-42)',
gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64 /usr/local/lib64
    libs=-lnsl -lgdbm -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.5.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib'

Locally applied patches:



@INC for perl 5.10.0:
    /opt/perl/lib/5.10.0/x86_64-linux
    /opt/perl/lib/5.10.0
    /opt/perl/lib/site_perl/5.10.0/x86_64-linux
    /opt/perl/lib/site_perl/5.10.0
    .


Environment for perl 5.10.0:
    HOME=/home/aff
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_PAPER=POSIX
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/aff/bin

    PERL_BADLANG (unset)
    SHELL=/bin/bash

-- 

@p5pRT
Copy link
Author

p5pRT commented Feb 4, 2011

From @Corion

Hello all,

as another data point, I can add Strawberry Perl 5.12 (MinGW) on Windows
XP, which reproducibly crashes after 1_073_xxx_xxx evals.

In an attempt to more quickly reproduce the error (as the current
program runs about 5 or 6 hours on one core), I skipped evaling the
lexical variables for most of the time, but this did not produce the
error [1].

There is a bit more discussion and different programs that pump up the
eval-counter at

http​://perlmonks.org/?node_id=884800

but nothing that is quick enough for conveniently adding this to the
test suite.

-max

[1] Code that does NOT trigger the error​:

#!/opt/perl/bin/perl

use strict;
use warnings;

my $count = 0;
my $continue = 5;
$|=1;

while (1) {
  $count++;
  if ($count < 1073700000) {
  eval '1 == 1'
  } else {
  if (! eval 'my $abc = 1; $abc++; 1') {
  print "\n$count​: $@​\n";

  exit if ! $continue--;
  };
  };
  if (0 == $count % 100_000) {
  print $count . "\r";
  print q(Expect crash) if $count > 1073700000;
  }
}

@p5pRT
Copy link
Author

p5pRT commented Feb 4, 2011

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

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2011

From vadim.konovalov@alcatel-lucent.com

$ ./perl -Ilib -l eval.pl
start​: Wed Feb 2 12​:18​:17 2011
1073741766 Global symbol "$abc" requires explicit package
name at (eval
1073741766) line 1.
end : Wed Feb 2 15​:50​:44 2011

wow...

I confirm (windows, Activestate perl 5.12.1), and this indeed takes 7 hours to run and 1_073_xxx_xxx iterations.

D​:\TESTS\perl>perl -w starnge-eval.pl
start​: Sat Feb 5 09​:36​:27 20111073741769 Global symbol "$abc" requires explicit package name at (eval 1073741769) line 1.
end : Sat Feb 5 16​:39​:38 2011

Regards,
Vadim

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2011

From @iabyn

On Sat, Feb 05, 2011 at 05​:39​:24PM +0100, Konovalov, Vadim (Vadim)** CTR ** wrote​:

$ ./perl -Ilib -l eval.pl
start​: Wed Feb 2 12​:18​:17 2011
1073741766 Global symbol "$abc" requires explicit package
name at (eval
1073741766) line 1.
end : Wed Feb 2 15​:50​:44 2011

wow...

I confirm (windows, Activestate perl 5.12.1), and this indeed takes 7 hours to run and 1_073_xxx_xxx iterations.

D​:\TESTS\perl>perl -w starnge-eval.pl
start​: Sat Feb 5 09​:36​:27 20111073741769 Global symbol "$abc" requires explicit package name at (eval 1073741769) line 1.
end : Sat Feb 5 16​:39​:38 2011

I've found the problem and am currently working up a fix.

--
Dave's first rule of Opera​:
If something needs saying, say it​: don't warble it.

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2011

From @iabyn

On Sun, Feb 06, 2011 at 02​:35​:30PM +0000, Dave Mitchell wrote​:

On Sat, Feb 05, 2011 at 05​:39​:24PM +0100, Konovalov, Vadim (Vadim)** CTR ** wrote​:

$ ./perl -Ilib -l eval.pl
start​: Wed Feb 2 12​:18​:17 2011
1073741766 Global symbol "$abc" requires explicit package
name at (eval
1073741766) line 1.
end : Wed Feb 2 15​:50​:44 2011

wow...

I confirm (windows, Activestate perl 5.12.1), and this indeed takes 7 hours to run and 1_073_xxx_xxx iterations.

D​:\TESTS\perl>perl -w starnge-eval.pl
start​: Sat Feb 5 09​:36​:27 20111073741769 Global symbol "$abc" requires explicit package name at (eval 1073741769) line 1.
end : Sat Feb 5 16​:39​:38 2011

I've found the problem and am currently working up a fix.

Now fixed with commits

  d1bfb64
  2df5bdd
  0d311cd
  6012dc8

The issue involved the wrapping of the PL_cop_seqmax variable (a U32),
which governs the scope visibility of lexical variables. The wrapping
issue was compounded by the fact that PAD_MAX was defined as I32_MAX
rather than U32_MAX. The first commit above (d1bfb64) fixes that,
and makes 99% of the problem go away. Its a good candidate for maint
a cherry-pick.

The rest of the commits solve the general problem of wrapping by cleaning
up the code associated with pad cop sequences, and making the range check
code much more fussy.

--
The warp engines start playing up a bit, but seem to sort themselves out
after a while without any intervention from boy genius Wesley Crusher.
  -- Things That Never Happen in "Star Trek" #17

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2011

@iabyn - Status changed from 'open' to 'resolved'

@p5pRT p5pRT closed this as completed Feb 6, 2011
@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2011

From @csjewell

I thought that number looked familiar - that's just under 1Gi (2^30 =
1073714824 is 55 away.)

I wonder if that helps any...

On Sat, 05 Feb 2011 17​:39 +0100, "Konovalov, Vadim (Vadim)** CTR **"
<vadim.konovalov@​alcatel-lucent.com> wrote​:

$ ./perl -Ilib -l eval.pl
start​: Wed Feb 2 12​:18​:17 2011
1073741766 Global symbol "$abc" requires explicit package
name at (eval
1073741766) line 1.
end : Wed Feb 2 15​:50​:44 2011

wow...

I confirm (windows, Activestate perl 5.12.1), and this indeed takes 7
hours to run and 1_073_xxx_xxx iterations.

D​:\TESTS\perl>perl -w starnge-eval.pl
start​: Sat Feb 5 09​:36​:27 20111073741769 Global symbol "$abc" requires
explicit package name at (eval 1073741769) line 1.
end : Sat Feb 5 16​:39​:38 2011

Regards,
Vadim
--
Curtis Jewell
csjewell@​cpan.org http​://csjewell.dreamwidth.org/
perl@​csjewell.fastmail.us http​://csjewell.comyr.org/perl/

"Your random numbers are not that random" -- perl-5.10.1.tar.gz/util.c

Strawberry Perl for Windows betas​: http​://strawberryperl.com/beta/

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

1 participant