Re: Fix handling of copy_file_range() return value

From: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
To: peter(at)eisentraut(dot)org
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Fix handling of copy_file_range() return value
Date: 2026-06-22 08:34:53
Message-ID: 20260622.173453.167916546544184263.horikyota.ntt@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

At Mon, 22 Jun 2026 09:19:59 +0200, Peter Eisentraut <peter(at)eisentraut(dot)org> wrote in
> While checking return/error handling of file system calls, I found
> that the copy_file_range() call in pg_combinebackup has a potential
> problem. If copy_file_range() returns 0, which is a documented
> condition, then the loop never makes progress and could spin forever.
>
> The other uses of copy_file_range() in the tree are surrounded by
> different logic and don't appear to have this problem.
>
> My suggested fix is to make a return value of 0 an error. It most
> likely indicates that the source file has an unexpected size.

Good catch. I agree with the analysis, and the proposed fix looks
reasonable to me.

I also checked the other four uses of copy_file_range() in the
tree. All but one handle a zero return value as EOF, and the remaining
case (check_copy_file_range()) appears safe because it is only testing
whether copy_file_range() is usable.

Regards,

--
Kyotaro Horiguchi
NTT Open Source Software Center

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2026-06-22 08:38:21 Re: Proposal: Conflict log history table for Logical Replication
Previous Message jian he 2026-06-22 08:28:26 enum_in cache lookup failed for type