Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5ZJx-0002Cn-5Q for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Mar 2019 17:11:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h5ZJv-0008Gn-7b for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Mar 2019 17:11:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5ZJu-0008Gg-HE for pgsql-hackers@lists.postgresql.org; Sun, 17 Mar 2019 17:11:35 +0000 Received: from anastigmatix.net ([68.171.219.55]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h5ZJr-0003pZ-A3 for pgsql-hackers@postgresql.org; Sun, 17 Mar 2019 17:11:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=anastigmatix.net; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:Cc:References:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=YNw5f1QyziA1fCPSrvTNY73K3We6egQGrOPseD1sxeU=; b=RVBrVrFbUeGD6ZmP31oxyp5pmZ VL/SqvqcKa+YiEEWS5wu3fPb9RBH7k31PBgfgNm1WMO7Vl4izUd0LK23OoeTyUA8OzQiGrRy1jrEl IEvWjU2rZs5+lp2eWSHaMAtrj+0f3A7fm4LBLzCn3E2c100MN2nhzJjcO6wlr93LP6FT3aaosb79R 1srZOS62aKax0403DgMuHve3hFwLe+ruepowupTaq0rRpVgdo2i37ro2T8dYB6nnfedj6iwsKHrl6 5LSgvkBVy4gOK/WcjKg1GfvZDe7G2BvdKEGbbMPKNo7ebtW5bPhEkew5J/2CJVYq5tdZvixXcbfBj HMDqsSqA==; Received: from [184.19.63.78] (port=46183) by bay.acenet.us with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.91) (envelope-from ) id 1h5ZJp-00EJtF-7X; Sun, 17 Mar 2019 13:11:30 -0400 Subject: Re: Fix XML handling with DOCTYPE To: Tom Lane References: <5C8D5D16.7090206@anastigmatix.net> <23319.1552769738@sss.pgh.pa.us> <5C8D6681.4070504@anastigmatix.net> <24203.1552771272@sss.pgh.pa.us> <5C8D79AF.7010204@anastigmatix.net> <5146.1552837534@sss.pgh.pa.us> Cc: Ryan Lambert , pgsql-hackers@postgresql.org From: Chapman Flack X-Enigmail-Draft-Status: N1110 Message-ID: <5C8E7FC0.8040401@anastigmatix.net> Date: Sun, 17 Mar 2019 13:11:28 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <5146.1552837534@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-OutGoing-Spam-Status: No, score=-95.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bay.acenet.us X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - anastigmatix.net X-Get-Message-Sender-Via: bay.acenet.us: authenticated_id: chap@anastigmatix.net X-Authenticated-Sender: bay.acenet.us: chap@anastigmatix.net X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, already matched List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/17/19 11:45, Tom Lane wrote: > Chapman Flack writes: >> On 03/16/19 17:21, Tom Lane wrote: >>> (1) always try to parse as document. If successful, we're done. >>> (2) otherwise, if allowed by xmloption, try to parse using our > >> What I don't like about that is that (a) the input could be >> arbitrarily long and complex to parse (not that you can't imagine >> a database populated with lots of short little XML snippets, but >> at the same time, a query could quite plausibly deal in yooge ones), >> and (b), step (1) could fail at the last byte of the input, followed >> by total reparsing as (2). > > That doesn't seem particularly likely to me: based on what's been > said here, I'd expect parsing with the wrong expectation to usually > fail near the start of the input. In any case, the other patch > also requires repeat parsing, no? It's just doing that in a different > set of cases. I'll do up a version with the open-coded prescan I proposed last night. Whether parsing with the wrong expectation is likely to fail near the start of the input depends on both the input and the expectation. If your expectation is DOCUMENT and the input is CONTENT, it's possible for the determining difference to be something that follows the first element, and a first element can be (and often is) nearly all of the input. What I was doing in the patch is the reverse: parsing with the expectation of CONTENT to see if a DTD gets tripped over. It isn't allowed for an element to precede a DTD, so that approach can be expected to fail fast if the other branch needs to be taken. But a quick pre-scan for the same thing would have the same property, without the libxml dependencies that bother you here. Watch this space. Regards, -Chap