Quellcode durchsuchen

Consume request body before flushing the buffer

This is continuation from https://git.eclipse.org/r/#/c/94249/. When an
error happens, we might not read the entire stream. Consume the request
body before we flush the buffer.

Change-Id: Ia473a04ace600653b2d1f2822e3023570d992410
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
tags/v4.9.0.201710071750-r
Masaya Suzuki vor 6 Jahren
Ursprung
Commit
9fb6561e7a
1 geänderte Dateien mit 17 neuen und 12 gelöschten Zeilen
  1. 17
    12
      org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java

+ 17
- 12
org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java Datei anzeigen

} }


private void service() throws IOException { 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 // If it's a non-bidi request, we need to read the entire request before
// writing a response. Buffer the response until then. // writing a response. Buffer the response until then.
try { try {
if (!clientShallowCommits.isEmpty()) if (!clientShallowCommits.isEmpty())
walk.assumeShallow(clientShallowCommits); walk.assumeShallow(clientShallowCommits);
sendPack = negotiate(); 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) { } catch (ServiceMayNotContinueException err) {
if (!err.isOutput() && err.getMessage() != null) { if (!err.isOutput() && err.getMessage() != null) {
try { try {
} }
throw err; throw err;
} finally { } finally {
if (!sendPack && !biDirectionalPipe) {
while (0 < rawIn.skip(2048) || 0 <= rawIn.read()) {
// Discard until EOF.
}
}
rawOut.stopBuffering(); rawOut.stopBuffering();
} }


private void sendPack() throws IOException { private void sendPack() throws IOException {
final boolean sideband = options.contains(OPTION_SIDE_BAND) final boolean sideband = options.contains(OPTION_SIDE_BAND)
|| options.contains(OPTION_SIDE_BAND_64K); || 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) { if (sideband) {
try { try {
sendPack(true); sendPack(true);

Laden…
Abbrechen
Speichern