diff options
author | Jonathan Nieder <jrn@google.com> | 2017-08-25 19:31:05 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2017-08-25 19:31:05 -0400 |
commit | 7e82be66cd3368c5476cc3cf8daa6d64bc54b83c (patch) | |
tree | 5e9ef2941b36a590d42f5ae814b5380de4e9dc1a | |
parent | e8d4f2598bb1750a40e202703bc9fbc481650c3f (diff) | |
parent | 9fb6561e7a669db24e3f0717a64a8cd2fcfb6ba1 (diff) | |
download | jgit-7e82be66cd3368c5476cc3cf8daa6d64bc54b83c.tar.gz jgit-7e82be66cd3368c5476cc3cf8daa6d64bc54b83c.zip |
Merge "Consume request body before flushing the buffer"
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java index 17af0b9838..c3f50a4d1b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java @@ -719,7 +719,7 @@ public class UploadPack { } private void service() throws IOException { - boolean sendPack; + boolean sendPack = false; // If it's a non-bidi request, we need to read the entire request before // writing a response. Buffer the response until then. try { @@ -752,6 +752,17 @@ public class UploadPack { if (!clientShallowCommits.isEmpty()) walk.assumeShallow(clientShallowCommits); sendPack = negotiate(); + if (sendPack && !biDirectionalPipe) { + // Ensure the request was fully consumed. Any remaining input must + // be a protocol error. If we aren't at EOF the implementation is broken. + int eof = rawIn.read(); + if (0 <= eof) { + sendPack = false; + throw new CorruptObjectException(MessageFormat.format( + JGitText.get().expectedEOFReceived, + "\\x" + Integer.toHexString(eof))); //$NON-NLS-1$ + } + } } catch (ServiceMayNotContinueException err) { if (!err.isOutput() && err.getMessage() != null) { try { @@ -778,6 +789,11 @@ public class UploadPack { } throw err; } finally { + if (!sendPack && !biDirectionalPipe) { + while (0 < rawIn.skip(2048) || 0 <= rawIn.read()) { + // Discard until EOF. + } + } rawOut.stopBuffering(); } @@ -1390,17 +1406,6 @@ public class UploadPack { private void sendPack() throws IOException { final boolean sideband = options.contains(OPTION_SIDE_BAND) || options.contains(OPTION_SIDE_BAND_64K); - - if (!biDirectionalPipe) { - // Ensure the request was fully consumed. Any remaining input must - // be a protocol error. If we aren't at EOF the implementation is broken. - int eof = rawIn.read(); - if (0 <= eof) - throw new CorruptObjectException(MessageFormat.format( - JGitText.get().expectedEOFReceived, - "\\x" + Integer.toHexString(eof))); //$NON-NLS-1$ - } - if (sideband) { try { sendPack(true); |