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 1icCLT-0007L5-KW for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Dec 2019 17:52:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1icCLS-0003UD-Dr for pgsql-bugs@arkaria.postgresql.org; Tue, 03 Dec 2019 17:52:18 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1icCLS-0003Sw-3J for pgsql-bugs@lists.postgresql.org; Tue, 03 Dec 2019 17:52:18 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1icCLP-0006N6-2I for pgsql-bugs@lists.postgresql.org; Tue, 03 Dec 2019 17:52:17 +0000 Received: by mail-wr1-x444.google.com with SMTP id a15so4797377wrf.9 for ; Tue, 03 Dec 2019 09:52:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=F+dbfPYbweE/+mcV0ieocD2FhLLbJAfTruLN0+Vx80Q=; b=YUu3UmRq15QzHUlp5yxGBkMguRi4wfgdrcB8M3ZktN8nSupiIjW+viT3fYeaXtrypg lvIlj4ULfgge5B3tjbOfCw41IBGPZeF+W9sLGybVtQ2h8HMbsi+QtRSD7DUzp7ouKvyu tVXIA/zkNsw6f2CMSxQ1Wa3RLx+UB4rLmH+gSumFyUru2r1R1AqZAkigJEwRfHuO3Ito 4fThcDEn1m8F0aefZaQ+4awRhtnSk1Y8Es7U14z8YTV1elZ1qBmENvgc5nEeoKG3oiuN gjzcvnPMi9KLjM0RrEueic2pmvPq1fJ/XALXKeCK5pXPw31DzvST6yIDKJ377YlC5Yd6 YLOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=F+dbfPYbweE/+mcV0ieocD2FhLLbJAfTruLN0+Vx80Q=; b=n9uhioD4knlOIkRqehOjtOykUWqPNBQm/TXk1XhitNSmC1hLYQa24BfZ7oXqZnLB8d Iu1yL97DXoXVthHO5EM0XPfptrKj7iKrm6mesRFZa6edds1iTpStHeW0lw4iJFSqxqMt MBLYZeaaW8yGCNeCKE6ii00og46TB314lZ6v8nOyNwqFq/evM2OgdxNkFfmwq0sgxLqQ d9lgsmWctnWmm6Caw6OwhlYb9cJRyg/HuZTy3SCN5/ZJFGrUjSQj15zNlUynW4jhQBoB aUHCu1zIs9ePXujD8KSRSz+0fVpEkOg0SymJD1l+Lr6WieyUnqI8OLlbSxjKi6jRI2Uj rIuQ== X-Gm-Message-State: APjAAAWVFay2z8r07LrRcNFAaF8/aBML956ssUVawAOS3bduQ0Gl2Cr2 kYPl3JvWXHKi3+zf0Vy4Gq9IXQ== X-Google-Smtp-Source: APXvYqzJksFijVW+p2O43ApzFNF6BGa0nYieyiEXTAseUm1uAudX4idF+Z710h0y/UUMJwJywfWwHQ== X-Received: by 2002:a5d:6305:: with SMTP id i5mr6696401wru.119.1575395533925; Tue, 03 Dec 2019 09:52:13 -0800 (PST) Received: from localhost (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id e16sm4445362wrj.80.2019.12.03.09.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2019 09:52:12 -0800 (PST) Date: Tue, 3 Dec 2019 18:52:11 +0100 From: Tomas Vondra To: cilizili@protonmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16144: Segmentation fault on dict_int extension Message-ID: <20191203175211.fllaggkccolrngbi@development> References: <16144-a36a5bef7657047d@postgresql.org> <20191202161920.d3k7b6dpqcgl5mst@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20191202161920.d3k7b6dpqcgl5mst@development> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Dec 02, 2019 at 05:19:20PM +0100, Tomas Vondra wrote: >On Mon, Dec 02, 2019 at 12:41:21PM +0000, PG Bug reporting form wrote: >>The following bug has been logged on the website: >> >>Bug reference: 16144 >>Logged by: cili >>Email address: cilizili@protonmail.com >>PostgreSQL version: 12.1 >>Operating system: CentOS 7.4 >>Description: >> >>The dict_int extension is an example of an add-on dictionary template for >>full-text search. The 'intdict' is a built-in dictionary. If we set MAXLEN >>parameter with negative value for the dictionary, ts_lexize function causes >>a segmentation fault. The negative limit for MAXLEN which causes >>segmentation fault is environment dependent. >> >># initdb >># pg_ctl -D /var/lib/pgsql/data -l logfile start >># psql >> >>postgres=# CREATE EXTENSION dict_int; >>CREATE EXTENSION >>postgres=# ALTER TEXT SEARCH DICTIONARY intdict (MAXLEN = -214783648); >>ALTER TEXT SEARCH DICTIONARY >>postgres=# select ts_lexize('intdict', '12345678'); >>server closed the connection unexpectedly >> This probably means the server terminated abnormally >> before or while processing the request. >>The connection to the server was lost. Attempting reset: Failed. >>!> >>!>\q >> > >Yeah, this seems to be a failure in evaluating maxlen parameter. It's >set to 6 by default, but we simply trust whatever value the user gives >us, and then we do this > > txt[d->maxlen] = '\0'; > >which fails for obvious reasons. > >Will fix by rejecting maxlen values less than 1. The docs don't say >which value should the the minimum, but 0 seems useless. > I've pushed a fix for this, rejecting maxlen values less than 1. I also backpatched this to all supported releases (the issue exists since 9.3). As for the upper limit, that's capped by length of the input string. There's an issue with using atoi() which does not report errors, but that's a separate issue. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services