Program: 8252
Project: 8252
Buggy source:
private Intent encryptAndSignImpl(Intent data,InputStream inputStream,OutputStream outputStream,boolean sign){
  try {
    boolean asciiArmor=data.getBooleanExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR,true);
    String originalFilename=data.getStringExtra(OpenPgpApi.EXTRA_ORIGINAL_FILENAME);
    if (originalFilename == null) {
      originalFilename="String_Node_Str";
    }
    boolean enableCompression=data.getBooleanExtra(OpenPgpApi.EXTRA_ENABLE_COMPRESSION,true);
    int compressionId;
    if (enableCompression) {
      compressionId=PgpSecurityConstants.OpenKeychainCompressionAlgorithmTags.USE_DEFAULT;
    }
 else {
      compressionId=PgpSecurityConstants.OpenKeychainCompressionAlgorithmTags.UNCOMPRESSED;
    }
    long[] keyIds;
{
      HashSet<Long> encryptKeyIds=new HashSet<>();
      if (data.hasExtra(OpenPgpApi.EXTRA_USER_IDS)) {
        String[] userIds=data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS);
        boolean isOpportunistic=data.getBooleanExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION,false);
        KeyIdResult result=returnKeyIdsFromEmails(data,userIds,isOpportunistic);
        if (result.mResultIntent != null) {
          return result.mResultIntent;
        }
        encryptKeyIds.addAll(result.mKeyIds);
      }
      if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS)) {
        for (        long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS)) {
          encryptKeyIds.add(keyId);
        }
      }
      keyIds=getUnboxedLongArray(encryptKeyIds);
    }
    long inputLength=inputStream.available();
    InputData inputData=new InputData(inputStream,inputLength,originalFilename);
    PgpSignEncryptInputParcel pseInput=new PgpSignEncryptInputParcel();
    pseInput.setEnableAsciiArmorOutput(asciiArmor).setVersionHeader(null).setCompressionAlgorithm(compressionId).setSymmetricEncryptionAlgorithm(PgpSecurityConstants.OpenKeychainSymmetricKeyAlgorithmTags.USE_DEFAULT).setEncryptionMasterKeyIds(keyIds).setFailOnMissingEncryptionKeyIds(true);
    if (sign) {
      Intent signKeyIdIntent=getSignKeyMasterId(data);
      if (signKeyIdIntent.getIntExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_ERROR) == OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED) {
        return signKeyIdIntent;
      }
      long signKeyId=signKeyIdIntent.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID,Constants.key.none);
      if (signKeyId == Constants.key.none) {
        throw new Exception("String_Node_Str");
      }
 else {
        pseInput.setSignatureMasterKeyId(signKeyId);
        try {
          long signSubKeyId=mProviderHelper.getCachedPublicKeyRing(pseInput.getSignatureMasterKeyId()).getSecretSignId();
          pseInput.setSignatureSubKeyId(signSubKeyId);
        }
 catch (        PgpKeyNotFoundException e) {
          throw new Exception("String_Node_Str",e);
        }
      }
      pseInput.setSignatureHashAlgorithm(PgpSecurityConstants.OpenKeychainHashAlgorithmTags.USE_DEFAULT).setAdditionalEncryptId(signKeyId);
    }
    if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION,-1) < 7) {
      String accName=data.getStringExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME);
      if (TextUtils.isEmpty(accName)) {
        accName="String_Node_Str";
      }
      final AccountSettings accSettings=mApiPermissionHelper.getAccSettings(accName);
      if (accSettings == null || (accSettings.getKeyId() == Constants.key.none)) {
        return mApiPermissionHelper.getCreateAccountIntent(data,accName);
      }
      pseInput.setAdditionalEncryptId(accSettings.getKeyId());
    }
    CryptoInputParcel inputParcel=CryptoInputParcelCacheService.getCryptoInputParcel(this,data);
    if (inputParcel == null) {
      inputParcel=new CryptoInputParcel(new Date());
    }
    if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
      inputParcel.mPassphrase=new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE));
    }
    PgpSignEncryptOperation op=new PgpSignEncryptOperation(this,mProviderHelper,null);
    PgpSignEncryptResult pgpResult=op.execute(pseInput,inputParcel,inputData,outputStream);
    if (pgpResult.isPending()) {
      ApiPendingIntentFactory piFactory=new ApiPendingIntentFactory(getBaseContext());
      RequiredInputParcel requiredInput=pgpResult.getRequiredInputParcel();
      PendingIntent pIntent=piFactory.requiredInputPi(data,requiredInput,pgpResult.mCryptoInputParcel);
      Intent result=new Intent();
      result.putExtra(OpenPgpApi.RESULT_INTENT,pIntent);
      result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
      return result;
    }
 else     if (pgpResult.success()) {
      Intent result=new Intent();
      result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_SUCCESS);
      return result;
    }
 else {
      LogEntryParcel errorMsg=pgpResult.getLog().getLast();
      throw new Exception(getString(errorMsg.mType.getMsgId()));
    }
  }
 catch (  Exception e) {
    Log.d(Constants.TAG,"String_Node_Str",e);
    Intent result=new Intent();
    result.putExtra(OpenPgpApi.RESULT_ERROR,new OpenPgpError(OpenPgpError.GENERIC_ERROR,e.getMessage()));
    result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_ERROR);
    return result;
  }
}

