Bug#1060798: IPC::Run3::run3 eats the calling process' stdin

Christoph Biedl debian.axhn at manchmal.in-ulm.de
Sun Jan 14 13:04:49 GMT 2024


Package: libipc-run3-perl
Version: 0.048-3
Severity: important
Tags: upstream
X-Debbugs-Cc: debian.axhn at manchmal.in-ulm.de

Greetings,

Summary: When a Perl application uses IPC::Run3::run3, any unread data
on stdin is lost.

The problem has been around for a long time, I can confirm it's already
there in Debian 8 ("jessie"). My gut feeling tells me I had already 
reported that, but I cannot find any traces of that (upstream page is
not barrier-free so I cannot check there). Also, his caused quite some
data loss in one of my programs, so possibly the severity
should be even higher.

In a nutshell, if a Perl program reads from stdin, and then decides to
peruse IPC::Run3::run3, anything that is still in the input buffer is
silently discarded. It's seems it does not appears on called program's
stdin, it's just gone. Data that arrives later will be processed as usual.

How to repeat:

Use this program1, it just generates a few text lines:
---------------------------------------------------------------------
#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

my $s = join ("\n", 0..10);
print "$s\n";
---------------------------------------------------------------------

This is program2, it reads from STDIN, prints each line, and calls
"date" if the input is "6":
---------------------------------------------------------------------
#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

use IPC::Run3;

while (defined (my $line = <STDIN>)) {
    chomp ($line);
    print "$line\n";
    if ($line eq '6') {
        my $out = '';
        run3 (
            [ 'date' ],
            \undef,
            \$out,
            \$out,
        );
        print $out;
    }
}
---------------------------------------------------------------------

Then run:

    ./program1 | program2

Expected:
---------------------------------------------------------------------
0
1
2
3
4
5
6
<current date and time>
7
8
9
10
---------------------------------------------------------------------

Got:
---------------------------------------------------------------------
0
1
2
3
4
5
6
<current date and time>
---------------------------------------------------------------------

FWIW, IPC::Run::run works as expected, try
---------------------------------------------------------------------
#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

use IPC::Run;

while (defined (my $line = <STDIN>)) {
    chomp ($line);
    print "$line\n";
    if ($line eq '6') {
        my $out = '';
        IPC::Run::run (
            [ 'date' ],
            \undef,
            \$out,
            \$out,
        );
        print $out;
    }
}
---------------------------------------------------------------------

Honestly, I haven't tried to fix this - in my experience subprocesses
and pipes are areas where it's fairly easy to do things wrong. Which is
why I prefer to delegate that task to some library.

So if all else fails, please place a big fat warning into IPC::Run3's
manpage to avoid other people get hit by this, too.

    Christoph


-- System Information:
Debian Release: trixie/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.69 (SMP w/8 CPU threads)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages libipc-run3-perl depends on:
ii  perl  5.38.2-3

libipc-run3-perl recommends no packages.

libipc-run3-perl suggests no packages.

-- no debconf information

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-perl-maintainers/attachments/20240114/2be94739/attachment.sig>


More information about the pkg-perl-maintainers mailing list