Program: 8411
Project: 8411
Buggy source:
public static void encrypt(Context context,InputData data,OutputStream outStream,boolean armored,long encryptionKeyIds[],long signatureKeyId,String signaturePassPhrase,ProgressDialogUpdater progress,int symmetricAlgorithm,int hashAlgorithm,int compression,boolean forceV3Signature,String passPhrase) throws IOException, GeneralException, PGPException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException {
  if (encryptionKeyIds == null) {
    encryptionKeyIds=new long[0];
  }
  ArmoredOutputStream armorOut=null;
  OutputStream out=null;
  OutputStream encryptOut=null;
  if (armored) {
    armorOut=new ArmoredOutputStream(outStream);
    armorOut.setHeader("String_Node_Str",getFullVersion(context));
    out=armorOut;
  }
 else {
    out=outStream;
  }
  PGPSecretKey signingKey=null;
  PGPSecretKeyRing signingKeyRing=null;
  PGPPrivateKey signaturePrivateKey=null;
  if (encryptionKeyIds.length == 0 && passPhrase == null) {
    throw new GeneralException(context.getString(R.string.error_noEncryptionKeysOrPassPhrase));
  }
  if (signatureKeyId != Id.key.none) {
    signingKeyRing=getSecretKeyRing(signatureKeyId);
    signingKey=PGPHelper.getSigningKey(signatureKeyId);
    if (signingKey == null) {
      throw new GeneralException(context.getString(R.string.error_signatureFailed));
    }
    if (signaturePassPhrase == null) {
      throw new GeneralException(context.getString(R.string.error_noSignaturePassPhrase));
    }
    if (progress != null)     progress.setProgress(R.string.progress_extractingSignatureKey,0,100);
    PBESecretKeyDecryptor keyDecryptor=new JcePBESecretKeyDecryptorBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(signaturePassPhrase.toCharArray());
    signaturePrivateKey=signingKey.extractPrivateKey(keyDecryptor);
    if (signaturePrivateKey == null) {
      throw new GeneralException(context.getString(R.string.error_couldNotExtractPrivateKey));
    }
  }
  if (progress != null)   progress.setProgress(R.string.progress_preparingStreams,5,100);
  JcePGPDataEncryptorBuilder encryptorBuilder=new JcePGPDataEncryptorBuilder(symmetricAlgorithm).setProvider(BOUNCY_CASTLE_PROVIDER_NAME).setWithIntegrityPacket(true);
  PGPEncryptedDataGenerator cPk=new PGPEncryptedDataGenerator(encryptorBuilder);
  if (encryptionKeyIds.length == 0) {
    Log.d(Constants.TAG,"String_Node_Str");
    JcePBEKeyEncryptionMethodGenerator symmetricEncryptionGenerator=new JcePBEKeyEncryptionMethodGenerator(passPhrase.toCharArray());
    cPk.addMethod(symmetricEncryptionGenerator);
  }
  for (int i=0; i < encryptionKeyIds.length; ++i) {
    PGPPublicKey key=PGPHelper.getEncryptPublicKey(encryptionKeyIds[i]);
    if (key != null) {
      JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator=new JcePublicKeyKeyEncryptionMethodGenerator(key);
      cPk.addMethod(pubKeyEncryptionGenerator);
    }
  }
  encryptOut=cPk.open(out,new byte[1 << 16]);
  PGPSignatureGenerator signatureGenerator=null;
  PGPV3SignatureGenerator signatureV3Generator=null;
  if (signatureKeyId != Id.key.none) {
    if (progress != null)     progress.setProgress(R.string.progress_preparingSignature,10,100);
    JcaPGPContentSignerBuilder contentSignerBuilder=new JcaPGPContentSignerBuilder(signingKey.getPublicKey().getAlgorithm(),hashAlgorithm).setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
    if (forceV3Signature) {
      signatureV3Generator=new PGPV3SignatureGenerator(contentSignerBuilder);
      signatureV3Generator.init(PGPSignature.BINARY_DOCUMENT,signaturePrivateKey);
    }
 else {
      signatureGenerator=new PGPSignatureGenerator(contentSignerBuilder);
      signatureGenerator.init(PGPSignature.BINARY_DOCUMENT,signaturePrivateKey);
      String userId=PGPHelper.getMainUserId(PGPHelper.getMasterKey(signingKeyRing));
      PGPSignatureSubpacketGenerator spGen=new PGPSignatureSubpacketGenerator();
      spGen.setSignerUserID(false,userId);
      signatureGenerator.setHashedSubpackets(spGen.generate());
    }
  }
  PGPCompressedDataGenerator compressGen=null;
  BCPGOutputStream bcpgOut=null;
  if (compression == Id.choice.compression.none) {
    bcpgOut=new BCPGOutputStream(encryptOut);
  }
 else {
    compressGen=new PGPCompressedDataGenerator(compression);
    bcpgOut=new BCPGOutputStream(compressGen.open(encryptOut));
  }
  if (signatureKeyId != Id.key.none) {
    if (forceV3Signature) {
      signatureV3Generator.generateOnePassVersion(false).encode(bcpgOut);
    }
 else {
      signatureGenerator.generateOnePassVersion(false).encode(bcpgOut);
    }
  }
  PGPLiteralDataGenerator literalGen=new PGPLiteralDataGenerator();
  OutputStream pOut=literalGen.open(bcpgOut,PGPLiteralData.BINARY,"String_Node_Str",new Date(),new byte[1 << 16]);
  if (progress != null)   progress.setProgress(R.string.progress_encrypting,20,100);
  long done=0;
  int n=0;
  byte[] buffer=new byte[1 << 16];
  InputStream in=data.getInputStream();
  while ((n=in.read(buffer)) > 0) {
    pOut.write(buffer,0,n);
    if (signatureKeyId != Id.key.none) {
      if (forceV3Signature) {
        signatureV3Generator.update(buffer,0,n);
      }
 else {
        signatureGenerator.update(buffer,0,n);
      }
    }
    done+=n;
    if (data.getSize() != 0) {
      if (progress != null)       progress.setProgress((int)(20 + (95 - 20) * done / data.getSize()),100);
    }
  }
  literalGen.close();
  if (signatureKeyId != Id.key.none) {
    if (progress != null)     progress.setProgress(R.string.progress_generatingSignature,95,100);
    if (forceV3Signature) {
      signatureV3Generator.generate().encode(pOut);
    }
 else {
      signatureGenerator.generate().encode(pOut);
    }
  }
  if (compressGen != null) {
    compressGen.close();
  }
  encryptOut.close();
  if (armored) {
    armorOut.close();
  }
  if (progress != null)   progress.setProgress(R.string.progress_done,100,100);
}

