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 1iIzlM-0006pp-Pn for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Oct 2019 18:35:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iIzlJ-0005x1-Fw for pgsql-bugs@arkaria.postgresql.org; Fri, 11 Oct 2019 18:35:37 +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 1iIzlJ-0005wh-1u for pgsql-bugs@lists.postgresql.org; Fri, 11 Oct 2019 18:35:37 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iIzlF-0007ND-TR for pgsql-bugs@lists.postgresql.org; Fri, 11 Oct 2019 18:35:35 +0000 Received: by mail-wr1-x442.google.com with SMTP id j11so13000084wrp.1 for ; Fri, 11 Oct 2019 11:35:33 -0700 (PDT) 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:user-agent; bh=HoVk0qukYB6OhrydMwiJPOBh5BI74Qez5w8x9F2JfCo=; b=BMndFUaVuN34Wr8Rh01ciD+c55DvAESKzQgtd1Zy25uUmGYHIdg3O15g08PWuB46PQ iREOB3E8E+GIrEfQrwKzMrcyUCAIJO4c9pju3nWUTGX+fvInbIQrP1RcRvZCuNG3gaRF fN11WYKhzhOdOt2J/bKA6IUbEbxri5F3lnygkYTVJjXcCz42eT5kOPC2b6MeuSQNZlWU 9SwvJoisq+aCS41m7/tX1uD4YIgH+dLjU2RGM1QHjX0tv620bcsE7rQOPdXCZMvpkzuP idoTTMU4+q9INAZBCtgD4VwHJh52SnEYNidjfj2V/YATtaAUA8YBh1pTUdzkjQt+cKA1 wLtw== 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:user-agent; bh=HoVk0qukYB6OhrydMwiJPOBh5BI74Qez5w8x9F2JfCo=; b=o2Mjtxl67q71LmYoF8CG1HpDphS/jyISNdAA8gW43PM9xNU673STp7k1owNNFjQ+AG ykSTVfzBp8ZnHVbmt3dKWzc++6ReGdtq/gOErPZnqoe88vhL6Z4MJWhOzhbQ+YmUcZ2M 9nskAbojGsI8Z6nBafYk76Ozd5GnB+oPNtCqZaWdANZidM+oOitqO6xNG9+XqW3WYXAi aQ7tZ/l0rvpicXi8Fn5Hy4WeBz3U3qp0B0UeB4VsMrBadh0SmSQVukRwt7OZKpCvRa3v xbTSrUhhR6Ph8GpXhi3bjgdPmUwy51iY3ZXnUvO4Vi3Mlh/0YWEBgN3J7vIK1XKBZ5yY 2RTg== X-Gm-Message-State: APjAAAVt2rdbfgZnrWgt2Wx8JSYLMgvt9sjSgueZf75qd8jvDuyoPH58 rmT3TynvOSUwX0gqjHLtJHwGfA== X-Google-Smtp-Source: APXvYqzAEBUojaYL8TEwyEq8iKWBEsCGXq5lk1mfvejo7gpPzT0qMtBe5mUielGoH1YuV25CoV/7IQ== X-Received: by 2002:a5d:484e:: with SMTP id n14mr13869883wrs.110.1570818932318; Fri, 11 Oct 2019 11:35:32 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id a2sm11222648wrp.11.2019.10.11.11.35.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 11:35:31 -0700 (PDT) Date: Fri, 11 Oct 2019 20:35:30 +0200 From: Tomas Vondra To: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16050: Server crash on CREATE TEXT SEARCH DICTIONARY with a wrong AffFile Message-ID: <20191011183530.tnw5c6kbudl7e3nb@development> References: <16050-024ae722464ab604@postgresql.org> <20191011172739.gyim55av2dfr2xac@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20191011172739.gyim55av2dfr2xac@development> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Oct 11, 2019 at 07:27:39PM +0200, Tomas Vondra wrote: >On Fri, Oct 11, 2019 at 03:05:38PM +0000, PG Bug reporting form wrote: >>The following bug has been logged on the website: >> >>Bug reference: 16050 >>Logged by: Alexander Lakhin >>Email address: exclusion@gmail.com >>PostgreSQL version: 12.0 >>Operating system: Ubuntu 18.04 >>Description: >> >>The following query: >>CREATE TEXT SEARCH DICTIONARY hunspell_num (Template=ispell, >>DictFile=hunspell_sample_num, AffFile=hunspell_sample_long); >> >>crashes postgres with the stack trace: >>Core was generated by `postgres: law regression [local] CREATE TEXT SEARCH >>DICTIONARY '. > >Yep, I can reproduce it quite easily. With extra debug symbols and >memory randomization it produces a bit clearer backtrace: > > >Program received signal SIGSEGV, Segmentation fault. >0x00000000008fd31b in getCompoundAffixFlagValue (Conf=0x2d053c8, s=0x7f7f7f7f7f7f7f7f ) at spell.c:1126 >1126 while (*flagcur) >(gdb) bt >#0 0x00000000008fd31b in getCompoundAffixFlagValue (Conf=0x2d053c8, s=0x7f7f7f7f7f7f7f7f ) at spell.c:1126 >#1 0x00000000008fe627 in makeCompoundFlags (Conf=0x2d053c8, affix=303) at spell.c:1608 >#2 0x00000000008fe959 in mkSPNode (Conf=0x2d053c8, low=0, high=1, level=3) at spell.c:1680 >#3 0x00000000008fea1e in mkSPNode (Conf=0x2d053c8, low=0, high=1, level=2) at spell.c:1692 >#4 0x00000000008fe794 in mkSPNode (Conf=0x2d053c8, low=0, high=4, level=1) at spell.c:1652 >#5 0x00000000008fe794 in mkSPNode (Conf=0x2d053c8, low=0, high=9, level=0) at spell.c:1652 >... > >That is, makeCompontFlags calls getCompoundAffixFlagValue with invalid >pointer 's', likely after it got already pfreed. > FWIW this is a pre-existing bug, it's not new in 12. I've been able to reproduce it on all releases since 9.6. On 9.5 the example does not work, because it does not include the hunspell dictionaries. After copying those from 9.6, the CREATE command complains about long flags not being supported - I've removed the first line 'FLAG long' from the affix file, and then it works without a crash. Looking at the commit history of spell.c, there seems to be a bunch of commits in 2016 (e.g. f4ceed6ceba3) touching exactly this part of the code (hunspell), and it also correlates quite nicely with the affected branches (9.6+). So I guess it's a bug in those changes. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services