Program: 8416
Project: 8416
Buggy source:
public static Bundle decrypt(Context context,InputData data,OutputStream outStream,String passPhrase,ProgressDialogUpdater progress,boolean assumeSymmetric) throws IOException, GeneralException, PGPException, SignatureException {
  if (passPhrase == null) {
    passPhrase="String_Node_Str";
  }
  Bundle returnData=new Bundle();
  InputStream in=PGPUtil.getDecoderStream(data.getInputStream());
  PGPObjectFactory pgpF=new PGPObjectFactory(in);
  PGPEncryptedDataList enc;
  Object o=pgpF.nextObject();
  long signatureKeyId=0;
  int currentProgress=0;
  if (progress != null)   progress.setProgress(R.string.progress_readingData,currentProgress,100);
  if (o instanceof PGPEncryptedDataList) {
    enc=(PGPEncryptedDataList)o;
  }
 else {
    enc=(PGPEncryptedDataList)pgpF.nextObject();
  }
  if (enc == null) {
    throw new GeneralException(context.getString(R.string.error_invalidData));
  }
  InputStream clear=null;
  PGPEncryptedData encryptedData=null;
  currentProgress+=5;
  if (assumeSymmetric) {
    PGPPBEEncryptedData pbe=null;
    Iterator<?> it=enc.getEncryptedDataObjects();
    while (it.hasNext()) {
      Object obj=it.next();
      if (obj instanceof PGPPBEEncryptedData) {
        pbe=(PGPPBEEncryptedData)obj;
        break;
      }
    }
    if (pbe == null) {
      throw new GeneralException(context.getString(R.string.error_noSymmetricEncryptionPacket));
    }
    if (progress != null)     progress.setProgress(R.string.progress_preparingStreams,currentProgress,100);
    PGPDigestCalculatorProvider digestCalcProvider=new JcaPGPDigestCalculatorProviderBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build();
    PBEDataDecryptorFactory decryptorFactory=new JcePBEDataDecryptorFactoryBuilder(digestCalcProvider).setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
    clear=pbe.getDataStream(decryptorFactory);
    encryptedData=pbe;
    currentProgress+=5;
  }
 else {
    if (progress != null)     progress.setProgress(R.string.progress_findingKey,currentProgress,100);
    PGPPublicKeyEncryptedData pbe=null;
    PGPSecretKey secretKey=null;
    Iterator<?> it=enc.getEncryptedDataObjects();
    while (it.hasNext()) {
      Object obj=it.next();
      if (obj instanceof PGPPublicKeyEncryptedData) {
        PGPPublicKeyEncryptedData encData=(PGPPublicKeyEncryptedData)obj;
        secretKey=getSecretKey(encData.getKeyID());
        if (secretKey != null) {
          pbe=encData;
          break;
        }
      }
    }
    if (secretKey == null) {
      throw new GeneralException(context.getString(R.string.error_noSecretKeyFound));
    }
    currentProgress+=5;
    if (progress != null)     progress.setProgress(R.string.progress_extractingKey,currentProgress,100);
    PGPPrivateKey privateKey=null;
    try {
      PBESecretKeyDecryptor keyDecryptor=new JcePBESecretKeyDecryptorBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
      privateKey=secretKey.extractPrivateKey(keyDecryptor);
    }
 catch (    PGPException e) {
      throw new PGPException(context.getString(R.string.error_wrongPassPhrase));
    }
    if (privateKey == null) {
      throw new GeneralException(context.getString(R.string.error_couldNotExtractPrivateKey));
    }
    currentProgress+=5;
    if (progress != null)     progress.setProgress(R.string.progress_preparingStreams,currentProgress,100);
    PublicKeyDataDecryptorFactory decryptorFactory=new JcePublicKeyDataDecryptorFactoryBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(privateKey);
    clear=pbe.getDataStream(decryptorFactory);
    encryptedData=pbe;
    currentProgress+=5;
  }
  PGPObjectFactory plainFact=new PGPObjectFactory(clear);
  Object dataChunk=plainFact.nextObject();
  PGPOnePassSignature signature=null;
  PGPPublicKey signatureKey=null;
  int signatureIndex=-1;
  if (dataChunk instanceof PGPCompressedData) {
    if (progress != null)     progress.setProgress(R.string.progress_decompressingData,currentProgress,100);
    PGPObjectFactory fact=new PGPObjectFactory(((PGPCompressedData)dataChunk).getDataStream());
    dataChunk=fact.nextObject();
    plainFact=fact;
    currentProgress+=10;
  }
  if (dataChunk instanceof PGPOnePassSignatureList) {
    if (progress != null)     progress.setProgress(R.string.progress_processingSignature,currentProgress,100);
    returnData.putBoolean(ApgService.RESULT_SIGNATURE,true);
    PGPOnePassSignatureList sigList=(PGPOnePassSignatureList)dataChunk;
    for (int i=0; i < sigList.size(); ++i) {
      signature=sigList.get(i);
      signatureKey=getPublicKey(signature.getKeyID());
      if (signatureKeyId == 0) {
        signatureKeyId=signature.getKeyID();
      }
      if (signatureKey == null) {
        signature=null;
      }
 else {
        signatureIndex=i;
        signatureKeyId=signature.getKeyID();
        String userId=null;
        PGPPublicKeyRing sigKeyRing=getPublicKeyRing(signatureKeyId);
        if (sigKeyRing != null) {
          userId=PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing));
        }
        returnData.putString(ApgService.RESULT_SIGNATURE_USER_ID,userId);
        break;
      }
    }
    returnData.putLong(ApgService.RESULT_SIGNATURE_KEY_ID,signatureKeyId);
    if (signature != null) {
      JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider=new JcaPGPContentVerifierBuilderProvider().setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
      signature.init(contentVerifierBuilderProvider,signatureKey);
    }
 else {
      returnData.putBoolean(ApgService.RESULT_SIGNATURE_UNKNOWN,true);
    }
    dataChunk=plainFact.nextObject();
    currentProgress+=10;
  }
  if (dataChunk instanceof PGPSignatureList) {
    dataChunk=plainFact.nextObject();
  }
  if (dataChunk instanceof PGPLiteralData) {
    if (progress != null)     progress.setProgress(R.string.progress_decrypting,currentProgress,100);
    PGPLiteralData literalData=(PGPLiteralData)dataChunk;
    OutputStream out=outStream;
    byte[] buffer=new byte[1 << 16];
    InputStream dataIn=literalData.getInputStream();
    int startProgress=currentProgress;
    int endProgress=100;
    if (signature != null) {
      endProgress=90;
    }
 else     if (encryptedData.isIntegrityProtected()) {
      endProgress=95;
    }
    int n=0;
    int done=0;
    long startPos=data.getStreamPosition();
    while ((n=dataIn.read(buffer)) > 0) {
      out.write(buffer,0,n);
      done+=n;
      if (signature != null) {
        try {
          signature.update(buffer,0,n);
        }
 catch (        SignatureException e) {
          returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS,false);
          signature=null;
        }
      }
      currentProgress=startProgress + (endProgress - startProgress) * done / (done + 100000);
      if (data.getSize() - startPos == 0) {
        currentProgress=endProgress;
      }
 else {
        currentProgress=(int)(startProgress + (endProgress - startProgress) * (data.getStreamPosition() - startPos) / (data.getSize() - startPos));
      }
      if (progress != null)       progress.setProgress(currentProgress,100);
    }
    if (signature != null) {
      if (progress != null)       progress.setProgress(R.string.progress_verifyingSignature,90,100);
      PGPSignatureList signatureList=(PGPSignatureList)plainFact.nextObject();
      PGPSignature messageSignature=signatureList.get(signatureIndex);
      if (signature.verify(messageSignature)) {
        returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS,true);
      }
 else {
        returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS,false);
      }
    }
  }
  if (encryptedData.isIntegrityProtected()) {
    if (progress != null)     progress.setProgress(R.string.progress_verifyingIntegrity,95,100);
    if (encryptedData.verify()) {
    }
 else {
    }
  }
 else {
  }
  if (progress != null)   progress.setProgress(R.string.progress_done,100,100);
  return returnData;
}

