{"thread":{"id":"38211","subject":"[PATCH] Bad file descriptor on filtering empty files","startedAt":"2014-12-19T22:41:58Z","lastAt":"2014-12-22T18:26:47Z","messageCount":2,"participants":["William Throwe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"253874","messageId":"87sigbmfd5.fsf@cornell.edu","threadId":"38211","inReplyTo":null,"subject":"[PATCH] Bad file descriptor on filtering empty files","fromName":"William Throwe","fromEmail":"wtt6@cornell.edu","sentAt":"2014-12-19T22:41:58Z","receivedAt":"2014-12-19T22:41:58Z","isPatch":true,"sender":{"key":"wtt6@cornell.edu","avatar":null},"body":"In git 2.2.0 (also tested on 2.2.0.65.g9abc44b), if an external\nsmudge/clean filter is called on an empty file git reports something\nlike:\nerror: copy-fd: read returned Bad file descriptor\nerror: cannot feed the input to external filter cat\nerror: external filter cat failed\n\nTest case:\n\nmkdir bug\ncd bug\ngit init\ngit config filter.cat.clean cat\ngit config filter.cat.smudge cat\necho '* filter=cat' >.gitattributes\ntouch a\ngit add a\n\n\nThis started in 9035d75a2be9d80d82676504d69553245017f6d4, which\nintroduced the possible call to copy_fd in code called from\napply_filter.  It appears that NULL as the src argument to apply_filter\nis being used both as a sentinel value to indicate that the fd should be\nused instead and also as a representation of the contents of an empty\nfile.  I suggest switching to using fd == -1 as the sentinel as shown in\nthe patch below.\n\nThanks,\nWill\n\n\ndiff --git a/convert.c b/convert.c\nindex 9a5612e..0509ac1 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -355,7 +355,7 @@ static int filter_buffer_or_fd(int in, int out, void *data)\n \n \tsigchain_push(SIGPIPE, SIG_IGN);\n \n-\tif (params->src) {\n+\tif (params->fd == -1) {\n \t\twrite_err = (write_in_full(child_process.in, params->src, params->size) < 0);\n \t} else {\n \t\twrite_err = copy_fd(params->fd, child_process.in);\n"},{"id":"253939","messageId":"xmqq7fxja6c8.fsf@gitster.dls.corp.google.com","threadId":"38211","inReplyTo":"87sigbmfd5.fsf@cornell.edu","subject":"Re: [PATCH] Bad file descriptor on filtering empty files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-12-22T18:26:47Z","receivedAt":"2014-12-22T18:26:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"William Throwe <wtt6@cornell.edu> writes:\n\n> In git 2.2.0 (also tested on 2.2.0.65.g9abc44b), if an external\n> smudge/clean filter is called on an empty file git reports something\n> like:\n> error: copy-fd: read returned Bad file descriptor\n> error: cannot feed the input to external filter cat\n> error: external filter cat failed\n>\n> Test case:\n>\n> mkdir bug\n> cd bug\n> git init\n> git config filter.cat.clean cat\n> git config filter.cat.smudge cat\n> echo '* filter=cat' >.gitattributes\n> touch a\n> git add a\n>\n>\n> This started in 9035d75a2be9d80d82676504d69553245017f6d4, which\n> introduced the possible call to copy_fd in code called from\n> apply_filter.  It appears that NULL as the src argument to apply_filter\n> is being used both as a sentinel value to indicate that the fd should be\n> used instead and also as a representation of the contents of an empty\n> file.  I suggest switching to using fd == -1 as the sentinel as shown in\n> the patch below.\n>\n> Thanks,\n> Will\n>\n\nWilliam, thanks for raising this issue.\n\nSteffen, comments?\n\n> diff --git a/convert.c b/convert.c\n> index 9a5612e..0509ac1 100644\n> --- a/convert.c\n> +++ b/convert.c\n> @@ -355,7 +355,7 @@ static int filter_buffer_or_fd(int in, int out, void *data)\n>  \n>  \tsigchain_push(SIGPIPE, SIG_IGN);\n>  \n> -\tif (params->src) {\n> +\tif (params->fd == -1) {\n>  \t\twrite_err = (write_in_full(child_process.in, params->src, params->size) < 0);\n>  \t} else {\n>  \t\twrite_err = copy_fd(params->fd, child_process.in);\n"}]}