--- zfs_vnops_os.c.sav	2023-04-10 08:01:05.905906000 -0700
+++ zfs_vnops_os.c	2023-04-10 08:14:40.563743000 -0700
@@ -6242,7 +6242,8 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range
 	struct mount *mp;
 	struct uio io;
 	int error;
-	uint64_t len = *ap->a_lenp;
+	uint64_t len;
+	ssize_t r = 0;
 
 	/*
 	 * TODO: If offset/length is not aligned to recordsize, use
@@ -6280,9 +6281,14 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range
 
 	io.uio_offset = *ap->a_outoffp;
 	io.uio_resid = *ap->a_lenp;
-	error = vn_rlimit_fsize(outvp, &io, ap->a_fsizetd);
+	error = vn_rlimit_fsizex(outvp, &io, 0, &r, ap->a_fsize_td);
 	if (error != 0)
 		goto out_locked;
+	len = io.uio_resid;
+	/*
+	 * No need to call vn_rlimit_fsizex_res before return,
+	 * since the uio is local.
+	 */
 
 	error = zfs_clone_range(VTOZ(invp), ap->a_inoffp, VTOZ(outvp),
 	    ap->a_outoffp, &len, ap->a_outcred);
