From 2ed0dc34326af28cb4a6cf97b229f3a7300bae6e Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Tue, 3 Mar 2026 15:53:07 +0100 Subject: [PATCH] Fix integer overflow in fake fileid calculation Replace INT64_MAX - (UINT64_MAX - taskid) with INT64_MIN + taskid. Avoids signed/unsigned mixing and signed overflow (UB). Fixes #252 --- pclsync/pfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pclsync/pfs.c b/pclsync/pfs.c index fa8ce64..1466d27 100644 --- a/pclsync/pfs.c +++ b/pclsync/pfs.c @@ -1389,8 +1389,10 @@ static int pfs_open(const char *path, struct fuse_file_info *fi) { } else { /* cr->fileid==0 */ psync_fstask_local_creat_t *lc; + int64_t fake_fileid; lc = pfs_task_creat_get_local(cr); - of = pfs_create_file(INT64_MAX - (UINT64_MAX - cr->taskid), 0, + fake_fileid = INT64_MIN + (int64_t)cr->taskid; + of = pfs_create_file(fake_fileid, 0, lc->datalen, 0, 1, 0, pfs_task_get_ref_locked(folder), fpath->name, PSYNC_CRYPTO_INVALID_ENCODER);