| Store | Cart

[perl #132974] [PATCH] ExtUtils::Constant fix "panic: failed to extend arg stack"

From: bulk88 (via RT) <perl...@perl.org>
Tue, 13 Mar 2018 21:05:38 -0700
# New Ticket Created by  bulk88 
# Please include the string:  [perl #132974]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=132974 >


This is a bug report for perl from bul...@hotmail.com,
generated with the help of perlbug 1.41 running under perl 5.27.9.


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

See attached patch. This is a 5.28 blocker IMO. I can't use the perl 
debugger ("-d") or Komodo debugger, on a DEBUGGING build, without this 
patch. I can reproduce the panic every time, but there are 2 conditions 
for me. I HAVE to use -d and the perl debugger. I am not sure why. I'm 
not sure how to test the stack extend logic deterministically from PP, 
or how to make a certain number of frames or largeness of stack frames 
to trigger the panic without using -d.

And it must be a DEBUGGING build (panic check wont be in the binary 
otherwise). IDK if on other systems it can be reproduced.

Since ExtUtils::Constant isn't maintained on CPAN 
https://www.nntp.perl.org/group/perl.perl5.porters/2017/01/msg242516.html 
  and its being patched/revision controlled in core and has no outside 
repo 
https://perl5.git.perl.org/perl.git/history/HEAD:/cpan/ExtUtils-Constant/lib/ExtUtils 
  and this breaks using perl5db.pl with any script that ever winds up 
calling AUTOLOAD/EU::C's XS code since 5.27.2 this patch is against 
core. Perls before 5.27.2 arent affected but the stack-overflow-by-1 is 
still there, but I think no actual memory corruption can happen, since 
pp_entersub always pops the CV off the stack, and XSUB constant() croaks 
if it has zero args (it needs 1 arg), accidentally guaranteeing space 
for 2 stack slots on the list context return of XSUB constant().

Example of me executing the panic.
-------------------------------
C:\p527\srcnew>perl -V
Summary of my perl5 (revision 5 version 27 subversion 10) configuration:

   Platform:
     osname=MSWin32
     osvers=5.2.3790
     archname=MSWin32-x64-multi-thread
     uname=''
     config_args='undef'
     hint=recommended
     useposix=true
     d_sigaction=undef
     useithreads=define
     usemultiplicity=define
     use64bitint=define
     use64bitall=undef
     uselongdouble=undef
     usemymalloc=n
     default_inc_excludes_dot=define
     bincompat5005=undef
   Compiler:
     cc='cl'
     ccflags ='-nologo -GF -W3 -Od -MD -Zi -DDEBUGGING -fp:precise 
-DWIN32 -D_CON
SOLE -DNO_STRICT -DWIN64 -DCONSERVATIVE -D_CRT_SECURE_NO_DEPRECATE 
-D_CRT_NONSTD
C_NO_DEPRECATE  -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT 
-DPERL_IMPLICIT_
SYS -DWIN32_NO_REGISTRY'
     optimize='-Od -MD -Zi -DDEBUGGING -fp:precise'
     cppflags='-DWIN32'
     ccversion='15.00.30729.01'
     gccversion=''
     gccosandvers=''
     intsize=4
     longsize=4
     ptrsize=8
     doublesize=8
     byteorder=12345678
     doublekind=3
     d_longlong=undef
     longlongsize=8
     d_longdbl=define
     longdblsize=8
     longdblkind=0
     ivtype='__int64'
     ivsize=8
     nvtype='double'
     nvsize=8
     Off_t='__int64'
     lseeksize=8
     alignbytes=8
     prototype=define
   Linker and Libraries:
     ld='link'
     ldflags ='-nologo -nodefaultlib -debug 
-libpath:"c:\perl\lib\CO
RE"             -machine:AMD64'
     libpth="c:\Program Files (x86)\Microsoft Visual Studio 
9.0\VC\lib\amd64"
     libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib 
comdlg32.li
b advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib 
ws2_32.l
ib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib comctl32.lib 
msvcrt.lib

     perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib 
winspool.lib comdlg3
2.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib 
uuid.lib ws2_
32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib 
comctl32.lib msvcrt
.lib
     libc=msvcrt.lib
     so=dll
     useshrplib=true
     libperl=perl527.lib
     gnulibc_version=''
   Dynamic Linking:
     dlsrc=dl_win32.xs
     dlext=dll
     d_dlsymun=undef
     ccdlflags=' '
     cccdlflags=' '
     lddlflags='-dll -nologo -nodefaultlib -debug 
-libpath:"c:\per
l\lib\CORE"             -machine:AMD64'


Characteristics of this binary (from libperl):
   Compile-time options:
     DEBUGGING
     HAS_TIMES
     HAVE_INTERP_INTERN
     MULTIPLICITY
     PERLIO_LAYERS
     PERL_COPY_ON_WRITE
     PERL_DISABLE_PMC
     PERL_DONT_CREATE_GVSV
     PERL_IMPLICIT_CONTEXT
     PERL_IMPLICIT_SYS
     PERL_OP_PARENT
     PERL_PRESERVE_IVUV
     PERL_TRACK_MEMPOOL
     USE_64_BIT_INT
     USE_ITHREADS
     USE_LARGE_FILES
     USE_LOCALE
     USE_LOCALE_COLLATE
     USE_LOCALE_CTYPE
     USE_LOCALE_NUMERIC
     USE_LOCALE_TIME
     USE_NO_REGISTRY
     USE_PERLIO
     USE_PERL_ATOF
   Built under MSWin32
   Compiled at Mar 13 2018 17:34:03
   @INC:
     C:/p527/srcnew/lib

C:\p527\srcnew>perl -d -e"use 
Compress::Raw::Bzip2;Compress::Raw::Bzip2::constan
t('BZ_OK');"

Loading DB routines from perl5db.pl version 1.53
Editor support available.

Enter h or 'h h' for help, or 'perldoc perldebug' for more help.

main::(-e:1):   use 
Compress::Raw::Bzip2;Compress::Raw::Bzip2::constant('BZ_OK')
;
   DB<1> c
panic: XSUB Compress::Raw::Bzip2::constant (Bzip2.c) failed to extend 
arg stack:
  base=1b13010, sp=1b13020, hwm=1b13018
  at -e line 1.
Debugged program terminated.  Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
   DB<1> q

C:\p527\srcnew>
-------------------------------

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
          category=core
          severity=low
---
Site configuration information for perl 5.27.9:

Configured by Administrator at Tue Jan 30 20:34:30 2018.

Summary of my perl5 (revision 5 version 27 subversion 9) configuration:

        Platform:
          osname=MSWin32
          osvers=5.2.3790
          archname=MSWin32-x86-multi-thread
          uname=''
          config_args='undef'
          hint=recommended
          useposix=true
          d_sigaction=undef
          useithreads=define
          usemultiplicity=define
          use64bitint=undef
          use64bitall=undef
          uselongdouble=undef
          usemymalloc=n
          default_inc_excludes_dot=define
          bincompat5005=undef
        Compiler:
          cc='cl'
          ccflags ='-nologo -GF -W3 -O1 -MD -Zi -DNDEBUG -GL -DWIN32
-D_CONSOLE -DNO_STRICT -D_CRT_SECURE_NO_DEPRECATE
-D_CRT_NONSTDC_NO_DEPRECATE  -DPERL_TEXTMODE_SCRIPTS
-DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DWIN32_NO_REGISTRY'
          optimize='-O1 -MD -Zi -DNDEBUG -GL'
          cppflags='-DWIN32'
          ccversion='15.00.30729.01'
          gccversion=''
          gccosandvers=''
          intsize=4
          longsize=4
          ptrsize=4
          doublesize=8
          byteorder=1234
          doublekind=3
          d_longlong=undef
          longlongsize=8
          d_longdbl=define
          longdblsize=8
          longdblkind=0
          ivtype='long'
          ivsize=4
          nvtype='double'
          nvsize=8
          Off_t='__int64'
          lseeksize=8
          alignbytes=8
          prototype=define
        Linker and Libraries:
          ld='link'
          ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -ltcg
-libpath:"c:\perl\lib\CORE"        -machine:x86'
          libpth="C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib"
          libs=oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
          perllibs=oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib ws2_32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib comctl32.lib msvcrt.lib
          libc=msvcrt.lib
          so=dll
          useshrplib=true
          libperl=perl527.lib
          gnulibc_version=''
        Dynamic Linking:
          dlsrc=dl_win32.xs
          dlext=dll
          d_dlsymun=undef
          ccdlflags=' '
          cccdlflags=' '
          lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf -ltcg
          -libpath:"c:\perl\lib\CORE"        -machine:x86'


---
@INC for perl 5.27.9:
          lib
          C:/p527/srcnew/lib

---
Environment for perl 5.27.9:
          CYGWIN=tty
          HOME (unset)
          LANG (unset)
          LANGUAGE (unset)
          LD_LIBRARY_PATH=/usr/lib/x86:/usr/X11R6/lib
          LOGDIR (unset)
          PATH=C:\WINDOWS\system32;C:\Program Files (x86)\Microsoft Visual
Studio 9.0\VC\BIN;C:\Program Files\Microsoft
SDKs\Windows\v6.0A\bin;C:\Perl\bin;C:\WINDOWS;C:\Program Files
(x86)\Microsoft Visual Studio 9.0\Common7\IDE;C:\Program Files
(x86)\Git\bin;C:\sp3220\c\bin;
          PERL_BADLANG (unset)
          SHELL (unset)









>From 63b02f14c1e01bf3904d0bf2d6b5061c92ae9822 Mon Sep 17 00:00:00 2001
From: Daniel Dragan <bul...@hotmail.com>
Date: Tue, 13 Mar 2018 23:38:23 -0400
Subject: [PATCH] ExtUtils::Constant fix "panic: failed to extend arg stack"

"$XS_Constant{$type}" is almost always a 2nd PUSH on stack, but EU::C
only extended by 1, not 2. This mistake didn't become visible until
the panic assert was added 5.27.2

panic: XSUB Compress::Raw::Bzip2::constant (Bzip2.c) failed to extend arg
stack: base=1b13010, sp=1b13020, hwm=1b13018

Numbers in message are from my 64bit perl, so 0x1b13020-0x1b13018=0x8
which is one 64 bit pointer stack slot, which is exactly the mistake that
this patch fixes in EU::C. See RT ticket associated with this commit for
details.
---
 cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm b/cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm
index 3199ebf..70c7fbc 100644
--- a/cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm
+++ b/cpan/ExtUtils-Constant/lib/ExtUtils/Constant.pm
@@ -1,6 +1,6 @@
 package ExtUtils::Constant;
 use vars qw (@ISA $VERSION @EXPORT_OK %EXPORT_TAGS);
-$VERSION = '0.24';
+$VERSION = '0.24_02';
 
 =head1 NAME
 
@@ -272,7 +272,7 @@ EOT
     $xs .= "        case PERL_constant_IS$type:\n";
     if (length $XS_Constant{$type}) {
       $xs .= << "EOT";
-          EXTEND(SP, 1);
+          EXTEND(SP, 2);
           PUSHs(&PL_sv_undef);
           $XS_Constant{$type};
 EOT
-- 
1.8.0.msysgit.0


Recent Messages in this Thread
bulk88 (via RT) Mar 14, 2018 04:05 am
James E Keenan via RT Mar 14, 2018 11:57 am
bulk88 via RT Mar 28, 2018 12:31 am
bulk88 via RT Mar 14, 2018 02:06 pm
Nicholas Clark Apr 18, 2018 06:20 am
Messages in this thread