git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] stream_to_pack: xread does not guarantee to read all requested bytes

From
Johannes Sixt <j6t@kdbg.org>
Date
Aug 20, 2013, 09:15 UTC
Message-ID
<521333AE.1090506@kdbg.org>

The deflate loop in bulk-checkin::stream_to_pack expects to get all bytes from a file that it requests to read in a single function call. But it used xread(), which does not give that guarantee. Replace it by read_in_full().

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 The size is limited to sizeof(ibuf) == 16384 bytes, so that there
 should not be a problem with the unpatched code on any OS in practice.
 Nevertheless, this change seems reasonable from a code hygiene POV.
 bulk-checkin.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 6b0b6d4..118c625 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -114,7 +114,7 @@ static int stream_to_pack(struct bulk_checkin_state *state,
 
 		if (size && !s.avail_in) {
 			ssize_t rsize = size < sizeof(ibuf) ? size : sizeof(ibuf);
-			if (xread(fd, ibuf, rsize) != rsize)
+			if (read_in_full(fd, ibuf, rsize) != rsize)
 				die("failed to read %d bytes from '%s'",
 				    (int)rsize, path);
 			offset += rsize;
-- 
1.8.4.rc3.1241.gcbfd92d.dirty
Next: Junio C Hamano
Message 1 of 8 in “stream_to_pack: xread does not guarantee to read all requested bytes”
  1. stream_to_pack: xread does not guarantee to read all requested bytesJohannes Sixt, Aug 20, 2013
  2. Junio C HamanoAug 20, 2013
  3. Antoine PelisseAug 20, 2013
  4. Junio C HamanoAug 20, 2013
  5. Johannes SixtAug 20, 2013
  6. Johannes SixtAug 20, 2013
  7. Junio C HamanoAug 20, 2013
  8. Johannes SixtAug 20, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.