{"thread":{"id":"62144","subject":"Bug report: null bytes in pre-receive hook output stream drops lines","startedAt":"2024-09-19T15:44:21Z","lastAt":"2024-09-19T15:44:21Z","messageCount":1,"participants":["Ryan Brainard"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"503063","messageId":"CAPzz1g+jhP4oXLFn3XtG29fe5XuKwKJ_CQrSVejX+LOBp_-LUw@mail.gmail.com","threadId":"62144","inReplyTo":null,"subject":"Bug report: null bytes in pre-receive hook output stream drops lines","fromName":"Ryan Brainard","fromEmail":"rbrainard@salesforce.com","sentAt":"2024-09-19T15:44:02Z","receivedAt":"2024-09-19T15:44:21Z","isPatch":false,"sender":{"key":"rbrainard@salesforce.com","avatar":null},"body":"I am reporting an issue where if a pre-receive hook sleeps and then\nreturns null bytes in the output stream, the git client that is\npushing will drop those lines intermittently.\n\n## What did you do before the bug happened? (Steps to reproduce your issue)\n\n1. Create a local \"server\" repo with a pre-receive hook that includes\nnull bytes in output: mkdir /tmp/server && cd $_ && git init --bare &&\necho -e '#!/usr/bin/env bash\\nfor n in {1..3}; do echo -ne \"\\\\x00\" &&\necho \"-----> Log line #${n}...\" && sleep 1; done' > hooks/pre-receive\n&& chmod +x hooks/pre-receive\n\n2. Create a local \"client\" repo: mkdir /tmp/client && cd $_ && git init\n\n3. Push a commit from client to server: git commit -m . --allow-empty\n&& git push file:///tmp/server master\n\n## What did you expect to happen? (Expected behavior)\n\nI would expect to see all the lines output to the client. The null\nbytes should not be printed.\n\n## What happened instead? (Actual behavior)\n\nOne or more of the log lines are dropped.  Run Step 3 multiple times\nand it will be a different line(s) each time.\n\nFor example:\n\nroot@5c7434417f1f:/tmp/client# git commit -m . --allow-empty && git\npush file:///tmp/server master\n[master b4f02d7] .\nEnumerating objects: 1, done.\nCounting objects: 100% (1/1), done.\nWriting objects: 100% (1/1), 175 bytes | 175.00 KiB/s, done.\nTotal 1 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)\nremote: -----> Log line #1...\nremote: -----> Log line #3...\nTo file:///tmp/server\n   ae04465..b4f02d7  master -> master\n\n## What's different between what you expected and what actually happened?\n\nI would expect all the lines like this:\n\nroot@5c7434417f1f:/tmp/client# git commit -m . --allow-empty && git\npush file:///tmp/server master\n[master b4f02d7] .\nEnumerating objects: 1, done.\nCounting objects: 100% (1/1), done.\nWriting objects: 100% (1/1), 175 bytes | 175.00 KiB/s, done.\nTotal 1 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)\nremote: -----> Log line #1...\nremote: -----> Log line #2...\nremote: -----> Log line #3...\nTo file:///tmp/server\n   ae04465..b4f02d7  master -> master\n\n## Anything else you want to add:\n\nTried this on multiple versions of git on both macOS and Ubuntu,\nincluding the latest 2.46.1.\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n[System Info]\ngit version:\ngit version 2.46.1\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nlibcurl: 8.5.0\nzlib: 1.3\nuname: Linux 6.6.12-linuxkit #1 SMP PREEMPT_DYNAMIC Fri Jan 19\n12:50:23 UTC 2024 x86_64\ncompiler info: gnuc: 13.2\nlibc info: glibc: 2.39\n$SHELL (typically, interactive shell): <unset>\n\n\n[Enabled Hooks]\n"}]}