]> source.dussan.org Git - jgit.git/commitdiff
UploadPack: consume delimiter in object-info command 98/199698/7
authorHan-Wen Nienhuys <hanwen@google.com>
Tue, 31 Jan 2023 22:27:27 +0000 (23:27 +0100)
committerHan-Wen NIenhuys <hanwen@google.com>
Thu, 2 Feb 2023 13:47:35 +0000 (08:47 -0500)
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 <empty string>

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

org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/ProtocolV2Parser.java

index 91b45e447bd5f3cab02f696956ed3bb884165927..4ad7fa3149e9735457672e58b894ec7ba032458a 100644 (file)
@@ -2766,7 +2766,9 @@ public class UploadPackTest {
                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);
index c4129ff4d0b6c8816e5e71aa95d92c72be115139..e437f22d02a85085180ebf800051b434ab8ba201 100644 (file)
@@ -281,6 +281,12 @@ final class ProtocolV2Parser {
                        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));