Fixed version (ground truth):
private Intent encryptAndSignImpl(Intent data,InputStream inputStream,OutputStream outputStream,boolean sign){
  try {
    boolean asciiArmor=data.getBooleanExtra(OpenPgpApi.EXTRA_REQUEST_ASCII_ARMOR,true);
    String originalFilename=data.getStringExtra(OpenPgpApi.EXTRA_ORIGINAL_FILENAME);
    if (originalFilename == null) {
      originalFilename="String_Node_Str";
    }
    boolean enableCompression=data.getBooleanExtra(OpenPgpApi.EXTRA_ENABLE_COMPRESSION,true);
    int compressionId;
    if (enableCompression) {
      compressionId=PgpSecurityConstants.OpenKeychainCompressionAlgorithmTags.USE_DEFAULT;
    }
 else {
      compressionId=PgpSecurityConstants.OpenKeychainCompressionAlgorithmTags.UNCOMPRESSED;
    }
    long[] keyIds;
{
      HashSet<Long> encryptKeyIds=new HashSet<>();
      if (data.hasExtra(OpenPgpApi.EXTRA_USER_IDS)) {
        String[] userIds=data.getStringArrayExtra(OpenPgpApi.EXTRA_USER_IDS);
        boolean isOpportunistic=data.getBooleanExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION,false);
        KeyIdResult result=returnKeyIdsFromEmails(data,userIds,isOpportunistic);
        if (result.mResultIntent != null) {
          return result.mResultIntent;
        }
        encryptKeyIds.addAll(result.mKeyIds);
      }
      if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS)) {
        for (        long keyId : data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS)) {
          encryptKeyIds.add(keyId);
        }
      }
      keyIds=getUnboxedLongArray(encryptKeyIds);
    }
    long inputLength=inputStream.available();
    InputData inputData=new InputData(inputStream,inputLength,originalFilename);
    PgpSignEncryptInputParcel pseInput=new PgpSignEncryptInputParcel();
    pseInput.setEnableAsciiArmorOutput(asciiArmor).setVersionHeader(null).setCompressionAlgorithm(compressionId).setSymmetricEncryptionAlgorithm(PgpSecurityConstants.OpenKeychainSymmetricKeyAlgorithmTags.USE_DEFAULT).setEncryptionMasterKeyIds(keyIds);
    if (sign) {
      Intent signKeyIdIntent=getSignKeyMasterId(data);
      if (signKeyIdIntent.getIntExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_ERROR) == OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED) {
        return signKeyIdIntent;
      }
      long signKeyId=signKeyIdIntent.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID,Constants.key.none);
      if (signKeyId == Constants.key.none) {
        throw new Exception("String_Node_Str");
      }
 else {
        pseInput.setSignatureMasterKeyId(signKeyId);
        try {
          long signSubKeyId=mProviderHelper.getCachedPublicKeyRing(pseInput.getSignatureMasterKeyId()).getSecretSignId();
          pseInput.setSignatureSubKeyId(signSubKeyId);
        }
 catch (        PgpKeyNotFoundException e) {
          throw new Exception("String_Node_Str",e);
        }
      }
      pseInput.setSignatureHashAlgorithm(PgpSecurityConstants.OpenKeychainHashAlgorithmTags.USE_DEFAULT).setAdditionalEncryptId(signKeyId);
    }
    if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION,-1) < 7) {
      String accName=data.getStringExtra(OpenPgpApi.EXTRA_ACCOUNT_NAME);
      if (TextUtils.isEmpty(accName)) {
        accName="String_Node_Str";
      }
      final AccountSettings accSettings=mApiPermissionHelper.getAccSettings(accName);
      if (accSettings == null || (accSettings.getKeyId() == Constants.key.none)) {
        return mApiPermissionHelper.getCreateAccountIntent(data,accName);
      }
      pseInput.setAdditionalEncryptId(accSettings.getKeyId());
    }
    CryptoInputParcel inputParcel=CryptoInputParcelCacheService.getCryptoInputParcel(this,data);
    if (inputParcel == null) {
      inputParcel=new CryptoInputParcel(new Date());
    }
    if (data.hasExtra(OpenPgpApi.EXTRA_PASSPHRASE)) {
      inputParcel.mPassphrase=new Passphrase(data.getCharArrayExtra(OpenPgpApi.EXTRA_PASSPHRASE));
    }
    PgpSignEncryptOperation op=new PgpSignEncryptOperation(this,mProviderHelper,null);
    PgpSignEncryptResult pgpResult=op.execute(pseInput,inputParcel,inputData,outputStream);
    if (pgpResult.isPending()) {
      ApiPendingIntentFactory piFactory=new ApiPendingIntentFactory(getBaseContext());
      RequiredInputParcel requiredInput=pgpResult.getRequiredInputParcel();
      PendingIntent pIntent=piFactory.requiredInputPi(data,requiredInput,pgpResult.mCryptoInputParcel);
      Intent result=new Intent();
      result.putExtra(OpenPgpApi.RESULT_INTENT,pIntent);
      result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
      return result;
    }
 else     if (pgpResult.success()) {
      Intent result=new Intent();
      result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_SUCCESS);
      return result;
    }
 else {
      LogEntryParcel errorMsg=pgpResult.getLog().getLast();
      throw new Exception(getString(errorMsg.mType.getMsgId()));
    }
  }
 catch (  Exception e) {
    Log.d(Constants.TAG,"String_Node_Str",e);
    Intent result=new Intent();
    result.putExtra(OpenPgpApi.RESULT_ERROR,new OpenPgpError(OpenPgpError.GENERIC_ERROR,e.getMessage()));
    result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_ERROR);
    return result;
  }
}