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

2024-01-14 Thread gregor herrmann
Control: forwarded -1 https://rt.cpan.org/Ticket/Display.html?id=52317

On Sun, 14 Jan 2024 14:04:49 +0100, Christoph Biedl wrote:

> 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.

There's an CPAN RT ticket at
https://rt.cpan.org/Ticket/Display.html?id=52317

An attempt for a pull request was withdrawn as non-functional, and …
 
> 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.

… the last step seems to be a suggestion to document the issue:
https://github.com/rjbs/IPC-Run3/pull/10


Cheers,
gregor

-- 
 .''`.  https://info.comodo.priv.at -- Debian Developer https://www.debian.org
 : :' : OpenPGP fingerprint D1E1 316E 93A7 60A8 104D  85FA BB3A 6801 8649 AA06
 `. `'  Member VIBE!AT & SPI Inc. -- Supporter Free Software Foundation Europe
   `-   


signature.asc
Description: Digital Signature


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

2024-01-14 Thread Christoph Biedl
Package: libipc-run3-perl
Version: 0.048-3
Severity: important
Tags: upstream
X-Debbugs-Cc: debian.a...@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 = )) {
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

7
8
9
10
-

Got:
-
0
1
2
3
4
5
6

-

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 = )) {
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



signature.asc
Description: PGP signature