Program: 85872
Project: 85872
Buggy source:
/** 
 * This is required for signatures which use a sigHashType which cannot be represented using SigHash and anyoneCanPay See transaction c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73, which has sigHashType 0
 */
synchronized Sha256Hash hashTransactionForSignature(int inputIndex,byte[] connectedScript,byte sigHashType) throws ScriptException {
  try {
    byte[][] inputScripts=new byte[inputs.size()][];
    long[] inputSequenceNumbers=new long[inputs.size()];
    for (int i=0; i < inputs.size(); i++) {
      inputScripts[i]=inputs.get(i).getScriptBytes();
      inputSequenceNumbers[i]=inputs.get(i).getSequenceNumber();
      inputs.get(i).setScriptBytes(TransactionInput.EMPTY_ARRAY);
    }
    connectedScript=Script.removeAllInstancesOfOp(connectedScript,Script.OP_CODESEPARATOR);
    TransactionInput input=inputs.get(inputIndex);
    input.setScriptBytes(connectedScript);
    ArrayList<TransactionOutput> outputs=this.outputs;
    if ((sigHashType & 0x1f) == (SigHash.NONE.ordinal() + 1)) {
      this.outputs=new ArrayList<TransactionOutput>(0);
      for (int i=0; i < inputs.size(); i++)       if (i != inputIndex)       inputs.get(i).setSequenceNumber(0);
    }
 else     if ((sigHashType & 0x1f) == (SigHash.SINGLE.ordinal() + 1)) {
      if (inputIndex >= this.outputs.size()) {
        for (int i=0; i < inputs.size(); i++) {
          inputs.get(i).setScriptBytes(inputScripts[i]);
          inputs.get(i).setSequenceNumber(inputSequenceNumbers[i]);
        }
        this.outputs=outputs;
        return new Sha256Hash("String_Node_Str");
      }
      this.outputs=new ArrayList<TransactionOutput>(this.outputs.subList(0,inputIndex));
      for (int i=0; i < inputIndex; i++)       this.outputs.set(i,new TransactionOutput(params,this,BigInteger.valueOf(-1),new byte[]{}));
      for (int i=0; i < inputs.size(); i++)       if (i != inputIndex)       inputs.get(i).setSequenceNumber(0);
    }
    ArrayList<TransactionInput> inputs=this.inputs;
    if ((sigHashType & 0x80) == 0x80) {
      this.inputs=new ArrayList<TransactionInput>();
      this.inputs.add(input);
    }
    ByteArrayOutputStream bos=new UnsafeByteArrayOutputStream(length == UNKNOWN_LENGTH ? 256 : length + 4);
    bitcoinSerialize(bos);
    uint32ToByteStreamLE(0x000000ff & sigHashType,bos);
    Sha256Hash hash=new Sha256Hash(doubleDigest(bos.toByteArray()));
    bos.close();
    this.inputs=inputs;
    for (int i=0; i < inputs.size(); i++) {
      inputs.get(i).setScriptBytes(inputScripts[i]);
      inputs.get(i).setSequenceNumber(inputSequenceNumbers[i]);
    }
    this.outputs=outputs;
    return hash;
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
/** 
 * This is required for signatures which use a sigHashType which cannot be represented using SigHash and anyoneCanPay See transaction c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73, which has sigHashType 0
 */
synchronized Sha256Hash hashTransactionForSignature(int inputIndex,byte[] connectedScript,byte sigHashType) throws ScriptException {
  try {
    byte[][] inputScripts=new byte[inputs.size()][];
    long[] inputSequenceNumbers=new long[inputs.size()];
    for (int i=0; i < inputs.size(); i++) {
      inputScripts[i]=inputs.get(i).getScriptBytes();
      inputSequenceNumbers[i]=inputs.get(i).getSequenceNumber();
      inputs.get(i).setScriptBytes(TransactionInput.EMPTY_ARRAY);
    }
    connectedScript=Script.removeAllInstancesOfOp(connectedScript,Script.OP_CODESEPARATOR);
    TransactionInput input=inputs.get(inputIndex);
    input.setScriptBytes(connectedScript);
    ArrayList<TransactionOutput> outputs=this.outputs;
    if ((sigHashType & 0x1f) == (SigHash.NONE.ordinal() + 1)) {
      this.outputs=new ArrayList<TransactionOutput>(0);
      for (int i=0; i < inputs.size(); i++)       if (i != inputIndex)       inputs.get(i).setSequenceNumber(0);
    }
 else     if ((sigHashType & 0x1f) == (SigHash.SINGLE.ordinal() + 1)) {
      if (inputIndex >= this.outputs.size()) {
        for (int i=0; i < inputs.size(); i++) {
          inputs.get(i).setScriptBytes(inputScripts[i]);
          inputs.get(i).setSequenceNumber(inputSequenceNumbers[i]);
        }
        this.outputs=outputs;
        return new Sha256Hash("String_Node_Str");
      }
      this.outputs=new ArrayList<TransactionOutput>(this.outputs.subList(0,inputIndex + 1));
      for (int i=0; i < inputIndex; i++)       this.outputs.set(i,new TransactionOutput(params,this,BigInteger.valueOf(-1),new byte[]{}));
      for (int i=0; i < inputs.size(); i++)       if (i != inputIndex)       inputs.get(i).setSequenceNumber(0);
    }
    ArrayList<TransactionInput> inputs=this.inputs;
    if ((sigHashType & 0x80) == 0x80) {
      this.inputs=new ArrayList<TransactionInput>();
      this.inputs.add(input);
    }
    ByteArrayOutputStream bos=new UnsafeByteArrayOutputStream(length == UNKNOWN_LENGTH ? 256 : length + 4);
    bitcoinSerialize(bos);
    uint32ToByteStreamLE(0x000000ff & sigHashType,bos);
    Sha256Hash hash=new Sha256Hash(doubleDigest(bos.toByteArray()));
    bos.close();
    this.inputs=inputs;
    for (int i=0; i < inputs.size(); i++) {
      inputs.get(i).setScriptBytes(inputScripts[i]);
      inputs.get(i).setSequenceNumber(inputSequenceNumbers[i]);
    }
    this.outputs=outputs;
    return hash;
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}