Program: 52578
Project: 52578
Buggy source:
public int receive(byte[] buf,int off,int len,int waitMillis) throws IOException {
  byte[] record=null;
  for (; ; ) {
    int receiveLimit=Math.min(len,getReceiveLimit()) + RECORD_HEADER_LENGTH;
    if (record == null || record.length < receiveLimit) {
      record=new byte[receiveLimit];
    }
    try {
      if (retransmit != null && System.currentTimeMillis() > retransmitExpiry) {
        retransmit=null;
        retransmitEpoch=null;
      }
      int received=receiveRecord(record,0,receiveLimit,waitMillis);
      if (received < 0) {
        return received;
      }
      if (received < RECORD_HEADER_LENGTH) {
        continue;
      }
      int length=TlsUtils.readUint16(record,11);
      if (received != (length + RECORD_HEADER_LENGTH)) {
        continue;
      }
      short type=TlsUtils.readUint8(record,0);
switch (type) {
case ContentType.alert:
case ContentType.application_data:
case ContentType.change_cipher_spec:
case ContentType.handshake:
case ContentType.heartbeat:
        break;
default :
      continue;
  }
  int epoch=TlsUtils.readUint16(record,3);
  DTLSEpoch recordEpoch=null;
  if (epoch == readEpoch.getEpoch()) {
    recordEpoch=readEpoch;
  }
 else   if (type == ContentType.handshake && retransmitEpoch != null && epoch == retransmitEpoch.getEpoch()) {
    recordEpoch=retransmitEpoch;
  }
  if (recordEpoch == null) {
    continue;
  }
  long seq=TlsUtils.readUint48(record,5);
  if (recordEpoch.getReplayWindow().shouldDiscard(seq)) {
    continue;
  }
  ProtocolVersion version=TlsUtils.readVersion(record,1);
  if (discoveredPeerVersion != null && !discoveredPeerVersion.equals(version)) {
    continue;
  }
  byte[] plaintext=recordEpoch.getCipher().decodeCiphertext(getMacSequenceNumber(recordEpoch.getEpoch(),seq),type,record,RECORD_HEADER_LENGTH,received - RECORD_HEADER_LENGTH);
  recordEpoch.getReplayWindow().reportAuthenticated(seq);
  if (plaintext.length > this.plaintextLimit) {
    continue;
  }
  if (discoveredPeerVersion == null) {
    discoveredPeerVersion=version;
  }
switch (type) {
case ContentType.alert:
{
      if (plaintext.length == 2) {
        short alertLevel=plaintext[0];
        short alertDescription=plaintext[1];
        peer.notifyAlertReceived(alertLevel,alertDescription);
        if (alertLevel == AlertLevel.fatal) {
          fail(alertDescription);
          throw new TlsFatalAlert(alertDescription);
        }
        if (alertDescription == AlertDescription.close_notify) {
          closeTransport();
        }
      }
 else {
      }
      continue;
    }
case ContentType.application_data:
{
    if (inHandshake) {
      continue;
    }
    break;
  }
case ContentType.change_cipher_spec:
{
  for (int i=0; i < plaintext.length; ++i) {
    short message=TlsUtils.readUint8(plaintext,i);
    if (message != ChangeCipherSpec.change_cipher_spec) {
      continue;
    }
    if (pendingEpoch != null) {
      readEpoch=pendingEpoch;
    }
  }
  continue;
}
case ContentType.handshake:
{
if (!inHandshake) {
  if (retransmit != null) {
    retransmit.receivedHandshakeRecord(epoch,plaintext,0,plaintext.length);
  }
  continue;
}
}
case ContentType.heartbeat:
{
continue;
}
}
if (!inHandshake && retransmit != null) {
this.retransmit=null;
this.retransmitEpoch=null;
}
System.arraycopy(plaintext,0,buf,off,plaintext.length);
return plaintext.length;
}
 catch (IOException e) {
throw e;
}
}
}

