{"thread":{"id":"13282","subject":"[PATCH] Die for an early EOF in a file reading loop","startedAt":"2008-04-27T14:07:24Z","lastAt":"2008-04-27T14:07:24Z","messageCount":1,"participants":["Heikki Orsila"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"75292","messageId":"20080427140724.GA26018@zakalwe.fi","threadId":"13282","inReplyTo":null,"subject":"[PATCH] Die for an early EOF in a file reading loop","fromName":"Heikki Orsila","fromEmail":"heikki.orsila@iki.fi","sentAt":"2008-04-27T14:07:24Z","receivedAt":"2008-04-27T14:07:24Z","isPatch":true,"sender":{"key":"heikki.orsila@iki.fi","avatar":null},"body":"The resulting data is zero terminated after the read loop, but\nthe subsequent loop that scans for '\\n' will overrun the buffer.\n\nSigned-off-by: Heikki Orsila <heikki.orsila@iki.fi>\n---\nYes, I know it is highly improbable that the file size changes between \nfstat() and read(), but so is read error on media.\n\n combine-diff.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 0e19cba..a4269f6 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -719,8 +719,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\t\twhile (sz < len) {\n \t\t\t\tssize_t done = xread(fd, result+sz, len-sz);\n \t\t\t\tif (done == 0)\n-\t\t\t\t\tbreak;\n-\t\t\t\tif (done < 0)\n+\t\t\t\t\tdie(\"early EOF '%s'\", elem->path);\n+\t\t\t\telse if (done < 0)\n \t\t\t\t\tdie(\"read error '%s'\", elem->path);\n \t\t\t\tsz += done;\n \t\t\t}\n-- \n1.5.4.4\n"}]}