Commit d1004ba
committed
http: use size_t for byte position in fwrite_sha1_file
fwrite_sha1_file() tracks the number of bytes written via an int
variable posn, but the total size to write (eltsize * nmemb) is
size_t. When the HTTP response body exceeds INT_MAX (~2GB), posn
overflows and the expression (char *)ptr + posn accesses memory
before the buffer (heap under-read), then writes that data to the
local object file via xwrite.
The hash check afterward would reject the corrupt object (so no
bad data enters the object store), but the under-read itself
could leak adjacent heap contents to the temporary file. In
practice this is unlikely because curl delivers data in small
chunks (typically 16KB per callback invocation), so eltsize *
nmemb is far below INT_MAX in a single call. However, the
function interface accepts arbitrary sizes, and the accumulation
across the do-while loop means posn grows across calls within a
single invocation, not across callbacks.
Change posn from int to size_t to match the type of size. This
is a hardening fix: the attack surface (a malicious HTTP server
triggering a >2GB single-callback delivery) is theoretical under
normal curl configurations, but the type mismatch is a genuine
defect.
Pointed out by Coverity.
Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>1 parent 31e2a73 commit d1004ba
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2718 | 2718 | | |
2719 | 2719 | | |
2720 | 2720 | | |
2721 | | - | |
| 2721 | + | |
2722 | 2722 | | |
2723 | 2723 | | |
2724 | 2724 | | |
| |||
0 commit comments