Program: 52517
Project: 52517
Buggy source:
/** 
 * Populate a passed in array with random data.
 * @param output output array for generated bits.
 * @param additionalInput additional input to be added to the DRBG in this step.
 * @param predictionResistant true if a reseed should be forced, false otherwise.
 * @return number of bits generated, -1 if a reseed required.
 */
public int generate(byte[] output,byte[] additionalInput,boolean predictionResistant){
  if (_isTDEA) {
    if (_reseedCounter > TDEA_RESEED_MAX) {
      return -1;
    }
    if (Utils.isTooLarge(output,TDEA_MAX_BITS_REQUEST / 8)) {
      throw new IllegalArgumentException("String_Node_Str" + TDEA_MAX_BITS_REQUEST);
    }
  }
 else {
    if (_reseedCounter > AES_RESEED_MAX) {
      return -1;
    }
    if (Utils.isTooLarge(output,AES_MAX_BITS_REQUEST / 8)) {
      throw new IllegalArgumentException("String_Node_Str" + AES_MAX_BITS_REQUEST);
    }
  }
  if (predictionResistant) {
    CTR_DRBG_Reseed_algorithm(_entropySource,additionalInput);
    additionalInput=null;
  }
  if (additionalInput != null) {
    additionalInput=Block_Cipher_df(additionalInput,_seedLength);
    CTR_DRBG_Update(additionalInput,_Key,_V);
  }
 else {
    additionalInput=new byte[_seedLength];
  }
  byte[] out=new byte[_V.length];
  _engine.init(true,new KeyParameter(expandKey(_Key)));
  for (int i=0; i <= output.length / out.length; i++) {
    addOneTo(_V);
    _engine.processBlock(_V,0,out,0);
    int bytesToCopy=((output.length - i * out.length) > out.length) ? out.length : (output.length - i * _V.length);
    System.arraycopy(out,0,output,i * out.length,bytesToCopy);
  }
  CTR_DRBG_Update(additionalInput,_Key,_V);
  _reseedCounter++;
  return output.length * 8;
}

Fixed version (ground truth):
/** 
 * Populate a passed in array with random data.
 * @param output output array for generated bits.
 * @param additionalInput additional input to be added to the DRBG in this step.
 * @param predictionResistant true if a reseed should be forced, false otherwise.
 * @return number of bits generated, -1 if a reseed required.
 */
public int generate(byte[] output,byte[] additionalInput,boolean predictionResistant){
  if (_isTDEA) {
    if (_reseedCounter > TDEA_RESEED_MAX) {
      return -1;
    }
    if (Utils.isTooLarge(output,TDEA_MAX_BITS_REQUEST / 8)) {
      throw new IllegalArgumentException("String_Node_Str" + TDEA_MAX_BITS_REQUEST);
    }
  }
 else {
    if (_reseedCounter > AES_RESEED_MAX) {
      return -1;
    }
    if (Utils.isTooLarge(output,AES_MAX_BITS_REQUEST / 8)) {
      throw new IllegalArgumentException("String_Node_Str" + AES_MAX_BITS_REQUEST);
    }
  }
  if (predictionResistant) {
    CTR_DRBG_Reseed_algorithm(_entropySource,additionalInput);
    additionalInput=null;
  }
  if (additionalInput != null) {
    additionalInput=Block_Cipher_df(additionalInput,_seedLength);
    CTR_DRBG_Update(additionalInput,_Key,_V);
  }
 else {
    additionalInput=new byte[_seedLength];
  }
  byte[] out=new byte[_V.length];
  _engine.init(true,new KeyParameter(expandKey(_Key)));
  for (int i=0; i <= output.length / out.length; i++) {
    int bytesToCopy=((output.length - i * out.length) > out.length) ? out.length : (output.length - i * _V.length);
    if (bytesToCopy != 0) {
      addOneTo(_V);
      _engine.processBlock(_V,0,out,0);
      System.arraycopy(out,0,output,i * out.length,bytesToCopy);
    }
  }
  CTR_DRBG_Update(additionalInput,_Key,_V);
  _reseedCounter++;
  return output.length * 8;
}