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

Bug report: null bytes in pre-receive hook output stream drops lines

From
RBRyan Brainard <rbrainard@salesforce.com>
Date
Sep 19, 2024, 15:44 UTC
Message-ID
<CAPzz1g+jhP4oXLFn3XtG29fe5XuKwKJ_CQrSVejX+LOBp_-LUw@mail.gmail.com>

I am reporting an issue where if a pre-receive hook sleeps and then returns null bytes in the output stream, the git client that is pushing will drop those lines intermittently.

## What did you do before the bug happened? (Steps to reproduce your issue)
1. Create a local "server" repo with a pre-receive hook that includes
null bytes in output: mkdir /tmp/server && cd $_ && git init --bare &&
echo -e '#!/usr/bin/env bash\nfor n in {1..3}; do echo -ne "\\x00" &&
echo "-----> Log line #${n}..." && sleep 1; done' > hooks/pre-receive
&& chmod +x hooks/pre-receive
2. Create a local "client" repo: mkdir /tmp/client && cd $_ && git init
3. Push a commit from client to server: git commit -m . --allow-empty
&& git push file:///tmp/server master
## What did you expect to happen? (Expected behavior)

I would expect to see all the lines output to the client. The null bytes should not be printed.

## What happened instead? (Actual behavior)

One or more of the log lines are dropped. Run Step 3 multiple times and it will be a different line(s) each time.

For example:
root@5c7434417f1f:/tmp/client# git commit -m . --allow-empty && git
push file:///tmp/server master
[master b4f02d7] .
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 175 bytes | 175.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
remote: -----> Log line #1...
remote: -----> Log line #3...
To file:///tmp/server
   ae04465..b4f02d7  master -> master
## What's different between what you expected and what actually happened?
I would expect all the lines like this:
root@5c7434417f1f:/tmp/client# git commit -m . --allow-empty && git
push file:///tmp/server master
[master b4f02d7] .
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 175 bytes | 175.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
remote: -----> Log line #1...
remote: -----> Log line #2...
remote: -----> Log line #3...
To file:///tmp/server
   ae04465..b4f02d7  master -> master
## Anything else you want to add:

Tried this on multiple versions of git on both macOS and Ubuntu, including the latest 2.46.1.

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.46.1 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh libcurl: 8.5.0 zlib: 1.3 uname: Linux 6.6.12-linuxkit #1 SMP PREEMPT_DYNAMIC Fri Jan 19 12:50:23 UTC 2024 x86_64 compiler info: gnuc: 13.2 libc info: glibc: 2.39 $SHELL (typically, interactive shell): <unset>

[Enabled Hooks]
Message 1 of 1 in “Bug report: null bytes in pre-receive hook output stream drops lines”
  1. Ryan BrainardSep 19, 2024

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.