Program: 8224
Project: 8224
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;
    }
    PgpSignEncryptData pgpData=new PgpSignEncryptData();
    pgpData.setEnableAsciiArmorOutput(asciiArmor).setVersionHeader(null).setCompressionAlgorithm(compressionId);
    if (sign) {
      Intent signKeyIdIntent=getSignKeyMasterId(data);
      if (signKeyIdIntent.getIntExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_ERROR) != OpenPgpApi.RESULT_CODE_SUCCESS) {
        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");
      }
      long signSubKeyId=mKeyRepository.getCachedPublicKeyRing(signKeyId).getSecretSignId();
      pgpData.setSignatureMasterKeyId(signKeyId).setSignatureSubKeyId(signSubKeyId).setAdditionalEncryptId(signKeyId);
    }
    KeyIdResult keyIdResult=mKeyIdExtractor.returnKeyIdsFromIntent(data,false,mApiPermissionHelper.getCurrentCallingPackage());
    boolean isDryRun=data.getBooleanExtra(OpenPgpApi.EXTRA_DRY_RUN,false);
    boolean isOpportunistic=data.getBooleanExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION,false);
    KeyIdResultStatus keyIdResultStatus=keyIdResult.getStatus();
    if (isDryRun) {
      return getDryRunStatusResult(keyIdResult);
    }
    if (keyIdResult.hasKeySelectionPendingIntent()) {
      if ((keyIdResultStatus == KeyIdResultStatus.MISSING || keyIdResultStatus == KeyIdResultStatus.NO_KEYS || keyIdResultStatus == KeyIdResultStatus.NO_KEYS_ERROR) && isOpportunistic) {
        return createErrorResultIntent(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS,"String_Node_Str");
      }
      Intent result=new Intent();
      result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
      result.putExtra(OpenPgpApi.RESULT_INTENT,keyIdResult.getKeySelectionPendingIntent());
      return result;
    }
    pgpData.setEncryptionMasterKeyIds(keyIdResult.getKeyIds());
    PgpSignEncryptInputParcel pseInput=new PgpSignEncryptInputParcel(pgpData);
    pseInput.setAllowedKeyIds(getAllowedKeyIds());
    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));
    }
    long inputLength=inputStream.available();
    InputData inputData=new InputData(inputStream,inputLength,originalFilename);
    PgpSignEncryptOperation op=new PgpSignEncryptOperation(this,mKeyRepository,null);
    PgpSignEncryptResult pgpResult=op.execute(pseInput,inputParcel,inputData,outputStream);
    if (pgpResult.isPending()) {
      RequiredInputParcel requiredInput=pgpResult.getRequiredInputParcel();
      PendingIntent pIntent=mApiPendingIntentFactory.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);
    return createErrorResultIntent(OpenPgpError.GENERIC_ERROR,e.getMessage());
  }
}

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;
    }
    PgpSignEncryptData pgpData=new PgpSignEncryptData();
    pgpData.setEnableAsciiArmorOutput(asciiArmor).setVersionHeader(null).setCompressionAlgorithm(compressionId);
    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");
      }
      long signSubKeyId=mKeyRepository.getCachedPublicKeyRing(signKeyId).getSecretSignId();
      pgpData.setSignatureMasterKeyId(signKeyId).setSignatureSubKeyId(signSubKeyId).setAdditionalEncryptId(signKeyId);
    }
    KeyIdResult keyIdResult=mKeyIdExtractor.returnKeyIdsFromIntent(data,false,mApiPermissionHelper.getCurrentCallingPackage());
    boolean isDryRun=data.getBooleanExtra(OpenPgpApi.EXTRA_DRY_RUN,false);
    boolean isOpportunistic=data.getBooleanExtra(OpenPgpApi.EXTRA_OPPORTUNISTIC_ENCRYPTION,false);
    KeyIdResultStatus keyIdResultStatus=keyIdResult.getStatus();
    if (isDryRun) {
      return getDryRunStatusResult(keyIdResult);
    }
    if (keyIdResult.hasKeySelectionPendingIntent()) {
      if ((keyIdResultStatus == KeyIdResultStatus.MISSING || keyIdResultStatus == KeyIdResultStatus.NO_KEYS || keyIdResultStatus == KeyIdResultStatus.NO_KEYS_ERROR) && isOpportunistic) {
        return createErrorResultIntent(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS,"String_Node_Str");
      }
      Intent result=new Intent();
      result.putExtra(OpenPgpApi.RESULT_CODE,OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
      result.putExtra(OpenPgpApi.RESULT_INTENT,keyIdResult.getKeySelectionPendingIntent());
      return result;
    }
    pgpData.setEncryptionMasterKeyIds(keyIdResult.getKeyIds());
    PgpSignEncryptInputParcel pseInput=new PgpSignEncryptInputParcel(pgpData);
    pseInput.setAllowedKeyIds(getAllowedKeyIds());
    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));
    }
    long inputLength=inputStream.available();
    InputData inputData=new InputData(inputStream,inputLength,originalFilename);
    PgpSignEncryptOperation op=new PgpSignEncryptOperation(this,mKeyRepository,null);
    PgpSignEncryptResult pgpResult=op.execute(pseInput,inputParcel,inputData,outputStream);
    if (pgpResult.isPending()) {
      RequiredInputParcel requiredInput=pgpResult.getRequiredInputParcel();
      PendingIntent pIntent=mApiPendingIntentFactory.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);
    return createErrorResultIntent(OpenPgpError.GENERIC_ERROR,e.getMessage());
  }
}