Bug#1016369: IO::Handle ->error does not work, always saying "fine"

Niko Tyni ntyni at debian.org
Sat Aug 6 19:04:17 BST 2022


Control: severity -1 normal

Hi, thanks Ian for the report and Damyan for looking into the issues.

On Sun, Jul 31, 2022 at 11:37:09AM +0300, Damyan Ivanov wrote:
> -=| Ian Jackson, 30.07.2022 13:42:05 +0100 |=-
> > Package: perl
> > Version: 5.34.0-4
> > Severity: grave
> > 
> > To reproduce
> > 
> >     perl -MIO::Handle -e 'open X, "<", "." or die $!; $_ = <X>; printf "%s %s %s\n", X->error(), $!;'
> >     perl -MIO::Handle -e 'open X, ">", "/dev/full" or die $!; print X 1; flush X; printf "%s %s %s\n", X->error(), $!; close X'
> > 
> > Expected output
> > 
> >     -1 Bad file descriptor
> >     -1 No space left on device
> > 
> > Actual output
> > 
> >     0 Bad file descriptor
> >     0 No space left on device


FWIW I get 

    0 Is a directory 
    1 No space left on device 

on sid (perl_5.34.0-5). I'm not sure why you'd expect -1. The documentation
for IO::Handle::error() only mentions it reporting a true value.

The first issue (reading a directory as a plain file) seems to be about
the error flag getting cleared when reading past EOF or something like
that. According to my meager debugger skills, the clearing happens around

  https://sources.debian.org/src/perl/5.34.0-5/pp_hot.c/#L3278

As Damyan notes, you can detect this by checking for EOF before reading,
although

   perl -MIO::Handle -e 'open X, "<", "." or die $!; $_ = <X> if !X->eof(); printf "%s %s\n", X->error(), $!;'
   1 Inappropriate ioctl for device 

is not quite what I'd expect either.

Anyway, the data loss argument seems misplaced given we've read all the
data there is when we are at EOF?

I can see there is probably a bug around here, but it would be good
to have an example test case that doesn't involve treating a directory
as a plain file (which can have very varying results between different
platforms) before taking this upstream. Particularly so if you want to
argue it's as serious as claimed here.

See also https://github.com/Perl/perl5/issues/12782 which has not
received attention in almost ten years.


The second issue (writing to /dev/full) is indeed fixed in sid / Perl
5.34.  It was https://github.com/Perl/perl5/issues/6799 and reportedly
only affects things like character devices (including /dev/full) and
sockets. I've verified that trying to write to a normal file on a full
filesystem does set the error() flag on stable / Perl 5.32.

I think that makes the issue less severe, and I'm not very inclined to
fix it in stable.  But in case we end up doing that anyway, these would
be the commits needed:

    https://github.com/Perl/perl5/commit/89341f87f9fc65c4d7133e497bb04586e86b8052

    https://github.com/Perl/perl5/commit/8a2562bec7cd9f8eff6812f340f99dddd028bb33

Downgrading the severity, but let me know what you think based on the above.
-- 
Niko




More information about the Perl-maintainers mailing list