Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pyx5w-0004FO-PI for pgsql-hackers@arkaria.postgresql.org; Tue, 16 May 2023 16:00:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pyx5u-00027w-F0 for pgsql-hackers@arkaria.postgresql.org; Tue, 16 May 2023 16:00:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pyx5u-00027T-3K for pgsql-hackers@lists.postgresql.org; Tue, 16 May 2023 16:00:10 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pyx5p-0009Vv-1d for pgsql-hackers@lists.postgresql.org; Tue, 16 May 2023 16:00:08 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f38bea8be8so4272497e87.0 for ; Tue, 16 May 2023 09:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684252803; x=1686844803; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=nrY08cCWFY7YpCW4a11ZQ7IBHnqME7ZJeRqWNDRPmlI=; b=i6mDqs2PZCS5MzdGMMM4rCcA/gTlC4560le2d0LYltj545UlUg4GFM23MkuQBSkRIU YzIl/2EPm4c1yWb+svhULxgdM39SWSPF311tImJ9OCOYtrs1GVxhY6u8xbnQCsG0hDIR 96nN3pt1zIOeToovRTdUyuz5+ZVa0AsXrshAQtsiZxkmge7UoXZvdIDjqCfm85zwU4ED gfLuFkEdN7+jtgj/szEV+INa4ZR1SGq6FfFQrUoGDjQ4TQ42fbteoT9BJvHksSNUS6aS V9WJwlRR5JeLwpF++r/i3p0GkQZ6zOIqekaXuhEOyNz8/HQVTeHY4fFRr8jfPA+qrp3I vZ2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684252803; x=1686844803; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nrY08cCWFY7YpCW4a11ZQ7IBHnqME7ZJeRqWNDRPmlI=; b=PNLPh8sWP/cRVHGZkqAgheRQn1LczYH8F6FukmXHFrBQm+FD/HzCNP3Rw+Htj3yzYM oCipDB60uzPnq40s6QbasL0bkNEN5aTvMrZJq55180H/EcuooAoKNWkE2j/H1FuW4TQV 7pZ72lnKPPSZGg5Fi9k7VHcs3oewmtQPJcXq778ZrT3k2tF00ohUPGL9CCAFojE9ZDw2 Rt1pmuaH/a+nc02jDQX2XswVQyuw+exGRcW63aByd9GZKzQwQVt3QGM9HL2+BFmyb9C8 /6kiuYdaNtvELvgGtNtVID5zov9WC4OTC1c/mDMa69mODZ0q0rBWQy2q0dDX7ukBPQrT Yy1Q== X-Gm-Message-State: AC+VfDxj+gVacCTJCqDn2eGieSK2hxDEhRR0J6eXIgkucZlQoKIjp3bN ZqVjq2RHsNlBrFAL279H0mM= X-Google-Smtp-Source: ACHHUZ59wpvPLwXnnzuuBhe1jdYGPNBcDWzphdA634BbuKd3QdRaVXNU+dMb0jUth5kjdOjHhnyhEA== X-Received: by 2002:a05:6512:10c6:b0:4ed:b86b:9cc9 with SMTP id k6-20020a05651210c600b004edb86b9cc9mr7605864lfg.28.1684252803186; Tue, 16 May 2023 09:00:03 -0700 (PDT) Received: from [1.0.0.7] ([81.23.166.126]) by smtp.gmail.com with ESMTPSA id o3-20020ac24943000000b004f27cf63a03sm1602776lfi.299.2023.05.16.09.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 May 2023 09:00:02 -0700 (PDT) Message-ID: Date: Tue, 16 May 2023 19:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Order changes in PG16 since ICU introduction Content-Language: en-US To: Jeff Davis , Tom Lane Cc: Daniel Verite , Andrew Gierth , Peter Eisentraut , Sandro Santilli , Regina Obe , pgsql-hackers@lists.postgresql.org References: <543e4ce6-8205-4aea-b54b-12b9ef747bf6@manitou-mail.org> <654a49f7ff7461bcf47be4181430678d45f93858.camel@j-davis.com> <37520ec1ae9591f83132f82dbd625f3fc2d69c16.camel@j-davis.com> <483826.1683582475@sss.pgh.pa.us> <2098874d-c111-41e4-9063-30bcf135226b@gmail.com> <91c0cdd2a402d59f8d6eaac40862d6f68e0b937c.camel@j-davis.com> From: Alexander Lakhin In-Reply-To: <91c0cdd2a402d59f8d6eaac40862d6f68e0b937c.camel@j-davis.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Jeff, 16.05.2023 00:03, Jeff Davis wrote: > On Sat, 2023-05-13 at 13:00 +0300, Alexander Lakhin wrote: >> On the current master (after 455f948b0, and before f7faa9976, of >> course) >> I get an ASAN-detected failure with the following query: >> CREATE COLLATION col (provider = icu, locale = '123456789012'); >> > Thank you for the report! > > ICU source specifically says: > > /** > * Useful constant for the maximum size of the language > part of a locale ID. > * (including the terminating NULL). > * @stable ICU 2.0 > */ > #define ULOC_LANG_CAPACITY 12 > > So the fact that it returning success without nul-terminating the > result is an ICU bug in my opinion, and I reported it here: > > https://unicode-org.atlassian.net/browse/ICU-22394 > > Unfortunately that means we need to be a bit more paranoid and always > check for that warning, even if we have a preallocated buffer of the > "correct" size. It also means that both U_STRING_NOT_TERMINATED_WARNING > and U_BUFFER_OVERFLOW_ERROR will be user-facing errors (potentially > scary), unless we check for those errors each time and report specific > errors for them. > > Another approach is to always check the length and loop using dynamic > allocation so that we never overflow (and forget about any static > buffers). That seems like overkill given that the problem case is > obviously invalid input; I think as long as we catch it and throw an > ERROR it's fine. But I can do this if others think it's worthwhile. > > Patch attached. It just checks for the U_STRING_NOT_TERMINATED_WARNING > in a few places and turns it into an ERROR. It also cleans up the loop > for uloc_getLanguageTag() to check for U_STRING_NOT_TERMINATED_WARNING > rather than (U_SUCCESS(status) && len >= buflen). I'm not sure about the proposed change in icu_from_uchar(). It seems that len_result + 1 bytes should always be enough for the result string terminated with NUL. If that's not true (we want to protect from some ICU bug here), then the change should be backpatched? Best regards, Alexander