PARI/GP Bug report logs - #1237
undefined behaviour in pari_init_parser

Package: pari; Maintainer for pari is Aurel Page <aurel.page@normalesup.org>; Source for pari is src:pari.

Reported by: Julian Taylor <jtaylor.debian@googlemail.com>

Date: Wed, 31 Aug 2011 15:33:08 UTC

Severity: normal

Done: Bill Allombert <Bill.Allombert@math.u-bordeaux1.fr>

Bug is archived. No further changes may be made.

Full log


Message #10 received at 1237@pari.math.u-bordeaux.fr (full text, mbox, reply):

Received: (at 1237) by pari.math.u-bordeaux.fr; 1 Sep 2011 20:22:51 +0000
From Bill.Allombert@math.u-bordeaux1.fr Thu Sep 01 22:22:51 2011
Received: from smtp5-g21.free.fr ([212.27.42.5])
	by pari.math.u-bordeaux1.fr with esmtp (Exim 4.69)
	(envelope-from <Bill.Allombert@math.u-bordeaux1.fr>)
	id 1QzDml-0007Kc-3z
	for 1237@pari.math.u-bordeaux.fr; Thu, 01 Sep 2011 22:22:51 +0200
Received: from yellowpig (unknown [82.239.212.167])
	by smtp5-g21.free.fr (Postfix) with ESMTP id 9A75AD480C4;
	Thu,  1 Sep 2011 22:22:46 +0200 (CEST)
Received: from bill by yellowpig with local (Exim 4.72)
	(envelope-from <Bill.Allombert@math.u-bordeaux1.fr>)
	id 1QzDmf-0003Ia-CQ; Thu, 01 Sep 2011 22:22:45 +0200
Date: Thu, 1 Sep 2011 22:22:45 +0200
From: Bill Allombert <Bill.Allombert@math.u-bordeaux1.fr>
To: Julian Taylor <jtaylor.debian@googlemail.com>,
	1237@pari.math.u-bordeaux.fr
Subject: Re: Bug#1237: undefined behaviour in pari_init_parser
Message-ID: <20110901202245.GH17070@yellowpig>
References: <4E5E52C5.4050702@googlemail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
In-Reply-To: <4E5E52C5.4050702@googlemail.com>
User-Agent: Mutt/1.5.20 (2009-06-14)
Content-Transfer-Encoding: quoted-printable
On Wed, Aug 31, 2011 at 05:27:01PM +0200, Julian Taylor wrote:
> Package: pari
> Version: 2.5.0
> 
> Hi,
> the stack_init function used from pari_init_parser exhibits undefined behavior.
> Thanks to Måns Rullgård for spotting this issue and suggesting the patch.
> 
> pari_init_parser calls stack_init with argument one and three unrelated variables
> in being in global/thread-local memory:
> src/language/parsec.h:43 stack_init(&s_node,sizeof(*pari_tree),(void **)&pari_tree);
> 
> In stack init this is used:
> src/headers/pariinl.h:560 stack_init(pari_stack *s, size_t size, void **data)
> {
>   s->offset = (char *)data-(char *)s;
> 
> here the difference between the unrelated memory location is taken which is undefined.

Hello Julian,

Undefined according to what rule ? The code is only requiring the adress space to be flat
which is true on all supported platforms.

> This leads to testsuite failures on some architectures like armel [0]m armhf [1] and sparc [2]
> 
> This patch would solves the issue by using a pointer directly instead of an offset.
> With it the testsuite succeeds on armel and amd64 (more were not tested).

Unfortunately, this patch breaks the documented API and ABI. The offset was introduced
for a purpose, see the documentation of pari_stack. GP2C would not work with your patch
applied.

The optimisation issue with gcc-4.6 was reported here http://bugs.debian.org/627084 
and http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49140 and 
http://bugs.debian.org/635214. Test-cases are provided.

Cheers,
-- 
Bill. <ballombe@debian.org>

Imagine a large red swirl here. 



Send a report that this bug log contains spam.


Bill Allombert <allomber@math.u-bordeaux.fr>. Last modified: Sat Aug 26 17:15:15 2023; Machine Name: pari

PARI/GP Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.