Bug#889734: libjson-xs-perl: JSON::XS is broken in multithreaded programs

2018-02-10 Thread gregor herrmann
Control: tag -1 + upstream wontfix

On Tue, 06 Feb 2018 15:34:49 +0100, Łukasz Stelmach wrote:

> The following program exposes a bug in JSON::XS module which makes the
> program die.
> 
> --8<---cut here---start->8---
> #!/usr/bin/perl
> 
> use JSON;
> use threads;
> 
> my $thnum = int($ARGV[0]);
> 
> $href{"foo"} = "bar";
> 
> for (1..$thnum) {
> threads->create(sub { print "quick thread\n" });
> }
> foreach (threads->list()) { $_->join(); }
> 
> print to_json(\%href);
> --8<---cut here---end--->8---
> 
> For any number of threads other than 0 (e.g. "perl prog.pl 1") the
> program dies printing[1]

This is a know and documented limitation:

(I-)THREADS
This module is *not* guaranteed to be ithread (or MULTIPLICITY-) safe
and there are no plans to change this. Note that perl's builtin
so-called theeads/ithreads are officially deprecated and should not be
used.

Given this statement by upstream, it doesn't look like they're going
to change this behaviour …


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
   `-   NP: Dire Straits: Ride Across The River


signature.asc
Description: Digital Signature


Bug#889734: libjson-xs-perl: JSON::XS is broken in multithreaded programs

2018-02-06 Thread Łukasz Stelmach
Package: libjson-xs-perl
Version: 3.030-1
Severity: important

Dear Maintainer,

The following program exposes a bug in JSON::XS module which makes the
program die.

--8<---cut here---start->8---
#!/usr/bin/perl

use JSON;
use threads;

my $thnum = int($ARGV[0]);

$href{"foo"} = "bar";

for (1..$thnum) {
threads->create(sub { print "quick thread\n" });
}
foreach (threads->list()) { $_->join(); }

print to_json(\%href);
--8<---cut here---end--->8---

For any number of threads other than 0 (e.g. "perl prog.pl 1") the
program dies printing[1]

hash- or arrayref expected (not a simple scalar, use allow_nonref to allow 
this) at /usr/share/perl5/JSON.pm line 156.

The logic that triggers it is in json_nonref()[2]. The condition that
causes the function to return 1 is[3]

SvSTASH (scalar) == bool_stash

because bool_stash is 0! bool_stash is assigned a value twice. Once in
BOOT[4] and for the second time in CLONE[5], which appears to be a problem.

Note, that to_json() dies even in the main thread.

[1] 
https://anonscm.debian.org/git/pkg-perl/packages/libjson-xs-perl.git/tree/XS.xs#n961
[2] 
https://anonscm.debian.org/git/pkg-perl/packages/libjson-xs-perl.git/tree/XS.xs#n356
[3] 
https://anonscm.debian.org/git/pkg-perl/packages/libjson-xs-perl.git/tree/XS.xs#n365
[4] 
https://anonscm.debian.org/git/pkg-perl/packages/libjson-xs-perl.git/tree/XS.xs#n1999
[5] 
https://anonscm.debian.org/git/pkg-perl/packages/libjson-xs-perl.git/tree/XS.xs#n2014

-- System Information:
Debian Release: 9.3
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: armel, arm64

Kernel: Linux 4.9.0-0.bpo.5-amd64 (SMP w/8 CPU cores)
Locale: LANG=pl_PL.UTF-8, LC_CTYPE=pl_PL.UTF-8 (charmap=UTF-8), 
LANGUAGE=pl_PL.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages libjson-xs-perl depends on:
ii  libc6   2.24-11+deb9u1
ii  libcommon-sense-perl3.74-2
ii  libtypes-serialiser-perl1.0-1
ii  perl5.24.1-3+deb9u2
ii  perl-base [perlapi-5.24.1]  5.24.1-3+deb9u2

libjson-xs-perl recommends no packages.

libjson-xs-perl suggests no packages.

-- no debconf information

-- 
Łukasz Stelmach
Samsung R Institute Poland
Samsung Electronics


signature.asc
Description: PGP signature