From 341116103e0eab7b8464a74affadf940652669b1 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 31 Jan 2023 23:27:27 +0100 Subject: [PATCH] UploadPack: consume delimiter in object-info command The 'size' packet line is an argument, so it must be preceeded by a 0001 delimiter. See also git's t5701-git-serve.sh test, https://github.com/git/git/blob/8b8d9a2/t/t5701-git-serve.sh#L329 Without this fix, the server will choke on the delimiter line, saying PackProtocolException: unexpected To test, I ran Gerrit locally with this fix $ curl -X POST -H 'git-protocol: version=2' -H 'content-type: application/x-git-upload-pack-request' -H 'accept: application/x-git-upload-pack-result' --data $'0018command=object-info\n00010009size\n0031oid d38b1b92bdb2893eb4505667375563f2d6d4086b\n0000' http://localhost:8080/git.git/git-upload-pack => 0008size0032d38b1b92bdb2893eb4505667375563f2d6d4086b 268590000 The same command completes identically on Gitlab (which supports the object-info command) $ curl -X POST -H 'git-protocol: version=2' -H 'content-type: application/x-git-upload-pack-request' -H 'accept: application/x-git-upload-pack-result' --data $'0018command=object-info\n00010009size\n0031oid d38b1b92bdb2893eb4505667375563f2d6d4086b\n0000' https://gitlab.com/gitlab-org/git.git/git-upload-pack => 0008size0032d38b1b92bdb2893eb4505667375563f2d6d4086b 268590000 In this case, the blob is for the COPYING file in the Git source tree, which is 26859 bytes long. Change-Id: Ief4ce1eb9303a3b2479547d7950ef01c7c28f472 --- .../tst/org/eclipse/jgit/transport/UploadPackTest.java | 4 +++- .../src/org/eclipse/jgit/transport/ProtocolV2Parser.java | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 91b45e447..4ad7fa314 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -2766,7 +2766,9 @@ public void testObjectInfo() throws Exception { TestV2Hook hook = new TestV2Hook(); ByteArrayInputStream recvStream = uploadPackV2((UploadPack up) -> { up.setProtocolV2Hook(hook); - }, "command=object-info\n", "size", + }, "command=object-info\n", + PacketLineIn.delimiter(), + "size", "oid " + ObjectId.toString(blob1.getId()), "oid " + ObjectId.toString(blob2.getId()), PacketLineIn.end()); PacketLineIn pckIn = new PacketLineIn(recvStream); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java index c4129ff4d..e437f22d0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java @@ -281,6 +281,12 @@ ObjectInfoRequest parseObjectInfoRequest(PacketLineIn pckIn) return builder.build(); } + if (!PacketLineIn.isDelimiter(line)) { + throw new PackProtocolException(MessageFormat + .format(JGitText.get().unexpectedPacketLine, line)); + } + + line = pckIn.readString(); if (!line.equals("size")) { //$NON-NLS-1$ throw new PackProtocolException(MessageFormat .format(JGitText.get().unexpectedPacketLine, line));