mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-07 02:09:59 +00:00
perl: fix max depth checks in PP
This commit is contained in:
parent
a86c1624a7
commit
bab622de25
2 changed files with 9 additions and 8 deletions
|
|
@ -124,11 +124,11 @@ sub _unexpected {
|
|||
{
|
||||
no warnings 'recursion';
|
||||
|
||||
my $max_depth;
|
||||
our $_max_depth;
|
||||
|
||||
sub pack :method {
|
||||
Carp::croak('Usage: Data::MessagePack->pack($dat [,$max_depth])') if @_ < 2;
|
||||
$max_depth = defined $_[2] ? $_[2] : 512; # init
|
||||
$_max_depth = defined $_[2] ? $_[2] : 512; # init
|
||||
return _pack( $_[1] );
|
||||
}
|
||||
|
||||
|
|
@ -136,6 +136,12 @@ sub pack :method {
|
|||
sub _pack {
|
||||
my ( $value ) = @_;
|
||||
|
||||
local $_max_depth = $_max_depth - 1;
|
||||
|
||||
if ( $_max_depth < 0 ) {
|
||||
Carp::croak("perl structure exceeds maximum nesting level (max_depth set too low?)");
|
||||
}
|
||||
|
||||
return CORE::pack( 'C', 0xc0 ) if ( not defined $value );
|
||||
|
||||
if ( ref($value) eq 'ARRAY' ) {
|
||||
|
|
@ -146,9 +152,6 @@ sub _pack {
|
|||
: $num < 2 ** 32 - 1 ? CORE::pack( 'CN', 0xdd, $num )
|
||||
: _unexpected("number %d", $num)
|
||||
;
|
||||
if ( --$max_depth <= 0 ) {
|
||||
Carp::croak("perl structure exceeds maximum nesting level (max_depth set too low?)");
|
||||
}
|
||||
return join( '', $header, map { _pack( $_ ) } @$value );
|
||||
}
|
||||
|
||||
|
|
@ -160,9 +163,6 @@ sub _pack {
|
|||
: $num < 2 ** 32 - 1 ? CORE::pack( 'CN', 0xdf, $num )
|
||||
: _unexpected("number %d", $num)
|
||||
;
|
||||
if ( --$max_depth <= 0 ) {
|
||||
Carp::croak("perl structure exceeds maximum nesting level (max_depth set too low?)");
|
||||
}
|
||||
return join( '', $header, map { _pack( $_ ) } %$value );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ my @input = (
|
|||
[[],[]],
|
||||
[{"a" => 97},{"a" => 97}],
|
||||
[{"a" => 97},{"a" => 97},{"a" => 97}],
|
||||
[ map { +{ "foo $_" => "bar $_" } } 'aa' .. 'zz' ],
|
||||
);
|
||||
|
||||
plan tests => @input * 2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue