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 1svOWn-00Ei9a-H7 for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Sep 2024 22:06:02 +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 1svOWm-006UHT-T1 for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Sep 2024 22:06:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svOWm-006UHL-Io for pgsql-hackers@lists.postgresql.org; Mon, 30 Sep 2024 22:06:00 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1svOWj-001uYb-37 for pgsql-hackers@postgresql.org; Mon, 30 Sep 2024 22:06:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 48UM5uIt1636826; Mon, 30 Sep 2024 18:05:56 -0400 From: Tom Lane To: Robert Haas cc: Amul Sul , Sravan Kumar , PostgreSQL-development Subject: Re: pg_verifybackup: TAR format backup verification In-reply-to: References: <1115881.1727564342@sss.pgh.pa.us> <1240823.1727629418@sss.pgh.pa.us> <1467228.1727710261@sss.pgh.pa.u! s> Comments: In-reply-to Robert Haas message dated "Mon, 30 Sep 2024 16:11:58 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1636824.1727733956.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Mon, 30 Sep 2024 18:05:56 -0400 Message-ID: <1636825.1727733956@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > On Mon, Sep 30, 2024 at 11:31 AM Tom Lane wrote: >> WFM, modulo the suggestion about changing data types. > I would prefer not to make the data type change here because it has > quite a few tentacles. I see your point for the function's "len" argument, but perhaps it's worth doing - int remaining; + size_t remaining; remaining = sizeof(ControlFileData) - mystreamer->control_file_bytes; memcpy(((char *) &mystreamer->control_file) + mystreamer->control_file_bytes, - data, Min(len, remaining)); + data, Min((size_t) len, remaining)); This is enough to ensure the Min() remains safe. regards, tom lane