{"thread":{"id":"55578","subject":"pkt-line and LF terminated lines of data","startedAt":"2021-04-28T22:22:29Z","lastAt":"2021-04-29T03:16:25Z","messageCount":4,"participants":["dwh@linuxprogrammer.org","Ævar Arnfjörð Bjarmason","brian m. carlson","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"423217","messageId":"20210428222219.GA982@localhost","threadId":"55578","inReplyTo":null,"subject":"pkt-line and LF terminated lines of data","fromName":"","fromEmail":"dwh@linuxprogrammer.org","sentAt":"2021-04-28T22:22:19Z","receivedAt":"2021-04-28T22:22:29Z","isPatch":false,"sender":{"key":"dwh@linuxprogrammer.org","avatar":null},"body":"I was just reading the Documentation/technical/protocol-common.txt\ndescription of the pkt-line format. One detail that is left out is how a\nreceiver of pkt-line encoded data determines if a line is binary data or\ncontains non-binary data.\n\nThe documentation says:\n\n> A non-binary line SHOULD BE terminated by an LF, which if present MUST\n> be included in the total length. Receivers MUST treat pkt-lines with\n> non-binary data the same whether or not they contain the trailing LF\n> (stripping the LF if present, and not complaining when it is missing).\n\nIt seems like a pkt-line with binary data could easily end with 0x0a\n(LF) and a receiver would strip it off even though that is a legitimate\nbyte in the binary stream. I don't think receivers should be trying to\ndetermine if the pkt-line is binary or non-binary and never strip off\nany 0x0a bytes at the end of a pkt-line.\n\nThe client code that relies on the pkt-line receiver is where the logic\nshould reside that figures out what to do with strings that end with LF.\nThe pkt-line receiver just parses the pkg-line length, reads the correct\nnumber of bytes and passes them along for further processing.\n\nWhat am I missing? What should be added to this documentation that gives\nmore detail on when/why/how a pkt-line would be determined to be\nnon-binary and the LF stripping would occur?\n\nCheers!\nDave\n"},{"id":"423221","messageId":"87bl9yylyg.fsf@evledraar.gmail.com","threadId":"55578","inReplyTo":"20210428222219.GA982@localhost","subject":"Re: pkt-line and LF terminated lines of data","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2021-04-29T00:12:00Z","receivedAt":"2021-04-29T00:27:11Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Wed, Apr 28 2021, dwh@linuxprogrammer.org wrote:\n\n> I was just reading the Documentation/technical/protocol-common.txt\n> description of the pkt-line format. One detail that is left out is how a\n> receiver of pkt-line encoded data determines if a line is binary data or\n> contains non-binary data.\n\nThey don't. The \"is it binary\" is a client convention / awareness of the\nconsumed payload.\n\n> The documentation says:\n>\n>> A non-binary line SHOULD BE terminated by an LF, which if present MUST\n>> be included in the total length. Receivers MUST treat pkt-lines with\n>> non-binary data the same whether or not they contain the trailing LF\n>> (stripping the LF if present, and not complaining when it is missing).\n>\n> It seems like a pkt-line with binary data could easily end with 0x0a\n> (LF) and a receiver would strip it off even though that is a legitimate\n> byte in the binary stream. I don't think receivers should be trying to\n> determine if the pkt-line is binary or non-binary and never strip off\n> any 0x0a bytes at the end of a pkt-line.\n>\n> The client code that relies on the pkt-line receiver is where the logic\n> should reside that figures out what to do with strings that end with LF.\n> The pkt-line receiver just parses the pkg-line length, reads the correct\n> number of bytes and passes them along for further processing.\n>\n> What am I missing? What should be added to this documentation that gives\n> more detail on when/why/how a pkt-line would be determined to be\n> non-binary and the LF stripping would occur?\n\nMy reading of the quoted documentation is that it already matches what\nyou're suggesting it should say.\n\nI.e. it doesn't anything about how binary data is handled, what it does\nsay is that if a client knows that a line is non-binary it should be\ntreating \"foo\" and \"foo\\n\" the same, i.e. being lenient and interpret\nboth as \"foo\".\n\nSee PACKET_READ_CHOMP_NEWLINE in pkt-line.c, and the entirety of the\ncommit that introduced the blurb you're quoting: 1c9b659d983\n(pack-protocol: clarify LF-handling in PKT-LINE(), 2015-09-03).\n\nIf you tweak the pkt-line.c code to do PACKET_READ_CHOMP_NEWLINE\nunconditionally you'll get a lot of test failures, digging into those is\na good starting point to see how the binary v.s. non-binary cases are\nhandled.\n"},{"id":"423228","messageId":"YIoVBmeGMheSi897@camp.crustytoothpaste.net","threadId":"55578","inReplyTo":"87bl9yylyg.fsf@evledraar.gmail.com","subject":"Re: pkt-line and LF terminated lines of data","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2021-04-29T02:08:06Z","receivedAt":"2021-04-29T02:08:45Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2021-04-29 at 00:12:00, Ævar Arnfjörð Bjarmason wrote:\n> \n> On Wed, Apr 28 2021, dwh@linuxprogrammer.org wrote:\n> \n> > I was just reading the Documentation/technical/protocol-common.txt\n> > description of the pkt-line format. One detail that is left out is how a\n> > receiver of pkt-line encoded data determines if a line is binary data or\n> > contains non-binary data.\n> \n> They don't. The \"is it binary\" is a client convention / awareness of the\n> consumed payload.\n\nAs a general rule of thumb, if the pkt-line is a pack or object, it's\nbinary, and otherwise (a ref advertisement, a negotiation, etc.) it's\ntext.  Almost any case where GIT_TRACE_PACKET prints the output is going\nto be text, and almost any case where it does not is going to be binary.\n\nNote that whether something is text or binary is specifically an\nattribute of what part of the protocol is being parsed, not what bytes\nit contains.  For example, a ref advertisement with a ref containing the\nbytes FE and FF is text, despite those not appearing in UTF-8.\n-- \nbrian m. carlson (he/him or they/them)\nHouston, Texas, US\n"},{"id":"423231","messageId":"xmqq1rataigx.fsf@gitster.g","threadId":"55578","inReplyTo":"20210428222219.GA982@localhost","subject":"Re: pkt-line and LF terminated lines of data","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-04-29T03:16:14Z","receivedAt":"2021-04-29T03:16:25Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"dwh@linuxprogrammer.org writes:\n\n> What am I missing? What should be added to this documentation that gives\n> more detail on when/why/how a pkt-line would be determined to be\n> non-binary and the LF stripping would occur?\n\nThere is (unfortunately) none.  What payload each packet carries is\ndetermined by the protocol, so a man-in-the-middle who is observing\na protocol exchange without any knowledge of the protocol that runs\non top of the pkt-line layer by definition would not be able to tell\nwhich packet is binary (as it is unaware of what exchange is made).\n\n"}]}