Program: 34233
Project: 34233
Buggy source:
/** 
 * Constructs the payload necessary to sign or verify the signature of a PubKey
 * @param pubkey - The PubKey object that we wish to sign or verify the signature of
 * @return A byte[] containing the constructed payload. 
 */
public byte[] createPubkeySignaturePayload(Pubkey pubkey){
  byte[] payload=null;
  ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
  try {
    if (pubkey.getObjectVersion() < 4) {
      outputStream.write(ByteUtils.intToBytes((int)pubkey.getExpirationTime()));
    }
 else {
      outputStream.write(ByteUtils.longToBytes(pubkey.getExpirationTime()));
    }
    outputStream.write(ByteUtils.intToBytes(pubkey.getObjectType()));
    outputStream.write(VarintEncoder.encode(pubkey.getObjectVersion()));
    outputStream.write(VarintEncoder.encode(pubkey.getStreamNumber()));
    if (pubkey.getObjectVersion() >= 4) {
      String addressString=new AddressGenerator().recreateAddressString(pubkey.getObjectVersion(),pubkey.getStreamNumber(),pubkey.getPublicSigningKey(),pubkey.getPublicEncryptionKey());
      outputStream.write(new AddressProcessor().calculateAddressTag(addressString));
    }
    outputStream.write(ByteUtils.intToBytes(pubkey.getBehaviourBitfield()));
    byte[] publicSigningKey=pubkey.getPublicSigningKey();
    if (publicSigningKey[0] == (byte)4 && publicSigningKey.length == 65) {
      publicSigningKey=ArrayCopier.copyOfRange(publicSigningKey,1,publicSigningKey.length);
    }
    outputStream.write(publicSigningKey);
    byte[] publicEncryptionKey=pubkey.getPublicEncryptionKey();
    if (publicEncryptionKey[0] == (byte)4 && publicEncryptionKey.length == 65) {
      publicEncryptionKey=ArrayCopier.copyOfRange(publicEncryptionKey,1,publicEncryptionKey.length);
    }
    outputStream.write(publicEncryptionKey);
    outputStream.write(VarintEncoder.encode(pubkey.getNonceTrialsPerByte()));
    outputStream.write(VarintEncoder.encode(pubkey.getExtraBytes()));
    payload=outputStream.toByteArray();
  }
 catch (  IOException e) {
    throw new RuntimeException("String_Node_Str",e);
  }
  return payload;
}

Fixed version (ground truth):
/** 
 * Constructs the payload necessary to sign or verify the signature of a PubKey
 * @param pubkey - The PubKey object that we wish to sign or verify the signature of
 * @return A byte[] containing the constructed payload. 
 */
public byte[] createPubkeySignaturePayload(Pubkey pubkey){
  byte[] payload=null;
  ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
  try {
    outputStream.write(ByteUtils.longToBytes(pubkey.getExpirationTime()));
    outputStream.write(ByteUtils.intToBytes(pubkey.getObjectType()));
    outputStream.write(VarintEncoder.encode(pubkey.getObjectVersion()));
    outputStream.write(VarintEncoder.encode(pubkey.getStreamNumber()));
    if (pubkey.getObjectVersion() >= 4) {
      String addressString=new AddressGenerator().recreateAddressString(pubkey.getObjectVersion(),pubkey.getStreamNumber(),pubkey.getPublicSigningKey(),pubkey.getPublicEncryptionKey());
      outputStream.write(new AddressProcessor().calculateAddressTag(addressString));
    }
    outputStream.write(ByteUtils.intToBytes(pubkey.getBehaviourBitfield()));
    byte[] publicSigningKey=pubkey.getPublicSigningKey();
    if (publicSigningKey[0] == (byte)4 && publicSigningKey.length == 65) {
      publicSigningKey=ArrayCopier.copyOfRange(publicSigningKey,1,publicSigningKey.length);
    }
    outputStream.write(publicSigningKey);
    byte[] publicEncryptionKey=pubkey.getPublicEncryptionKey();
    if (publicEncryptionKey[0] == (byte)4 && publicEncryptionKey.length == 65) {
      publicEncryptionKey=ArrayCopier.copyOfRange(publicEncryptionKey,1,publicEncryptionKey.length);
    }
    outputStream.write(publicEncryptionKey);
    outputStream.write(VarintEncoder.encode(pubkey.getNonceTrialsPerByte()));
    outputStream.write(VarintEncoder.encode(pubkey.getExtraBytes()));
    payload=outputStream.toByteArray();
  }
 catch (  IOException e) {
    throw new RuntimeException("String_Node_Str",e);
  }
  return payload;
}