Program: 153260
Project: 153260
Buggy source:
private byte[] readStandard(DataInputStream in,PassthroughConnection ptc,KillableThread thread,byte[] buffer){
  if (length == null) {
    return null;
  }
  if (length < 0) {
    compressed=true;
    length=-length;
  }
  setupBuffer(buffer);
  int pos=0;
  while (pos < length) {
    try {
      pos+=in.read(value,pos,length - pos);
    }
 catch (    SocketTimeoutException ste) {
      if (!thread.killed()) {
        timeout++;
        if (timeout > 20) {
          ptc.printLogMessage("String_Node_Str");
          return null;
        }
        continue;
      }
      return null;
    }
catch (    IOException e) {
      ptc.printLogMessage("String_Node_Str");
      return null;
    }
  }
  if (!compressed) {
    return value;
  }
 else   if (value == null) {
    return null;
  }
  ChunkScan chunkScan=ptc.chunkScan;
  if (Globals.compressInfo()) {
    ptc.printLogMessage("String_Node_Str" + length);
  }
  if (chunkScan.expandChunkData(buffer,length,buffer) == null) {
    return null;
  }
  chunkScan.extractHashes(buffer,ptc.hashes);
  int miss=0;
  int hit=0;
  int blockSize=Globals.getBlockSize();
  for (int cnt=0; cnt < 40; cnt++) {
    long hash=ptc.hashes[cnt];
    byte[] cachedHash=ptc.hashCache.getArray(hash,0,ptc);
    byte[] hashArray=cachedHash;
    if (cachedHash == null) {
      miss++;
      hashArray=new byte[2048];
      HashThread.transferArray(buffer,32768,cnt,hashArray,0,false);
      ptc.hashCache.addArray(hash,hashArray);
    }
 else {
      hit++;
      HashThread.transferArray(buffer,32768,cnt,cachedHash,0,true);
    }
    if (!ptc.hashesReceivedThisConnection.containsKey(hash)) {
      int ptcPos=ptc.hashBlockReceivedPos;
      ptc.hashesReceivedThisConnection.put(hash,true);
      ptc.hashBlockReceived[ptcPos]=hash;
      ptc.hashBlockReceivedFull[ptcPos]=hashArray;
      ptcPos++;
      if (ptcPos == blockSize) {
        ptcPos=0;
        ptc.hashCache.saveHashBlockToDisk(ptc.hashBlockReceived,ptc.hashBlockReceivedFull,blockSize,false);
      }
      ptc.hashBlockReceivedPos=ptcPos;
    }
  }
  if (Globals.compressInfo()) {
    ptc.printLogMessage("String_Node_Str" + hit + "String_Node_Str"+ miss);
  }
  Integer newLength=chunkScan.recompressChunkData(buffer,true,null);
  if (newLength == null) {
    return null;
  }
  lengthUnit.setValue(newLength);
  int saved=ptc.savedData.addAndGet(newLength - length);
  if (Main.craftGUI != null) {
    int percent=(100 * saved) / (ptc.packetCounter);
    Main.craftGUI.safeSetStatus("String_Node_Str" + ptc.clientInfo.getUsername() + "String_Node_Str"+ saved / 1024 + "String_Node_Str" + percent + "String_Node_Str");
  }
  return value;
}

Fixed version (ground truth):
private byte[] readStandard(DataInputStream in,PassthroughConnection ptc,KillableThread thread,byte[] buffer){
  if (length == null) {
    return null;
  }
  if (length < 0) {
    compressed=true;
    length=-length;
  }
  setupBuffer(buffer);
  int pos=0;
  while (pos < length) {
    try {
      pos+=in.read(value,pos,length - pos);
    }
 catch (    SocketTimeoutException ste) {
      if (!thread.killed()) {
        timeout++;
        if (timeout > 20) {
          ptc.printLogMessage("String_Node_Str");
          return null;
        }
        continue;
      }
      return null;
    }
catch (    IOException e) {
      ptc.printLogMessage("String_Node_Str");
      return null;
    }
  }
  if (!compressed) {
    return value;
  }
 else   if (value == null) {
    return null;
  }
  ChunkScan chunkScan=ptc.chunkScan;
  if (Globals.compressInfo()) {
    ptc.printLogMessage("String_Node_Str" + length);
  }
  if (chunkScan.expandChunkData(buffer,length,buffer) == null) {
    return null;
  }
  chunkScan.extractHashes(buffer,ptc.hashes);
  int miss=0;
  int hit=0;
  int blockSize=Globals.getBlockSize();
  for (int cnt=0; cnt < 40; cnt++) {
    long hash=ptc.hashes[cnt];
    byte[] cachedHash=ptc.hashCache.getArray(hash,0,ptc);
    byte[] hashArray=cachedHash;
    if (cachedHash == null) {
      miss++;
      hashArray=new byte[2048];
      HashThread.transferArray(buffer,65536,cnt,hashArray,0,false);
      ptc.hashCache.addArray(hash,hashArray);
    }
 else {
      hit++;
      HashThread.transferArray(buffer,65536,cnt,cachedHash,0,true);
    }
    if (!ptc.hashesReceivedThisConnection.containsKey(hash)) {
      int ptcPos=ptc.hashBlockReceivedPos;
      ptc.hashesReceivedThisConnection.put(hash,true);
      ptc.hashBlockReceived[ptcPos]=hash;
      ptc.hashBlockReceivedFull[ptcPos]=hashArray;
      ptcPos++;
      if (ptcPos == blockSize) {
        ptcPos=0;
        ptc.hashCache.saveHashBlockToDisk(ptc.hashBlockReceived,ptc.hashBlockReceivedFull,blockSize,false);
      }
      ptc.hashBlockReceivedPos=ptcPos;
    }
  }
  if (Globals.compressInfo()) {
    ptc.printLogMessage("String_Node_Str" + hit + "String_Node_Str"+ miss);
  }
  Integer newLength=chunkScan.recompressChunkData(buffer,true,null);
  if (newLength == null) {
    return null;
  }
  lengthUnit.setValue(newLength);
  int saved=ptc.savedData.addAndGet(newLength - length);
  if (Main.craftGUI != null) {
    int percent=(100 * saved) / (ptc.packetCounter);
    Main.craftGUI.safeSetStatus("String_Node_Str" + ptc.clientInfo.getUsername() + "String_Node_Str"+ saved / 1024 + "String_Node_Str" + percent + "String_Node_Str");
  }
  return value;
}