Subject: | arity check fault breaks static method resolution |
Date: | Mon, 3 Mar 2014 11:13:23 +0000 |
To: | bug-Sereal-Encoder [...] rt.cpan.org |
From: | Zefram <zefram [...] fysh.org> |
In attempting to eke out a bit of extra performance by statically
resolving a critical method call, I found this breakage:
$ perl -MSereal::Encoder -lwe '$s=Sereal::Encoder->new; print length($s->encode({})); print length($s->can("encode")->($s, {}));'
9
Found type 13 CODE(0x1e9c060), but it is not representable by the Sereal encoding format at -e line 1.
This call with the separately-resolved method ought to be entirely
equivalent to calling the method normally. It's very strange that
it's not. Turns out that Sereal::Encoder::encode screws up an arity
check and can look beyond its arguments on the stack. Whether the bug
shows up therefore depends on accidents of the surrounding expression
that determine what the invalid stack slot actually contains. Attached
patch fixes.
-zefram
Message body is not shown because sender requested not to inline it.