Fixed version (ground truth):
public int receive(byte[] buf,int off,int len,int waitMillis) throws IOException {
  byte[] record=null;
  for (; ; ) {
    int receiveLimit=Math.min(len,getReceiveLimit()) + RECORD_HEADER_LENGTH;
    if (record == null || record.length < receiveLimit) {
      record=new byte[receiveLimit];
    }
    try {
      if (retransmit != null && System.currentTimeMillis() > retransmitExpiry) {
        retransmit=null;
        retransmitEpoch=null;
      }
      int received=receiveRecord(record,0,receiveLimit,waitMillis);
      if (received < 0) {
        return received;
      }
      if (received < RECORD_HEADER_LENGTH) {
        continue;
      }
      int length=TlsUtils.readUint16(record,11);
      if (received != (length + RECORD_HEADER_LENGTH)) {
        continue;
      }
      short type=TlsUtils.readUint8(record,0);
switch (type) {
case ContentType.alert:
case ContentType.application_data:
case ContentType.change_cipher_spec:
case ContentType.handshake:
case ContentType.heartbeat:
        break;
default :
      continue;
  }
  int epoch=TlsUtils.readUint16(record,3);
  DTLSEpoch recordEpoch=null;
  if (epoch == readEpoch.getEpoch()) {
    recordEpoch=readEpoch;
  }
 else   if (type == ContentType.handshake && retransmitEpoch != null && epoch == retransmitEpoch.getEpoch()) {
    recordEpoch=retransmitEpoch;
  }
  if (recordEpoch == null) {
    continue;
  }
  long seq=TlsUtils.readUint48(record,5);
  if (recordEpoch.getReplayWindow().shouldDiscard(seq)) {
    continue;
  }
  ProtocolVersion version=TlsUtils.readVersion(record,1);
  if (discoveredPeerVersion != null && !discoveredPeerVersion.equals(version)) {
    continue;
  }
  byte[] plaintext=recordEpoch.getCipher().decodeCiphertext(getMacSequenceNumber(recordEpoch.getEpoch(),seq),type,record,RECORD_HEADER_LENGTH,received - RECORD_HEADER_LENGTH);
  recordEpoch.getReplayWindow().reportAuthenticated(seq);
  if (plaintext.length > this.plaintextLimit) {
    continue;
  }
  if (discoveredPeerVersion == null) {
    discoveredPeerVersion=version;
  }
switch (type) {
case ContentType.alert:
{
      if (plaintext.length == 2) {
        short alertLevel=plaintext[0];
        short alertDescription=plaintext[1];
        peer.notifyAlertReceived(alertLevel,alertDescription);
        if (alertLevel == AlertLevel.fatal) {
          fail(alertDescription);
          throw new TlsFatalAlert(alertDescription);
        }
        if (alertDescription == AlertDescription.close_notify) {
          closeTransport();
        }
      }
 else {
      }
      continue;
    }
case ContentType.application_data:
{
    if (inHandshake) {
      continue;
    }
    break;
  }
case ContentType.change_cipher_spec:
{
  for (int i=0; i < plaintext.length; ++i) {
    short message=TlsUtils.readUint8(plaintext,i);
    if (message != ChangeCipherSpec.change_cipher_spec) {
      continue;
    }
    if (pendingEpoch != null) {
      readEpoch=pendingEpoch;
    }
  }
  continue;
}
case ContentType.handshake:
{
if (!inHandshake) {
  if (retransmit != null) {
    retransmit.receivedHandshakeRecord(epoch,plaintext,0,plaintext.length);
  }
  continue;
}
break;
}
case ContentType.heartbeat:
{
continue;
}
}
if (!inHandshake && retransmit != null) {
this.retransmit=null;
this.retransmitEpoch=null;
}
System.arraycopy(plaintext,0,buf,off,plaintext.length);
return plaintext.length;
}
 catch (IOException e) {
throw e;
}
}
}