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

Crashing when attributes number exceeds 23 #64

Closed
serhiybutz opened this issue Oct 13, 2016 · 5 comments
Closed

Crashing when attributes number exceeds 23 #64

serhiybutz opened this issue Oct 13, 2016 · 5 comments

Comments

@serhiybutz
Copy link

serhiybutz commented Oct 13, 2016

Under Ubuntu 16.04, Perl 5.22.1 (5.24.0 too) following scripts combination crashes:

File: Bar.pm

package Bar;
use Mouse;
has attr00  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr01  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr02  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr03  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr04  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr05  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr06  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr07  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr08  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr09  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr10  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr11  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr12  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr13  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr14  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr15  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr16  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr17  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr18  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr19  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr20  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr21  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr22  => (
    is       => 'ro',
    isa      => 'Str',
);
has attr23  => (
    is       => 'ro',
    isa      => 'Str',
);
1;

File: Foo.pm

package Foo;
use Mouse;
extends 'Bar';
has '+attr00'  => (
    isa => 'Str',
);
1;

File: Holder.pm

package Holder;
use Foo;
1;

File: run.pl

#!/usr/local/bin/perl -w
use warnings;
use Holder;

When script run.pl is run it crashes with following error message (sometimes it goes with backtrace):

Could not find an attribute by the name of 'attr00' to inherit from in Foo at /usr/local/lib/perl5/site_perl/5.24.0/x86_64-linux/Mouse/Meta/Class.pm line 225.
    Mouse::Meta::Class::add_attribute(Mouse::Meta::Class=HASH(0x16a2d20), "+attr00", "isa", "Str") called at /usr/local/lib/perl5/site_perl/5.24.0/x86_64-linux/Mouse.pm line 52
    Mouse::has("+attr00", "isa", "Str") called at Foo.pm line 4
    require Foo.pm called at Holder.pm line 2
    Holder::BEGIN() called at Foo.pm line 0
    eval {...} called at Foo.pm line 0
    require Holder.pm called at ./run.pl line 3
    main::BEGIN() called at Foo.pm line 0
    eval {...} called at Foo.pm line 0
Compilation failed in require at Holder.pm line 2.
BEGIN failed--compilation aborted at Holder.pm line 2.
Compilation failed in require at ./run.pl line 3.
BEGIN failed--compilation aborted at ./run.pl line 3.

Crashing stops if:

  1. 'use warnings' in run.pl is removed
  2. number of attributes in Bar.pm is less than 24
  3. run in debug-mode (like perl -d run.pl)

Also here's a fragment of valgrind output that I believe is relevant to the issue:

==22649== Invalid write of size 8
==22649==    at 0x6AA1CC0: XS_Mouse__Meta__Class_get_all_attributes (in /usr/local/lib/perl5/site_perl/5.24.0/x86_64-linux/auto/Mouse/Mouse.so)
==22649==    by 0x4B5887: Perl_pp_entersub (in /usr/local/bin/perl)
@serhiybutz serhiybutz changed the title Crashing when attributes number overrides 23 Crashing when attributes number exceeds 23 Oct 13, 2016
@sezal
Copy link
Contributor

sezal commented Dec 20, 2016

Is there any update on this issue? Because of this issue we have to keep our production servers running on ubuntu trusty :(

@syohex
Copy link
Collaborator

syohex commented Dec 21, 2016

Sorry belated response. I can reproduce this issue.

I suppose stack pointer is strange if there are more than 22 attributes and then Mouse::Meta::Class::get_all_attributes method returns nothing(It should returns 23 attribute instances). However I cannot understand how to fix this issue.

(Why does it work if its method is called two times ?)

diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm
index 4c1c5f3..4b94db9 100644
--- a/lib/Mouse/Meta/Class.pm
+++ b/lib/Mouse/Meta/Class.pm
@@ -193,6 +193,7 @@ sub find_attribute_by_name {
     my($self, $name) = @_;
     defined($name)
         or $self->throw_error('You must define an attribute name to find');
+    $self->get_all_attributes;
     foreach my $attr($self->get_all_attributes) {
         return $attr if $attr->name eq $name;
     }

asolovey added a commit to TrackingSoft/p5-Mouse that referenced this issue Dec 22, 2016
Using mouse metaclass attribute cache inside add_attribute may
cause strange problems such as missing attributes or memory
corruption.
@sezal
Copy link
Contributor

sezal commented Dec 27, 2016

we have submitted #67 to fix this issue.

@sezal
Copy link
Contributor

sezal commented Jan 6, 2017

update: patch was tested for more than a week on production and everything works smooth now.

syohex added a commit that referenced this issue Jan 14, 2017
Fix attribute override problem with recent perl (issue #64)
@syohex syohex closed this as completed Jan 14, 2017
syohex added a commit that referenced this issue Jan 14, 2017
Changelog diff is:

diff --git a/Changes b/Changes
index c50ca85..6565eeb 100644
--- a/Changes
+++ b/Changes
@@ -2,6 +2,11 @@ Revision history for Mouse

 {{$NEXT}}

+v2.4.7 2017-01-14T13:46:04Z
+    - Workaround for issue #64(#67)
+      In some case stack is corrupted at more than 23 attributes.
+      This change may makes a bit slow in that case.
+
 v2.4.6 2017-01-06T06:51:15Z
     - Fix test for older Perls (#68)
     - Define macros for older Visual Studio compiler(#66)
@syohex
Copy link
Collaborator

syohex commented Jan 14, 2017

Release Mouse v2.4.7 which applies #67 workaround.

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

No branches or pull requests

3 participants