pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Andrey Borodin <x4mmm@yandex-team.ru>
Cc: Sergey Mirvoda <sergey@mirvoda.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Андрей Бородин <borodin@octonica.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15420: Server crash. Segmentation fault when parsing xml file
Date: Fri, 05 Oct 2018 06:08:38 +0100
Message-ID: <87pnwpc7wi.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <FB4290EC-851A-4BE4-A5F5-3A96FBEE014F@yandex-team.ru>
References: <15420-6648d2ed070c05d4@postgresql.org>
	<20181004091103.GC1256@paquier.xyz>
	<CALkWArhSqk3RVefP-UHrz8FxE0F4Wyas3yHyyf_1QKqVM_84=g@mail.gmail.com>
	<CAFj8pRDStCJR2KppoV+0+6ZSxaVx2vuEEkLef=2AKULDL-T-Dg@mail.gmail.com>
	<CAFj8pRBzoi7GhaJEVg16zgiqe9y5t_yV3t5aAua5P46=aQQrkg@mail.gmail.com>
	<CALkWArg-fBxB+pHn440BFm_+eOmihPny44ObqBGoEZG9Y9DAiQ@mail.gmail.com>
	<0FD7884D-E9D9-41DF-AA05-15E7420F996A@yandex-team.ru>
	<87tvm1cbkk.fsf@news-spur.riddles.org.uk>
	<FB4290EC-851A-4BE4-A5F5-3A96FBEE014F@yandex-team.ru>

>>>>> "Andrey" == Andrey Borodin <x4mmm@yandex-team.ru> 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)




view thread (39+ messages)  latest in thread

Message-ID: <87pnwpc7wi.fsf@news-spur.riddles.org.uk>
Permalink:  ../87pnwpc7wi.fsf@news-spur.riddles.org.uk/
Also on:    postgresql.org/message-id/87pnwpc7wi.fsf@news-spur.riddles.org.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andrew@tao11.riddles.org.uk, x4mmm@yandex-team.ru, sergey@mirvoda.com, pavel.stehule@gmail.com, borodin@octonica.com, michael@paquier.xyz
  Subject: Re: BUG #15420: Server crash. Segmentation fault when parsing xml file
  In-Reply-To: <87pnwpc7wi.fsf@news-spur.riddles.org.uk>
  References: <15420-6648d2ed070c05d4@postgresql.org> <20181004091103.GC1256@paquier.xyz> <CALkWArhSqk3RVefP-UHrz8FxE0F4Wyas3yHyyf_1QKqVM_84=g@mail.gmail.com> <CAFj8pRDStCJR2KppoV+0+6ZSxaVx2vuEEkLef=2AKULDL-T-Dg@mail.gmail.com> <CAFj8pRBzoi7GhaJEVg16zgiqe9y5t_yV3t5aAua5P46=aQQrkg@mail.gmail.com> <CALkWArg-fBxB+pHn440BFm_+eOmihPny44ObqBGoEZG9Y9DAiQ@mail.gmail.com> <0FD7884D-E9D9-41DF-AA05-15E7420F996A@yandex-team.ru> <87tvm1cbkk.fsf@news-spur.riddles.org.uk> <FB4290EC-851A-4BE4-A5F5-3A96FBEE014F@yandex-team.ru> <87pnwpc7wi.fsf@news-spur.riddles.org.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox