Program: 178611
Project: 178611
Buggy source:
public Packet getPacket(Packet packet,int timeout) throws IOException {
  if (packet == null) {
    packet=new Packet();
    packet.buffer=buffer;
    packet.mask=bufferMask;
  }
  Packet ret=null;
  long startTime=System.currentTimeMillis();
  boolean interrupted=false;
  int packetId=-1;
  while (ret == null && length < bufferLength && startTime + timeout > System.currentTimeMillis() && !Thread.currentThread().isInterrupted()) {
    try {
      ret=PacketScan.packetScan(buffer,start,length,bufferMask,packet);
    }
 catch (    IllegalStateException ise) {
      throw ise;
    }
    int readSoFar=0;
    if (ret == null) {
      int startMod=start & bufferMask;
      int endMod=(start + length) & bufferMask;
      int available;
      if (endMod >= startMod) {
        available=bufferLength - endMod;
      }
 else {
        available=startMod - endMod;
      }
      available-=SPARE_BYTES;
      int actual=0;
      try {
        actual=in.read(buffer,endMod,available);
        if (actual > 0 && packetId == -1) {
          packetId=0xFF & buffer[startMod];
        }
        readSoFar+=actual;
        if (readSoFar < 100) {
          try {
            Thread.sleep(10);
          }
 catch (          InterruptedException e) {
            Thread.currentThread().interrupt();
          }
        }
      }
 catch (      SocketTimeoutException ste) {
        continue;
      }
      if (actual == -1) {
        throw new EOFException();
      }
 else {
        length+=actual;
        if (length > buffer.length - 1 - SPARE_BYTES) {
          System.err.println("String_Node_Str");
          System.out.println("String_Node_Str");
          StringBuilder sb=new StringBuilder();
          boolean first=true;
          for (int i=-32; i < 256; i++) {
            if (!first) {
              sb.append("String_Node_Str");
            }
 else {
              first=false;
            }
            int pos=(start + i) & bufferMask;
            if (i == 0) {
              sb.append("String_Node_Str");
            }
            sb.append(Integer.toHexString(buffer[pos] & 0xFF));
            if (i == 0) {
              sb.append("String_Node_Str");
            }
          }
          throw new IOException("String_Node_Str");
        }
      }
    }
  }
  if (interrupted) {
    Thread.currentThread().interrupt();
  }
  if (ret == null) {
    return null;
  }
  int size=ret.end - ret.start;
  start+=size;
  length-=size;
  return ret;
}

Fixed version (ground truth):
public Packet getPacket(Packet packet,int timeout) throws IOException {
  if (packet == null) {
    packet=new Packet();
    packet.buffer=buffer;
    packet.mask=bufferMask;
  }
  Packet ret=null;
  long startTime=System.currentTimeMillis();
  boolean interrupted=false;
  int packetId=-1;
  while (ret == null && length < bufferLength && startTime + timeout > System.currentTimeMillis() && !Thread.currentThread().isInterrupted()) {
    try {
      ret=PacketScan.packetScan(buffer,start,length,bufferMask,packet);
    }
 catch (    IllegalStateException ise) {
      throw ise;
    }
    int readSoFar=0;
    if (ret == null) {
      int startMod=start & bufferMask;
      int endMod=(start + length) & bufferMask;
      int available;
      if (endMod >= startMod) {
        available=bufferLength - endMod;
      }
 else {
        available=startMod - endMod;
      }
      available=Math.min(available,buffer.length - SPARE_BYTES - length);
      int actual=0;
      try {
        actual=in.read(buffer,endMod,available);
        if (actual > 0 && packetId == -1) {
          packetId=0xFF & buffer[startMod];
        }
        readSoFar+=actual;
        if (readSoFar < 100) {
          try {
            Thread.sleep(10);
          }
 catch (          InterruptedException e) {
            Thread.currentThread().interrupt();
          }
        }
      }
 catch (      SocketTimeoutException ste) {
        continue;
      }
      if (actual == -1) {
        throw new EOFException();
      }
 else {
        length+=actual;
        if (length > buffer.length - 1 - SPARE_BYTES) {
          System.err.println("String_Node_Str");
          System.out.println("String_Node_Str");
          StringBuilder sb=new StringBuilder();
          boolean first=true;
          for (int i=-32; i < 256; i++) {
            if (!first) {
              sb.append("String_Node_Str");
            }
 else {
              first=false;
            }
            int pos=(start + i) & bufferMask;
            if (i == 0) {
              sb.append("String_Node_Str");
            }
            sb.append(Integer.toHexString(buffer[pos] & 0xFF));
            if (i == 0) {
              sb.append("String_Node_Str");
            }
          }
          throw new IOException("String_Node_Str");
        }
      }
    }
  }
  if (interrupted) {
    Thread.currentThread().interrupt();
  }
  if (ret == null) {
    return null;
  }
  int size=ret.end - ret.start;
  start+=size;
  length-=size;
  return ret;
}