Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bN4pC-0002vK-IP for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Jul 2016 21:02:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bN4pC-00060v-5O for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Jul 2016 21:02:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bN4hs-00038z-Nd for pgsql-bugs@postgresql.org; Tue, 12 Jul 2016 20:55:04 +0000 Received: from mail-pf0-x22f.google.com ([2607:f8b0:400e:c00::22f]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bN4hm-00032S-AY for pgsql-bugs@postgresql.org; Tue, 12 Jul 2016 20:55:02 +0000 Received: by mail-pf0-x22f.google.com with SMTP id h14so10506390pfe.1 for ; Tue, 12 Jul 2016 13:54:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gravitext-com.20150623.gappssmtp.com; s=20150623; h=date:from:subject:to:message-id:in-reply-to:references:mime-version; bh=kbUdQQuMIHE8n948dYTURZcUQinITla/ZYuIhI5Rd7k=; b=koV7D3hFrVm9XhM27xNxZQF9wKuWLGDnGl44K/5T7hWVFl1YeUm9CLXFULtLoRP3vC wm617eg/zxvt4gKEkhYBKLkI62KCkGS2IX22j7+puJIIsx2JN11vAimcYUvK7REnu64S G+pQHxbwgkOoQh0aXkh40LmUhAEVMhIoNAhFlZjY1AoU1SGe1UdyGvtqQXEXEtbcbPrH BF1sMwvhUHk3qe0oYHDT3SqqR1ChYphUn3FYvEJqaJXAoJDITUMPWMILgmogsWXlhArA zWUeTqXys0edZy03utaJ8obUz4i/fSho8rNOS8Icn4N3MORTWjudphxnT23QEY+HJlOu IS6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:subject:to:message-id:in-reply-to :references:mime-version; bh=kbUdQQuMIHE8n948dYTURZcUQinITla/ZYuIhI5Rd7k=; b=Ar3T1GIEXkcpCgg5J4vcRCYJ6BYQ7PefJa3f3D+cEGieXLcDQiPV0AvM8bJgVdqXPq ZadJWoX1D0DoVJXvL1iLy+Gbr9w3rJqrsIP0aD4OuCnKMyz3viibW2buviJaeV3plQ4y YwhuP+R4ulpX1AQfq7OGXVmzGM2PzF+K/Rk0Xtx819RKvMzuGEsT4gEONsHtYEnN8vtI 8lAJUQvcbHzwQ5pNfTHNLYtXM1npjhZosjL1bXxbr67YcfAKkkFMMsXJqvG5kx1Xyb/4 iMN4VKHeti/AN3Zk8gjDiMH3ODbF39RA5flC35e9jK7z6eqw2bWQbnv0PqHALIWufdRv c1Qg== X-Gm-Message-State: ALyK8tL+dP7Usq11nRvgaTcyd57by62TVknzEqs1V+SUFq5MSWkQrBLtqmzGnGxSi5dypw== X-Received: by 10.98.24.194 with SMTP id 185mr36044675pfy.52.1468356895110; Tue, 12 Jul 2016 13:54:55 -0700 (PDT) Received: from [10.5.18.45] ([64.125.192.130]) by smtp.gmail.com with ESMTPSA id w8sm299492paz.32.2016.07.12.13.54.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jul 2016 13:54:54 -0700 (PDT) Date: Tue, 12 Jul 2016 13:54:53 -0700 From: David Kellum Subject: Re: BUG #14245: Segfault on weird to_tsquery To: pgsql-bugs Message-Id: <1468356893.2574.7@smtp.gmail.com> In-Reply-To: <2157.1468352545@sss.pgh.pa.us> References: <20160712175855.1414.10498@wrigleys.postgresql.org> <2157.1468352545@sss.pgh.pa.us> X-Mailer: geary/0.11.0 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=-ziixeAqR81UgvBIAZFLi" X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --=-ziixeAqR81UgvBIAZFLi Content-Type: text/plain; charset=utf-8; format=flowed On Tue, Jul 12, 2016 at 12:42 PM, Tom Lane wrote: > david@gravitext.com writes: >> I am doing some (fuzz) testing of full text queries and managed to >> generate the following case which causes a SEGFAULT on PostgreSQL >> 9.6 >> beta1 and beta2: >> select to_tsquery('!(a & !b) & c') as tsquery >> This weird query outputs the following on 9.5.2, instead of >> crashing: >> "!( !'b' ) & 'c'" > > Note that while crashing is certainly not good, the pre-9.6 behavior > can hardly be called correct either. What happened to 'a'? 'a' is a stopword, dropped by to_tsquery() as described here: https://www.postgresql.org/docs/9.6/static/textsearch-controls.html#TEXTSEARCH-PARSING-QUERIES > The difference is that while basic tsquery input takes the tokens at > face value, to_tsquery normalizes each token into a lexeme using the > specified or default configuration, and discards any tokens that are > stop words according to the configuration. ...and I believe I want this behavior. Otherwise queries with stopword in '&' condition will not match anything. In truth I have no reason to want to support this kind of weird double negative, on any version, and will also look at filtering it out in my code before calling to_tsquery(). It might be worth noting that these other slightly different cases are fine on 9.6: select to_tsquery('!(apple & !b) & c'); ---> !( 'appl' & !'b' ) & 'c' select to_tsquery('!(apple & !a) & c'); ---> !'appl' & 'c'\ Clearly a pretty obscure case, but a crash nonetheless. > Also, it looks like this is specific to to_tsquery; if you just feed > the same thing to tsqueryin, it seems fine with it: > > # select '!(a & !b) & c'::tsquery; > tsquery > ----------------------- > !( 'a' & !'b' ) & 'c' > (1 row) Against another test table, English search config, I confirmed that 'a & ball'::tsquery doesn't match anything, but to_tsquery('a & ball') does. Thanks, David --=-ziixeAqR81UgvBIAZFLi Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Jul 12, 2016 at 12:42 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:=
david@gravitext.com wri= tes:
I am doing some (fuzz) testing of full text queries and manage= d to generate the following case which causes a SEGFAULT on PostgreSQL 9.6 beta1 and beta2: select to_tsquery('!(a & !b) & c') as tsquery This weird query outputs the following on 9.5.2, instead of crashing: "!( !'b' ) & 'c'"
Note that while crashing is certainly not good, the pre-9.6 behavior can hardly be called correct either. What happened to 'a'?

'a' is a stopword, dropped by to_tsquery() as descri= bed here:

The difference is that = while basic tsquery input takes the tokens at face value, to_tsquery normal= izes each token into a lexeme using the specified or default configuration,= and discards any tokens that are stop words according to the configuration= .

...and I believe I want this behavi= or.  Otherwise queries with stopword in '&' condition will not mat= ch anything.  In truth I have no reason to want to support this kind o= f weird double negative, on any version, and will also look at filtering it= out in my code before calling to_tsquery(). 

It might be worth noting that these other slightly different cases ar= e fine on 9.6:

select to_tsquery('!(apple & !b= ) & c'); ---> !( 'appl' & !'b' ) & 'c'
select to_t= squery('!(apple & !a) & c'); ---> !'appl' & 'c'\
<= div>
Clearly a pretty obscure case, but a crash nonetheless.<= /div>

Also, it looks like this is spe= cific to to_tsquery; if you just feed the same thing to tsqueryin, it seems fine with it: # select '!(a & !b) & c'::tsquery; tsquery =20 ----------------------- !( 'a' & !'b' ) & 'c' (1 row)

Against another = test table, English search config, I confirmed that 'a & ball'::tsquery= doesn't match anything, but to_tsquery('a & ball') does.
Thanks,
David




= --=-ziixeAqR81UgvBIAZFLi--