Browse Source

Fix bad test fix from 0bff481 "Limit receive commands"

In 0bff481d45 to accurately use the two
limits it was necessary to move the LimitedInputStream out of the
PacketLineIn and further down to the PackParser. Unfortuantely this
didn't survive review, as a buggy test failed and the "fix" was to
drop this part of the code.

The maxPackSizeLimit should apply to the pack stream, not the pkt-line
framing used to send commands to control the ReceivePack instance. The
commands are controlled using a different limit. The failing test allowed
too many bytes in the pack and was only failing because it was including
the command framing. The correct fix for the test was simply to drop the
limit lower, to more closely match the actual pack size.

Change-Id: I47d3885b9d7d527e153df7ac9c62fc2865ceecf4
stable-4.7
Shawn Pearce 8 years ago
parent
commit
07fdc50c07
  1. 2
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/GitServletResponseTests.java
  2. 23
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java

2
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/GitServletResponseTests.java

@ -269,7 +269,7 @@ public class GitServletResponseTests extends HttpTestCase {
Transport t; Transport t;
// this maxPackSize leads to an unPackError // this maxPackSize leads to an unPackError
maxPackSize = 400; maxPackSize = 100;
// this PostReceiveHook when called after an unsuccesfull unpack will // this PostReceiveHook when called after an unsuccesfull unpack will
// lead to an IllegalStateException // lead to an IllegalStateException
postHook = new PostReceiveHook() { postHook = new PostReceiveHook() {

23
org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java

@ -1058,14 +1058,6 @@ public abstract class BaseReceivePack {
rawOut = o; rawOut = o;
} }
if (maxPackSizeLimit >= 0)
rawIn = new LimitedInputStream(rawIn, maxPackSizeLimit) {
@Override
protected void limitExceeded() throws TooLargePackException {
throw new TooLargePackException(limit);
}
};
pckIn = new PacketLineIn(rawIn); pckIn = new PacketLineIn(rawIn);
pckOut = new PacketLineOut(rawOut); pckOut = new PacketLineOut(rawOut);
pckOut.setFlushOnEnd(false); pckOut.setFlushOnEnd(false);
@ -1369,7 +1361,7 @@ public abstract class BaseReceivePack {
if (getRefLogIdent() != null) if (getRefLogIdent() != null)
lockMsg += " from " + getRefLogIdent().toExternalString(); //$NON-NLS-1$ lockMsg += " from " + getRefLogIdent().toExternalString(); //$NON-NLS-1$
parser = ins.newPackParser(rawIn); parser = ins.newPackParser(packInputStream());
parser.setAllowThin(true); parser.setAllowThin(true);
parser.setNeedNewObjectIds(checkReferencedIsReachable); parser.setNeedNewObjectIds(checkReferencedIsReachable);
parser.setNeedBaseObjectIds(checkReferencedIsReachable); parser.setNeedBaseObjectIds(checkReferencedIsReachable);
@ -1389,6 +1381,19 @@ public abstract class BaseReceivePack {
timeoutIn.setTimeout(timeout * 1000); timeoutIn.setTimeout(timeout * 1000);
} }
private InputStream packInputStream() {
InputStream packIn = rawIn;
if (maxPackSizeLimit >= 0) {
packIn = new LimitedInputStream(packIn, maxPackSizeLimit) {
@Override
protected void limitExceeded() throws TooLargePackException {
throw new TooLargePackException(limit);
}
};
}
return packIn;
}
private boolean needCheckConnectivity() { private boolean needCheckConnectivity() {
return isCheckReceivedObjects() return isCheckReceivedObjects()
|| isCheckReferencedObjectsAreReachable() || isCheckReferencedObjectsAreReachable()

Loading…
Cancel
Save