Commit 691459d
committed
wrapper: reject count > SSIZE_MAX in read_in_full/write_in_full
Both functions accumulate bytes transferred in a ssize_t total
variable, but accept a size_t count parameter. When count exceeds
SSIZE_MAX, total overflows after processing SSIZE_MAX bytes,
producing a negative return value that callers interpret as an
error (or worse, a small positive value after further wrapping).
In practice, git never passes such large counts because file
sizes and buffer allocations are bounded well below SSIZE_MAX on
all target platforms. The POSIX specification for read() and
write() also limits single operations to SSIZE_MAX bytes, and
git's xread/xwrite wrappers further clamp to MAX_IO_SIZE. But
the accumulation in the _in_full wrappers means that even with
per-call clamping, total can exceed SSIZE_MAX when count does.
Reject count > SSIZE_MAX upfront with EINVAL rather than
silently producing wrong return values. This matches the POSIX
convention where read/write return EINVAL for invalid arguments.
Pointed out by Coverity.
Assisted-by: Claude Opus 4.6
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>1 parent d1004ba commit 691459d
1 file changed
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
291 | 296 | | |
292 | 297 | | |
293 | 298 | | |
| |||
307 | 312 | | |
308 | 313 | | |
309 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
310 | 320 | | |
311 | 321 | | |
312 | 322 | | |
| |||
0 commit comments