houseabsolute / Params-Validate

Validate method/function parameters
https://metacpan.org/release/Params-Validate/
Other
7 stars 14 forks source link

"validate" crashes on a closed IO::Scalar object #23

Open autarch opened 3 years ago

autarch commented 3 years ago

Migrated from rt.cpan.org #127811 (status was 'stalled')

Requestors:

From pawelkrol@cpan.org on 2018-11-26 17:59:36 :

Hi!

I would like to use Params::Validate's "validate" function to validate an IO::Scalar object. However when an IO::Scalar object is closed, "validate" will always crash regardless of whatever actual validation callbacks are defined.

Here is a minimal code that demonstrates the bug and the results of its execution:

$ cat test.pl

!/usr/bin/perl

use Data::Dumper; use IO::Scalar; use Params::Validate qw(:all);

sub test { print Dumper \@; validate(@, { arg => {} }); }

my $var = new IO::Scalar; $var->close; test({ arg => $var }); $ ./test.pl $VAR1 = [ { 'arg' => bless( *IO::Scalar::FH, 'IO::Scalar' ) } ]; Can't use an undefined value as a SCALAR reference at /usr/local/share/perl5/IO/Scalar.pm line 157. $ echo $? 255

I confirmed it to crash at least since version 1.23. I have got the latest version of IO::Scalar (2.111) installed as well.

I would very much appreciate if this problem could be addressed in the next version of this excellent package.

Many thanks!

Best regards, Pawel Krol.

autarch commented 3 years ago

From drolsky@cpan.org (@autarch) on 2018-11-27 16:52:23 :

Hi Pawel,

I'm not really using this module any more in any new code. Instead I'm using https://metacpan.org/release/Params-ValidationCompiler which ends up being quite a bit faster. You might want to take a look at it.

Since I'm not really using it I'm not sure if I'll get a chance to investigate this bug myself. However, a PR against https://github.com/houseabsolute/Params-Validate would be welcome.

autarch commented 3 years ago

From pawelkrol@cpan.org on 2018-11-29 19:47:29 :

Hi!

Thank you very much for your response. I was thinking how it could be fixed, and perhaps it makes more sense to address the issue at its root cause, i.e. in the "IO::Scalar" module, since this is where it actually blows up. I have opened a respective ticket to "IO-stringy" package:

https://rt.cpan.org/Ticket/Display.html?id=127843

Since it is a low-level module, changing it would be more invasive. Thus I am not entirely sure if fixing a bug there is feasible. Let's wait and see what the maintainers say. If the change proves to be unacceptable, we could always "eval" + inspect "$@" to capture the error message from an underlying function, although I am not entirely sure how to account for a variety of possible errors thrown by different modules. If you have an idea what would be the most appropriate way to handle it, I would be happy to open a PR.

Params::ValidationCompiler may seem like a reasonable alternative. Thanks for the suggestion, I was not aware of it. I will sure give it a try!

Many thanks!

Best regards, Pawel Krol.

autarch commented 3 years ago

From drolsky@cpan.org (@autarch) on 2020-02-09 17:20:01 :

Marking stalled since this needs to be fixed in IO::Scalar.