Thread (12 messages) flat view 12 messages, 3 authors, 1d ago
WARM1d

[PATCH 1/7] wrapper: guard writev_in_full() against signed overflow

From: Johannes Schindelin via GitGitGadget <hidden>
Date: 2026-09-17 17:52:42
Subsystem: the rest · Maintainer: Linus Torvalds

From: Johannes Schindelin <redacted>

As Git for Windows' Coverity run after merging v2.56.0-rc0 reported,
`writev_in_full()` keeps its cumulative successful output in an
`ssize_t`. Although `xwritev()` limits each individual write to a
syscall-sized amount, repeated successful writes can still exceed
`SSIZE_MAX`. The unchecked accumulation was introduced by d70eb7f3600d
(wrapper: introduce writev(3p) wrappers, 2026-08-07).

Treat an aggregate that would overflow the signed total as an I/O
failure.

Assisted-by: GPT-5.6 Luna
Signed-off-by: Johannes Schindelin <redacted>
---
 wrapper.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/wrapper.c b/wrapper.c
index 561f9ee9c9..05a9cd369c 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -376,6 +376,10 @@ ssize_t writev_in_full(int fd, struct iovec *iov, int iovcnt)
 			return -1;
 		}
 
+		if (signed_add_overflows(total_written, bytes_written)) {
+			errno = EOVERFLOW;
+			return -1;
+		}
 		total_written += bytes_written;
 
 		/*
-- 
gitgitgadget
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help