From: Johannes Schindelin <joha…@gmx.de>
The `fwrite_sha1_file()` function tracks the number of bytes written
during a single invocation in an `int` variable (`posn`), even though
the buffer length `size = eltsize * nmemb` has type `size_t`. If a
caller or callback ever passed more than `INT_MAX` bytes in a single
call, `posn` could overflow and wrap negative, causing `(char *)ptr +
posn` to under-read the buffer. While curl delivers data in small
chunks in practice, matching the variable type to `size` avoids the
defect.
Pointed out by Coverity.
Helped-by: Patrick Steinhardt <p…@pks.im>
Helped-by: Junio C Hamano <gits…@pobox.com>
Assisted-by: GPT-6 Luna
Assisted-by: Claude Opus 4.6 and GPT-6.1 Sol
Signed-off-by: Johannes Schindelin <joha…@gmx.de>
---
http.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/http.c b/http.c
index d79678d01f..2879eb3874 100644
--- a/http.c
+++ b/http.c
@@ -2848,7 +2848,7 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
{
unsigned char expn[4096];
size_t size = eltsize * nmemb;
- int posn = 0;
+ size_t posn = 0;
struct http_object_request *freq = data;
struct active_request_slot *slot = freq->slot;
--
gitgitgadget