Fixed version (ground truth):
public static Bundle decrypt(Context context,InputData data,OutputStream outStream,String passPhrase,ProgressDialogUpdater progress,boolean assumeSymmetric) throws IOException, GeneralException, PGPException, SignatureException {
  if (passPhrase == null) {
    passPhrase="String_Node_Str";
  }
  Bundle returnData=new Bundle();
  InputStream in=PGPUtil.getDecoderStream(data.getInputStream());
  PGPObjectFactory pgpF=new PGPObjectFactory(in);
  PGPEncryptedDataList enc;
  Object o=pgpF.nextObject();
  long signatureKeyId=0;
  int currentProgress=0;
  if (progress != null)   progress.setProgress(R.string.progress_readingData,currentProgress,100);
  if (o instanceof PGPEncryptedDataList) {
    enc=(PGPEncryptedDataList)o;
  }
 else {
    enc=(PGPEncryptedDataList)pgpF.nextObject();
  }
  if (enc == null) {
    throw new GeneralException(context.getString(R.string.error_invalidData));
  }
  InputStream clear=null;
  PGPEncryptedData encryptedData=null;
  currentProgress+=5;
  if (assumeSymmetric) {
    PGPPBEEncryptedData pbe=null;
    Iterator<?> it=enc.getEncryptedDataObjects();
    while (it.hasNext()) {
      Object obj=it.next();
      if (obj instanceof PGPPBEEncryptedData) {
        pbe=(PGPPBEEncryptedData)obj;
        break;
      }
    }
    if (pbe == null) {
      throw new GeneralException(context.getString(R.string.error_noSymmetricEncryptionPacket));
    }
    updateProgress(progress,R.string.progress_preparingStreams,currentProgress,100);
    PGPDigestCalculatorProvider digestCalcProvider=new JcaPGPDigestCalculatorProviderBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build();
    PBEDataDecryptorFactory decryptorFactory=new JcePBEDataDecryptorFactoryBuilder(digestCalcProvider).setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
    clear=pbe.getDataStream(decryptorFactory);
    encryptedData=pbe;
    currentProgress+=5;
  }
 else {
    if (progress != null)     progress.setProgress(R.string.progress_findingKey,currentProgress,100);
    PGPPublicKeyEncryptedData pbe=null;
    PGPSecretKey secretKey=null;
    Iterator<?> it=enc.getEncryptedDataObjects();
    while (it.hasNext()) {
      Object obj=it.next();
      if (obj instanceof PGPPublicKeyEncryptedData) {
        PGPPublicKeyEncryptedData encData=(PGPPublicKeyEncryptedData)obj;
        secretKey=getSecretKey(encData.getKeyID());
        if (secretKey != null) {
          pbe=encData;
          break;
        }
      }
    }
    if (secretKey == null) {
      throw new GeneralException(context.getString(R.string.error_noSecretKeyFound));
    }
    currentProgress+=5;
    updateProgress(progress,R.string.progress_extractingKey,currentProgress,100);
    PGPPrivateKey privateKey=null;
    try {
      PBESecretKeyDecryptor keyDecryptor=new JcePBESecretKeyDecryptorBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
      privateKey=secretKey.extractPrivateKey(keyDecryptor);
    }
 catch (    PGPException e) {
      throw new PGPException(context.getString(R.string.error_wrongPassPhrase));
    }
    if (privateKey == null) {
      throw new GeneralException(context.getString(R.string.error_couldNotExtractPrivateKey));
    }
    currentProgress+=5;
    updateProgress(progress,R.string.progress_preparingStreams,currentProgress,100);
    PublicKeyDataDecryptorFactory decryptorFactory=new JcePublicKeyDataDecryptorFactoryBuilder().setProvider(BOUNCY_CASTLE_PROVIDER_NAME).build(privateKey);
    clear=pbe.getDataStream(decryptorFactory);
    encryptedData=pbe;
    currentProgress+=5;
  }
  PGPObjectFactory plainFact=new PGPObjectFactory(clear);
  Object dataChunk=plainFact.nextObject();
  PGPOnePassSignature signature=null;
  PGPPublicKey signatureKey=null;
  int signatureIndex=-1;
  if (dataChunk instanceof PGPCompressedData) {
    if (progress != null)     progress.setProgress(R.string.progress_decompressingData,currentProgress,100);
    PGPObjectFactory fact=new PGPObjectFactory(((PGPCompressedData)dataChunk).getDataStream());
    dataChunk=fact.nextObject();
    plainFact=fact;
    currentProgress+=10;
  }
  if (dataChunk instanceof PGPOnePassSignatureList) {
    if (progress != null)     progress.setProgress(R.string.progress_processingSignature,currentProgress,100);
    returnData.putBoolean(ApgService.RESULT_SIGNATURE,true);
    PGPOnePassSignatureList sigList=(PGPOnePassSignatureList)dataChunk;
    for (int i=0; i < sigList.size(); ++i) {
      signature=sigList.get(i);
      signatureKey=getPublicKey(signature.getKeyID());
      if (signatureKeyId == 0) {
        signatureKeyId=signature.getKeyID();
      }
      if (signatureKey == null) {
        signature=null;
      }
 else {
        signatureIndex=i;
        signatureKeyId=signature.getKeyID();
        String userId=null;
        PGPPublicKeyRing sigKeyRing=getPublicKeyRing(signatureKeyId);
        if (sigKeyRing != null) {
          userId=PGPHelper.getMainUserId(PGPHelper.getMasterKey(sigKeyRing));
        }
        returnData.putString(ApgService.RESULT_SIGNATURE_USER_ID,userId);
        break;
      }
    }
    returnData.putLong(ApgService.RESULT_SIGNATURE_KEY_ID,signatureKeyId);
    if (signature != null) {
      JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider=new JcaPGPContentVerifierBuilderProvider().setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
      signature.init(contentVerifierBuilderProvider,signatureKey);
    }
 else {
      returnData.putBoolean(ApgService.RESULT_SIGNATURE_UNKNOWN,true);
    }
    dataChunk=plainFact.nextObject();
    currentProgress+=10;
  }
  if (dataChunk instanceof PGPSignatureList) {
    dataChunk=plainFact.nextObject();
  }
  if (dataChunk instanceof PGPLiteralData) {
    if (progress != null)     progress.setProgress(R.string.progress_decrypting,currentProgress,100);
    PGPLiteralData literalData=(PGPLiteralData)dataChunk;
    OutputStream out=outStream;
    byte[] buffer=new byte[1 << 16];
    InputStream dataIn=literalData.getInputStream();
    int startProgress=currentProgress;
    int endProgress=100;
    if (signature != null) {
      endProgress=90;
    }
 else     if (encryptedData.isIntegrityProtected()) {
      endProgress=95;
    }
    int n=0;
    int done=0;
    long startPos=data.getStreamPosition();
    while ((n=dataIn.read(buffer)) > 0) {
      out.write(buffer,0,n);
      done+=n;
      if (signature != null) {
        try {
          signature.update(buffer,0,n);
        }
 catch (        SignatureException e) {
          returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS,false);
          signature=null;
        }
      }
      currentProgress=startProgress + (endProgress - startProgress) * done / (done + 100000);
      if (data.getSize() - startPos == 0) {
        currentProgress=endProgress;
      }
 else {
        currentProgress=(int)(startProgress + (endProgress - startProgress) * (data.getStreamPosition() - startPos) / (data.getSize() - startPos));
      }
      updateProgress(progress,currentProgress,100);
    }
    if (signature != null) {
      if (progress != null)       progress.setProgress(R.string.progress_verifyingSignature,90,100);
      PGPSignatureList signatureList=(PGPSignatureList)plainFact.nextObject();
      PGPSignature messageSignature=signatureList.get(signatureIndex);
      if (signature.verify(messageSignature)) {
        returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS,true);
      }
 else {
        returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS,false);
      }
    }
  }
  if (encryptedData.isIntegrityProtected()) {
    if (progress != null)     progress.setProgress(R.string.progress_verifyingIntegrity,95,100);
    if (encryptedData.verify()) {
    }
 else {
    }
  }
 else {
  }
  updateProgress(progress,R.string.progress_done,100,100);
  return returnData;
}