Skip to content

IO::Handle::error() can lose read errors #20060

Closed
@ntyni

Description

@ntyni

As reported by Ian Jackson in https://bugs.debian.org/1016369 IO::Handle::error() can report 0 when there was an error on the filehandle.

A test case is

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

which returns "0 Is a directory" for me on Linux although all reads on the filehandle fail with EISDIR.

I've debugged this a bit and it looks like the error gets cleared in Perl_do_readline() around pp_hot.c:3295 or so with a PerlIO_clearerr() call. I think this is related to reading past EOF or something like that?

While trying to treat a directory as a regular file is something of a corner case (and the result is rather platform dependent), Ian argues that this is an indication of a more general problem where EIO and similar errors can go unnoticed if user code is relying on the IO::Handle::error() method to report them. Of course, creating simple test cases for such errors is difficult if not impossible.

I see #12782 is very similar but hasn't really received much attention. Is this something that should at least be documented as a caveat if it's not fixable?

-----------------------------------------------------------------
---
Flags:
    category=library
    severity=medium
    module=IO::Handle
---
Site configuration information for perl 5.37.3:

Configured by ntyni at Sat Aug  6 17:54:25 BST 2022.

Summary of my perl5 (revision 5 version 37 subversion 3) configuration:
  Commit id: 12d173c94b050c244dbb4e2162e29834a9ac3aff
  Platform:
    osname=linux
    osvers=5.17.0-1-amd64
    archname=x86_64-linux
    uname='linux carme 5.17.0-1-amd64 #1 smp preempt debian 5.17.3-1 (2022-04-18) x86_64 gnulinux '
    config_args='-des -Dusedevel'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='11.2.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.33.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.33'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'


---
@INC for perl 5.37.3:
    lib
    /usr/local/lib/perl5/site_perl/5.37.3/x86_64-linux
    /usr/local/lib/perl5/site_perl/5.37.3
    /usr/local/lib/perl5/5.37.3/x86_64-linux
    /usr/local/lib/perl5/5.37.3

---
Environment for perl 5.37.3:
    HOME=/home/ntyni
    LANG=C
    LANGUAGE (unset)
    LC_CTYPE=fi_FI.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/games
    PERL_BADLANG (unset)
    SHELL=/bin/zsh

Metadata

Metadata

Assignees

No one assigned

    Labels

    dist-IOissues in the dual-life blead-first IO distribution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions