Program: 187854
Project: 187854
Buggy source:
/** 
 * encrypt a string using a random session key
 * @author Peli
 * @param plaintext
 * @return encrypted String
 * @throws Exception
 */
public Uri encryptFileWithSessionKey(ContentResolver contentResolver,Uri fileUri) throws CryptoHelperException {
  Log.i(TAG,"String_Node_Str");
  status=false;
  if (password == null) {
    String msg="String_Node_Str";
    throw new CryptoHelperException(msg);
  }
  String outputPath="String_Node_Str";
  try {
    InputStream is;
    if (fileUri.getScheme().equals("String_Node_Str")) {
      is=new java.io.FileInputStream(fileUri.getPath());
      outputPath=fileUri.getPath() + "String_Node_Str";
    }
 else {
      is=contentResolver.openInputStream(fileUri);
      outputPath=Environment.getExternalStorageDirectory().toString() + "String_Node_Str";
    }
    FileOutputStream os=new FileOutputStream(outputPath);
    byte[] cipherSessionKey={};
    byte[] ciphertext={};
    SecretKey sessionKey=null;
    byte[] sessionKeyEncoded=null;
    String sessionKeyString=null;
    try {
      KeyGenerator keygen;
      keygen=KeyGenerator.getInstance("String_Node_Str");
      keygen.init(256);
      sessionKey=keygen.generateKey();
      sessionKeyEncoded=sessionKey.getEncoded();
      sessionKeyString=new String(sessionKeyEncoded);
    }
 catch (    NoSuchAlgorithmException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
    try {
      pbeCipher.init(Cipher.ENCRYPT_MODE,pbeKey,pbeParamSpec);
      cipherSessionKey=pbeCipher.doFinal(sessionKeyEncoded);
    }
 catch (    IllegalBlockSizeException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
catch (    BadPaddingException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
catch (    InvalidKeyException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
catch (    InvalidAlgorithmParameterException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
    String stringCipherVersion="String_Node_Str";
    byte[] bytesCipherVersion=stringCipherVersion.getBytes();
    os.write(bytesCipherVersion,0,bytesCipherVersion.length);
    os.write(cipherSessionKey,0,cipherSessionKey.length);
    Log.d(TAG,"String_Node_Str" + bytesCipherVersion.length);
    Log.d(TAG,"String_Node_Str" + cipherSessionKey.length);
    Trivium tri=new Trivium();
    try {
      tri.setupKey(Trivium.MODE_ENCRYPT,sessionKeyEncoded,0);
      tri.setupNonce(sessionKeyEncoded,10);
      final int bytesLen=4096;
      byte[] bytesIn=new byte[bytesLen];
      byte[] bytesOut=new byte[bytesLen];
      int offset=0;
      int numRead=0;
      while ((numRead=is.read(bytesIn,0,bytesLen)) >= 0) {
        if ((numRead | 3) != 0) {
          Log.d(TAG,"String_Node_Str" + numRead);
        }
        tri.process(bytesIn,0,bytesOut,0,numRead);
        os.write(bytesOut,0,numRead);
        offset+=numRead;
      }
      if (offset < is.available()) {
        throw new IOException("String_Node_Str");
      }
      is.close();
      os.close();
    }
 catch (    ESJException e) {
      Log.e(TAG,"String_Node_Str",e);
    }
  }
 catch (  FileNotFoundException e) {
    Log.e(TAG,"String_Node_Str",e);
  }
catch (  IOException e) {
    Log.e(TAG,"String_Node_Str",e);
  }
  return Uri.parse("String_Node_Str" + outputPath);
}

Fixed version (ground truth):
/** 
 * encrypt a string using a random session key
 * @author Peli
 * @param plaintext
 * @return encrypted String
 * @throws Exception
 */
public Uri encryptFileWithSessionKey(ContentResolver contentResolver,Uri fileUri) throws CryptoHelperException {
  Log.i(TAG,"String_Node_Str");
  status=false;
  if (password == null) {
    String msg="String_Node_Str";
    throw new CryptoHelperException(msg);
  }
  String outputPath="String_Node_Str";
  try {
    InputStream is;
    if (fileUri.getScheme().equals("String_Node_Str")) {
      is=new java.io.FileInputStream(fileUri.getPath());
      outputPath=fileUri.getPath() + "String_Node_Str";
    }
 else {
      is=contentResolver.openInputStream(fileUri);
      outputPath=Environment.getExternalStorageDirectory().toString() + "String_Node_Str";
    }
    FileOutputStream os=new FileOutputStream(outputPath);
    byte[] cipherSessionKey={};
    byte[] ciphertext={};
    SecretKey sessionKey=null;
    byte[] sessionKeyEncoded=null;
    String sessionKeyString=null;
    try {
      KeyGenerator keygen;
      keygen=KeyGenerator.getInstance("String_Node_Str");
      keygen.init(256);
      sessionKey=keygen.generateKey();
      sessionKeyEncoded=sessionKey.getEncoded();
      sessionKeyString=new String(sessionKeyEncoded);
    }
 catch (    NoSuchAlgorithmException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
    try {
      pbeCipher.init(Cipher.ENCRYPT_MODE,pbeKey,pbeParamSpec);
      cipherSessionKey=pbeCipher.doFinal(sessionKeyEncoded);
    }
 catch (    IllegalBlockSizeException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
catch (    BadPaddingException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
catch (    InvalidKeyException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
catch (    InvalidAlgorithmParameterException e) {
      Log.e(TAG,"String_Node_Str" + e.toString());
    }
    String stringCipherVersion="String_Node_Str";
    byte[] bytesCipherVersion=stringCipherVersion.getBytes();
    os.write(bytesCipherVersion,0,bytesCipherVersion.length);
    os.write(cipherSessionKey,0,cipherSessionKey.length);
    Log.d(TAG,"String_Node_Str" + bytesCipherVersion.length);
    Log.d(TAG,"String_Node_Str" + cipherSessionKey.length);
    Trivium tri=new Trivium();
    try {
      tri.setupKey(Trivium.MODE_ENCRYPT,sessionKeyEncoded,0);
      tri.setupNonce(sessionKeyEncoded,10);
      final int bytesLen=4096;
      byte[] bytesIn=new byte[bytesLen];
      byte[] bytesOut=new byte[bytesLen];
      int offset=0;
      int numRead=0;
      while ((numRead=is.read(bytesIn,0,bytesLen)) >= 0) {
        if ((numRead & 3) != 0) {
          Log.d(TAG,"String_Node_Str" + numRead + "String_Node_Str"+ (numRead | 3));
        }
        tri.process(bytesIn,0,bytesOut,0,numRead);
        os.write(bytesOut,0,numRead);
        offset+=numRead;
      }
      if (offset < is.available()) {
        throw new IOException("String_Node_Str");
      }
      is.close();
      os.close();
    }
 catch (    ESJException e) {
      Log.e(TAG,"String_Node_Str",e);
    }
  }
 catch (  FileNotFoundException e) {
    Log.e(TAG,"String_Node_Str",e);
  }
catch (  IOException e) {
    Log.e(TAG,"String_Node_Str",e);
  }
  return Uri.parse("String_Node_Str" + outputPath);
}