Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGwQM-001CGR-7z for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Jun 2024 08:00:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sGwQI-003lKr-Pj for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Jun 2024 08:00:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGwQI-003lKj-87 for pgsql-bugs@lists.postgresql.org; Tue, 11 Jun 2024 08:00:07 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sGwQG-000lFP-O2 for pgsql-bugs@lists.postgresql.org; Tue, 11 Jun 2024 08:00:05 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-52bc335e49aso1058114e87.3 for ; Tue, 11 Jun 2024 01:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718092803; x=1718697603; darn=lists.postgresql.org; 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=K9p4VPbvJGm6HOP0p6RdNIYi/6tVxUBFny5RrtjkCP0=; b=cO4VtE6zNkH9zqjijM3WR+fSn2wQU7RfRZ2eJU4Qgjj+kI2PHSLkPoY+Z9jXizweig /KVENfRUpEbD583ZBhtpEB9YZEBDdLQmgBMKJCKZfYOHxvoXNfx77VTA90Yw8leHoGsd ZZNgY5MuSSkdG7Vky3qg0/SMLu1FTvGVvkICVyUtl2jxfTz8QFCbHqfGjMOGWOTbYl9i k3FDUHTVx5K76yEMQ6Yl5rpL0yr1mNHF8FnZ1xrKuEUGYK+mFrXdrLRB6e1rJPGxUR02 FutYUn8vXBX/BT0iUm3Sp7zWg+ncc7OPHTz6QmjY0k2G2f4q2493XISp/aCjrMJcJGwK +abQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718092803; x=1718697603; 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=K9p4VPbvJGm6HOP0p6RdNIYi/6tVxUBFny5RrtjkCP0=; b=jAAYbQ+ArY+i8reVYVGvO8HelQr331vxfzBLjFWH/vOBqPcNsjRfHVQt+R8ul42sZ1 aTjJGkuGFtwP6L12uT0kXSEXAXpUBlEb9kfH1kMuEaDdx7iJJcsgS+3N4T4NhzbuSij0 EzfZz/xStchlXSqU9uSB9BCa4kQ8cVG9hvlumNVVGlUKKlnJ3+n6MJhXDGfczvKhPlYf v8FUHtE7btMAAp99JJixYUuJv/xmiB81gyBt4iCro9H2GgOlMVuW5XmIXfztl98dhSI5 9AUWCZde5LqJiVzS+UFNDLZ5HKwEnIa9AUKYRAI/02X19N+/N+sRn2NlTEgr9HVqAIfW 5Low== X-Forwarded-Encrypted: i=1; AJvYcCXB65zGGPBc5gOV9zRL0KvMbDgxnCMYe2B2lFNWzDIa2H/5uqRn5v3e2PLapcFRvafjhaBUd+oB2B8liIIC7JX8zvTC9OLBHXjbMBiMLjvP X-Gm-Message-State: AOJu0Yx1vppFzDRUQZL2I4gvpFJOwQ1+cOJjgH1tufqvpd++J73OkXpH bTpYdb/w8wNNxAbJLTAEXhTaVlsAQ6cMbywk7vRF1y75rVjnLroh X-Google-Smtp-Source: AGHT+IHvHkGbUBNsg+Qi5KxDuVG4a2ut4hpa7gpuvcMX0BMXcuAMzURN6Ox6avtq9Rcd5miiFrvBaA== X-Received: by 2002:a05:6512:2c05:b0:52c:88ce:2a25 with SMTP id 2adb3069b0e04-52c88ce2a78mr4207211e87.48.1718092802649; Tue, 11 Jun 2024 01:00:02 -0700 (PDT) Received: from [1.0.0.7] ([178.155.25.76]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52c93efa281sm220214e87.146.2024.06.11.01.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Jun 2024 01:00:01 -0700 (PDT) Message-ID: <53085e53-7148-1707-1643-71a4969728cf@gmail.com> Date: Tue, 11 Jun 2024 11:00:01 +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: BUG #18483: Segmentation fault in tests modules Content-Language: en-US To: Michael Paquier Cc: Tom Lane , a.kozhemyakin@postgrespro.ru, pgsql-bugs@lists.postgresql.org References: <18483-30bfff42de238000@postgresql.org> <219049.1717792376@sss.pgh.pa.us> <439c9310-1d71-f2c6-b213-a9a2ea732ba9@gmail.com> <336833.1717859243@sss.pgh.pa.us> <250a21e5-d677-6b2a-2692-cd4233785e37@gmail.com> From: Alexander Lakhin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 11.06.2024 02:10, Michael Paquier wrote: > So, valgrind is noisy here because the incomplete byte sequence > \x8b passed as input of the function after a valid byte sequence > causes pg_encoding_mblen() to return 2, which is 1 byte passed the end > of the actual string. report_invalid_encoding() is careful to not > show any data passed in its input. I am not really sure that this is > worth bothering with here, TBH. As far as I know this is related to > the fact that we want test_enc_conversion() to be flexible enough to > accept any kind of input, working as a cheap shortcut to call these > internal encoding routines. What do you think? I think that maybe this case illustrates an API shortcoming. The report_invalid_encoding function takes len as an argument, but then passes mbstr as a null-terminated string to pg_encoding_mblen(): /*  * report_invalid_encoding: complain about invalid multibyte character  *  * note: len is remaining length of string, not length of character;  * len must be greater than zero, as we always examine the first byte.  */ void report_invalid_encoding(int encoding, const char *mbstr, int len) {     int         l = pg_encoding_mblen(encoding, mbstr); ... Maybe the comment should say something about null-termination expected? I could not find other report_invalid_encoding() callers that pass not null-terminated strings to it,  so maybe leave test_enc_conversion() as-is, just keep in mind that it is an imperfect example of report_invalid_encoding() usage and it might require some modifications for fuzz testing. Best regards, Alexander