Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g8IMB-0005rW-9v for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Oct 2018 05:08:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g8IM8-0006Y5-R5 for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Oct 2018 05:08:52 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g8IM8-0006Xs-DJ for pgsql-bugs@lists.postgresql.org; Fri, 05 Oct 2018 05:08:52 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g8IM0-0002py-PY for pgsql-bugs@lists.postgresql.org; Fri, 05 Oct 2018 05:08:51 +0000 Received: from [192.168.127.1] (port=29072 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1g8ILv-00084H-LM; Fri, 05 Oct 2018 05:08:39 +0000 Received: from [127.0.0.1] (port=56324 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1g8ILu-000GxG-UH; Fri, 05 Oct 2018 05:08:39 +0000 From: Andrew Gierth To: Andrey Borodin Cc: Sergey Mirvoda , Pavel Stehule , =?utf-8?B?0JDQvdC00YDQtdC5INCR0L7RgNC+0LQ=?= =?utf-8?B?0LjQvQ==?= , Michael Paquier , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15420: Server crash. Segmentation fault when parsing xml file In-Reply-To: (Andrey Borodin's message of "Fri, 5 Oct 2018 09:40:44 +0500") Message-ID: <87pnwpc7wi.fsf@news-spur.riddles.org.uk> References: <15420-6648d2ed070c05d4@postgresql.org> <20181004091103.GC1256@paquier.xyz> <0FD7884D-E9D9-41DF-AA05-15E7420F996A@yandex-team.ru> <87tvm1cbkk.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Fri, 05 Oct 2018 06:08:38 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Andrey" == Andrey Borodin writes: >> You're sure about that libxml2 version? I can reproduce a crash on >> 2.9.4, but have as yet failed to do so on 2.9.7 (fails with an error >> message instead) Andrey> You are right, there was default 2.9.4 from OS, and 2.9.4 from Andrey> brew was not used. Andrey> x4mmm-osx:pgsql x4mmm$ xmllint --version Andrey> xmllint: using libxml version 20904 I have a complete diagnosis of why it crashes on 2.9.4, and I can see why it does not crash the same way on 2.9.7, but I would not bet anything on 2.9.7 not having some comparable issue. What happens on 2.9.4 is this (this is all inside libxml2): - at some point when parsing an element tag, the code decides to raise a fatal error and call xmlHaltParser - xmlHaltParser works by resetting the input buffer's "base" and "cur" pointers to point to a literal "" in the code (thus, a null byte) - xmlParseStartTag2 detects that input->base has changed, and assumes that this is because the buffer got reallocated; in the process of dealing with this, it resets input->cur to input->base + cur where "cur" is a local variable holding the previous offset in the buffer (which is now of course nonsense, so input->cur points into the weeds) - something later tries to access the byte at *input->cur and likely crashes (depending on many random factors, including load addresses of shared libraries and where in the buffer the original error was detected) Between 2.9.4 and 2.9.7 xmlParseStartTag2 was changed to handle buffer reallocations differently so it doesn't fail the same way (it no longer tries to modify input->cur). But there are so many ways that this error path can screw itself up that I honestly would not trust it for one second. -- Andrew (irc:RhodiumToad)