Program: 8424
Project: 8424
Buggy source:
public static Bundle verifyText(Context context,InputData data,OutputStream outStream,boolean lookupUnknownKey,ProgressDialogUpdater progress) throws IOException, ApgGeneralException, PGPException, SignatureException {
  Bundle returnData=new Bundle();
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  ArmoredInputStream aIn=new ArmoredInputStream(data.getInputStream());
  updateProgress(progress,R.string.progress_done,0,100);
  ByteArrayOutputStream lineOut=new ByteArrayOutputStream();
  int lookAhead=readInputLine(lineOut,aIn);
  byte[] lineSep=getLineSeparator();
  byte[] line=lineOut.toByteArray();
  out.write(line,0,getLengthWithoutSeparator(line));
  out.write(lineSep);
  while (lookAhead != -1 && aIn.isClearText()) {
    lookAhead=readInputLine(lineOut,lookAhead,aIn);
    line=lineOut.toByteArray();
    out.write(line,0,getLengthWithoutSeparator(line));
    out.write(lineSep);
  }
  out.close();
  byte[] clearText=out.toByteArray();
  outStream.write(clearText);
  returnData.putBoolean(ApgService.RESULT_SIGNATURE,true);
  updateProgress(progress,R.string.progress_processingSignature,60,100);
  PGPObjectFactory pgpFact=new PGPObjectFactory(aIn);
  PGPSignatureList sigList=(PGPSignatureList)pgpFact.nextObject();
  if (sigList == null) {
    throw new ApgGeneralException(context.getString(R.string.error_corruptData));
  }
  PGPSignature signature=null;
  long signatureKeyId=0;
  PGPPublicKey signatureKey=null;
  for (int i=0; i < sigList.size(); ++i) {
    signature=sigList.get(i);
    signatureKey=ProviderHelper.getPGPPublicKey(context,signature.getKeyID());
    if (signatureKeyId == 0) {
      signatureKeyId=signature.getKeyID();
    }
    if (signatureKey == null && lookupUnknownKey) {
      returnData=new Bundle();
      returnData.putLong(ApgService.RESULT_SIGNATURE_KEY_ID,signatureKeyId);
      returnData.putBoolean(ApgService.RESULT_SIGNATURE_LOOKUP_KEY,true);
      return returnData;
    }
    if (signatureKey == null) {
      signature=null;
    }
 else {
      signatureKeyId=signature.getKeyID();
      String userId=null;
      PGPPublicKeyRing sigKeyRing=ProviderHelper.getPGPPublicKeyRingByMasterKeyId(context,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) {
    returnData.putBoolean(ApgService.RESULT_SIGNATURE_UNKNOWN,true);
    if (progress != null)     progress.setProgress(R.string.progress_done,100,100);
    return returnData;
  }
  JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider=new JcaPGPContentVerifierBuilderProvider().setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
  signature.init(contentVerifierBuilderProvider,signatureKey);
  InputStream sigIn=new BufferedInputStream(new ByteArrayInputStream(clearText));
  lookAhead=readInputLine(lineOut,sigIn);
  processLine(signature,lineOut.toByteArray());
  if (lookAhead != -1) {
    do {
      lookAhead=readInputLine(lineOut,lookAhead,sigIn);
      signature.update((byte)'\r');
      signature.update((byte)'\n');
      processLine(signature,lineOut.toByteArray());
    }
 while (lookAhead != -1);
  }
  returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS,signature.verify());
  updateProgress(progress,R.string.progress_done,100,100);
  return returnData;
}

Fixed version (ground truth):
public static Bundle verifyText(Context context,InputData data,OutputStream outStream,boolean lookupUnknownKey,ProgressDialogUpdater progress) throws IOException, ApgGeneralException, PGPException, SignatureException {
  Bundle returnData=new Bundle();
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  ArmoredInputStream aIn=new ArmoredInputStream(data.getInputStream());
  updateProgress(progress,R.string.progress_done,0,100);
  ByteArrayOutputStream lineOut=new ByteArrayOutputStream();
  int lookAhead=readInputLine(lineOut,aIn);
  byte[] lineSep=getLineSeparator();
  byte[] line=lineOut.toByteArray();
  out.write(line,0,getLengthWithoutSeparator(line));
  out.write(lineSep);
  while (lookAhead != -1 && aIn.isClearText()) {
    lookAhead=readInputLine(lineOut,lookAhead,aIn);
    line=lineOut.toByteArray();
    out.write(line,0,getLengthWithoutSeparator(line));
    out.write(lineSep);
  }
  out.close();
  byte[] clearText=out.toByteArray();
  outStream.write(clearText);
  returnData.putBoolean(ApgService.RESULT_SIGNATURE,true);
  updateProgress(progress,R.string.progress_processingSignature,60,100);
  PGPObjectFactory pgpFact=new PGPObjectFactory(aIn);
  PGPSignatureList sigList=(PGPSignatureList)pgpFact.nextObject();
  if (sigList == null) {
    throw new ApgGeneralException(context.getString(R.string.error_corruptData));
  }
  PGPSignature signature=null;
  long signatureKeyId=0;
  PGPPublicKey signatureKey=null;
  for (int i=0; i < sigList.size(); ++i) {
    signature=sigList.get(i);
    signatureKey=ProviderHelper.getPGPPublicKey(context,signature.getKeyID());
    if (signatureKeyId == 0) {
      signatureKeyId=signature.getKeyID();
    }
    if (signatureKey == null && lookupUnknownKey) {
      returnData=new Bundle();
      returnData.putLong(ApgService.RESULT_SIGNATURE_KEY_ID,signatureKeyId);
      returnData.putBoolean(ApgService.RESULT_SIGNATURE_LOOKUP_KEY,true);
      return returnData;
    }
    if (signatureKey == null) {
      signature=null;
    }
 else {
      signatureKeyId=signature.getKeyID();
      String userId=null;
      PGPPublicKeyRing signKeyRing=ProviderHelper.getPGPPublicKeyRingByMasterKeyId(context,signatureKeyId);
      if (signKeyRing != null) {
        userId=PGPHelper.getMainUserId(PGPHelper.getMasterKey(signKeyRing));
      }
      returnData.putString(ApgService.RESULT_SIGNATURE_USER_ID,userId);
      break;
    }
  }
  returnData.putLong(ApgService.RESULT_SIGNATURE_KEY_ID,signatureKeyId);
  if (signature == null) {
    returnData.putBoolean(ApgService.RESULT_SIGNATURE_UNKNOWN,true);
    if (progress != null)     progress.setProgress(R.string.progress_done,100,100);
    return returnData;
  }
  JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider=new JcaPGPContentVerifierBuilderProvider().setProvider(BOUNCY_CASTLE_PROVIDER_NAME);
  signature.init(contentVerifierBuilderProvider,signatureKey);
  InputStream sigIn=new BufferedInputStream(new ByteArrayInputStream(clearText));
  lookAhead=readInputLine(lineOut,sigIn);
  processLine(signature,lineOut.toByteArray());
  if (lookAhead != -1) {
    do {
      lookAhead=readInputLine(lineOut,lookAhead,sigIn);
      signature.update((byte)'\r');
      signature.update((byte)'\n');
      processLine(signature,lineOut.toByteArray());
    }
 while (lookAhead != -1);
  }
  returnData.putBoolean(ApgService.RESULT_SIGNATURE_SUCCESS,signature.verify());
  updateProgress(progress,R.string.progress_done,100,100);
  return returnData;
}