Fixed version (ground truth):
public static void encrypt(Context context,InputData data,OutputStream outStream,boolean armored,long encryptionKeyIds[],long signatureKeyId,String signaturePassPhrase,ProgressDialogUpdater progress,int symmetricAlgorithm,int hashAlgorithm,int compression,boolean forceV3Signature,String passPhrase) throws IOException, GeneralException, PGPException, NoSuchProviderException, NoSuchAlgorithmException, SignatureException {
  if (encryptionKeyIds == null) {
    encryptionKeyIds=new long[0];
  }
  ArmoredOutputStream armorOut=null;
  OutputStream out=null;
  OutputStream encryptOut=null;
  if (armored) {
    armorOut=new ArmoredOutputStream(outStream);
    armorOut.setHeader("String_Node_Str",getFullVersion(context));
    out=armorOut;
  }
 else {
    out=outStream;
  }
  PGPSecretKey signingKey=null;
  PGPSecretKeyRing signingKeyRing=null;
  PGPPrivateKey signaturePrivateKey=null;
  if (encryptionKeyIds.length == 0 && passPhrase == null) {
    throw new GeneralException(context.getString(R.string.error_noEncryptionKeysOrPassPhrase));
  }
  if (signatureKeyId != Id.key.none) {
    signingKeyRing=getSecretKeyRing(signatureKeyId);
    signingKey=PGPHelper.getSigningKey(signatureKeyId);
    if (signingKey == null) {
      throw new GeneralException(context.getString(R.string.error_signatureFailed));
    }
    if (signaturePassPhrase == null) {
      throw new GeneralException(context.getString(R.string.error_noSignaturePassPhrase));
    }
    if (progress != null)     progress.setProgress(R.string.progress_extractingSignatureKey,0,100);
    PBESecretKeyDecryptor keyDecryptor=new JcePBESecretKeyDecryptorBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(signaturePassPhrase.toCharArray());
    signaturePrivateKey=signingKey.extractPrivateKey(keyDecryptor);
    if (signaturePrivateKey == null) {
      throw new GeneralException(context.getString(R.string.error_couldNotExtractPrivateKey));
    }
  }
  updateProgress(progress,R.string.progress_preparingStreams,5,100);
  JcePGPDataEncryptorBuilder encryptorBuilder=new JcePGPDataEncryptorBuilder(symmetricAlgorithm).setProvider(BOUNCY_CASTLE_PROVIDER_NAME).setWithIntegrityPacket(true);
  PGPEncryptedDataGenerator cPk=new PGPEncryptedDataGenerator(encryptorBuilder);
  if (encryptionKeyIds.length == 0) {
    Log.d(Constants.TAG,"String_Node_Str");
    JcePBEKeyEncryptionMethodGenerator symmetricEncryptionGenerator=new JcePBEKeyEncryptionMethodGenerator(passPhrase.toCharArray());
    cPk.addMethod(symmetricEncryptionGenerator);
  }
  for (int i=0; i < encryptionKeyIds.length; ++i) {
    PGPPublicKey key=PGPHelper.getEncryptPublicKey(encryptionKeyIds[i]);
    if (key != null) {
      JcePublicKeyKeyEncryptionMethodGenerator pubKeyEncryptionGenerator=new JcePublicKeyKeyEncryptionMethodGenerator(key);
      cPk.addMethod(pubKeyEncryptionGenerator);
    }
  }
  encryptOut=cPk.open(out,new byte[1 << 16]);
  PGPSignatureGenerator signatureGenerator=null;
  PGPV3SignatureGenerator signatureV3Generator=null;
  if (signatureKeyId != Id.key.none) {
    if (progress != null)     progress.setProgress(R.string.progress_preparingSignature,10,100);
    JcaPGPContentSignerBuilder contentSignerBuilder=new JcaPGPContentSignerBuilder(signingKey.getPublicKey().getAlgorithm(),hashAlgorithm).setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
    if (forceV3Signature) {
      signatureV3Generator=new PGPV3SignatureGenerator(contentSignerBuilder);
      signatureV3Generator.init(PGPSignature.BINARY_DOCUMENT,signaturePrivateKey);
    }
 else {
      signatureGenerator=new PGPSignatureGenerator(contentSignerBuilder);
      signatureGenerator.init(PGPSignature.BINARY_DOCUMENT,signaturePrivateKey);
      String userId=PGPHelper.getMainUserId(PGPHelper.getMasterKey(signingKeyRing));
      PGPSignatureSubpacketGenerator spGen=new PGPSignatureSubpacketGenerator();
      spGen.setSignerUserID(false,userId);
      signatureGenerator.setHashedSubpackets(spGen.generate());
    }
  }
  PGPCompressedDataGenerator compressGen=null;
  BCPGOutputStream bcpgOut=null;
  if (compression == Id.choice.compression.none) {
    bcpgOut=new BCPGOutputStream(encryptOut);
  }
 else {
    compressGen=new PGPCompressedDataGenerator(compression);
    bcpgOut=new BCPGOutputStream(compressGen.open(encryptOut));
  }
  if (signatureKeyId != Id.key.none) {
    if (forceV3Signature) {
      signatureV3Generator.generateOnePassVersion(false).encode(bcpgOut);
    }
 else {
      signatureGenerator.generateOnePassVersion(false).encode(bcpgOut);
    }
  }
  PGPLiteralDataGenerator literalGen=new PGPLiteralDataGenerator();
  OutputStream pOut=literalGen.open(bcpgOut,PGPLiteralData.BINARY,"String_Node_Str",new Date(),new byte[1 << 16]);
  updateProgress(progress,R.string.progress_encrypting,20,100);
  long done=0;
  int n=0;
  byte[] buffer=new byte[1 << 16];
  InputStream in=data.getInputStream();
  while ((n=in.read(buffer)) > 0) {
    pOut.write(buffer,0,n);
    if (signatureKeyId != Id.key.none) {
      if (forceV3Signature) {
        signatureV3Generator.update(buffer,0,n);
      }
 else {
        signatureGenerator.update(buffer,0,n);
      }
    }
    done+=n;
    if (data.getSize() != 0) {
      updateProgress(progress,(int)(20 + (95 - 20) * done / data.getSize()),100);
    }
  }
  literalGen.close();
  if (signatureKeyId != Id.key.none) {
    updateProgress(progress,R.string.progress_generatingSignature,95,100);
    if (forceV3Signature) {
      signatureV3Generator.generate().encode(pOut);
    }
 else {
      signatureGenerator.generate().encode(pOut);
    }
  }
  if (compressGen != null) {
    compressGen.close();
  }
  encryptOut.close();
  if (armored) {
    armorOut.close();
  }
  updateProgress(progress,R.string.progress_done,100,100);
}