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

Re: pkt-line and LF terminated lines of data

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 29, 2021, 00:12 UTC
Message-ID
<87bl9yylyg.fsf@evledraar.gmail.com>
In-Reply-To
<20210428222219.GA982@localhost>
On Wed, Apr 28 2021, dwh@linuxprogrammer.org wrote:
> I was just reading the Documentation/technical/protocol-common.txt
> description of the pkt-line format. One detail that is left out is how a
> receiver of pkt-line encoded data determines if a line is binary data or
> contains non-binary data.

They don't. The "is it binary" is a client convention / awareness of the consumed payload.

Show 21 quoted lines
> The documentation says:
>
>> A non-binary line SHOULD BE terminated by an LF, which if present MUST
>> be included in the total length. Receivers MUST treat pkt-lines with
>> non-binary data the same whether or not they contain the trailing LF
>> (stripping the LF if present, and not complaining when it is missing).
>
> It seems like a pkt-line with binary data could easily end with 0x0a
> (LF) and a receiver would strip it off even though that is a legitimate
> byte in the binary stream. I don't think receivers should be trying to
> determine if the pkt-line is binary or non-binary and never strip off
> any 0x0a bytes at the end of a pkt-line.
>
> The client code that relies on the pkt-line receiver is where the logic
> should reside that figures out what to do with strings that end with LF.
> The pkt-line receiver just parses the pkg-line length, reads the correct
> number of bytes and passes them along for further processing.
>
> What am I missing? What should be added to this documentation that gives
> more detail on when/why/how a pkt-line would be determined to be
> non-binary and the LF stripping would occur?

My reading of the quoted documentation is that it already matches what you're suggesting it should say.

I.e. it doesn't anything about how binary data is handled, what it does say is that if a client knows that a line is non-binary it should be treating "foo" and "foo\n" the same, i.e. being lenient and interpret both as "foo".

See PACKET_READ_CHOMP_NEWLINE in pkt-line.c, and the entirety of the commit that introduced the blurb you're quoting: 1c9b659d983 (pack-protocol: clarify LF-handling in PKT-LINE(), 2015-09-03).

If you tweak the pkt-line.c code to do PACKET_READ_CHOMP_NEWLINE unconditionally you'll get a lot of test failures, digging into those is a good starting point to see how the binary v.s. non-binary cases are handled.

Previous: dwh@linuxprogrammer.orgNext: brian m. carlson
Message 2 of 4 in “pkt-line and LF terminated lines of data”
  1. dwh@linuxprogrammer.orgApr 28, 2021
  2. Ævar Arnfjörð BjarmasonApr 29, 2021
  3. brian m. carlsonApr 29, 2021
  4. Junio C HamanoApr 29, 2021

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.