Program: 178632
Project: 178632
Buggy source:
static final Packet packetScan(byte[] buffer,int start,int dataLength,int mask,Packet packet){
  if (dataLength == 0) {
    return null;
  }
  if (packet == null) {
    packet=new Packet();
  }
  packet.start=start;
  packet.end=start;
  packet.buffer=buffer;
  packet.mask=mask;
  if (mask == 0) {
    return null;
  }
  if (mask + 1 != buffer.length) {
    System.out.println("String_Node_Str");
    System.err.println("String_Node_Str");
    return null;
  }
  int position=start;
  int packetId=buffer[position & mask] & 0xff;
  ProtocolUnitArray.Op[] ops=ProtocolUnitArray.ops[packetId];
  int[] params=ProtocolUnitArray.params[packetId];
  if (ops == null) {
    if (dataLength > 0) {
      System.out.println(packet + "String_Node_Str" + Integer.toHexString(packetId));
      System.err.println(packet + "String_Node_Str" + Integer.toHexString(packetId));
      throw new IllegalStateException("String_Node_Str" + Integer.toHexString(packetId));
    }
    return null;
  }
  int opsLength=ops.length;
  for (int cnt=0; cnt < opsLength; cnt++) {
switch (ops[cnt]) {
case JUMP_FIXED:
{
        position=(position + params[cnt]);
        break;
      }
case BYTE_SIZED:
{
      byte size=getByte(buffer,position,mask);
      position=(position + 1);
      if (size > maxPacketSize) {
        if (position - start <= dataLength) {
          System.err.println("String_Node_Str");
          System.out.println("String_Node_Str");
        }
        return null;
      }
      position=(position + size);
      if (size < 0) {
        return null;
      }
      break;
    }
case SHORT_SIZED:
{
    short size=getShort(buffer,position,mask);
    position=(position + 2);
    if (size > maxPacketSize) {
      if (position - start <= dataLength) {
        System.err.println("String_Node_Str");
        System.out.println("String_Node_Str");
      }
      return null;
    }
    position=(position + size);
    if (size < 0) {
      return null;
    }
    break;
  }
case SHORT_SIZED_DOUBLED:
{
  short size=(short)(getShort(buffer,position,mask) << 1);
  position=(position + 2);
  if (size > maxPacketSize) {
    if (position - start <= dataLength) {
      System.err.println("String_Node_Str");
      System.out.println("String_Node_Str");
    }
    return null;
  }
  position=(position + size);
  if (size < 0) {
    return null;
  }
  break;
}
case SHORT_SIZED_QUAD:
{
short size=(short)(getShort(buffer,position,mask) << 2);
position=(position + 2);
if (size > maxPacketSize) {
  if (position - start <= dataLength) {
    System.err.println("String_Node_Str");
    System.out.println("String_Node_Str");
  }
  return null;
}
position=(position + size);
if (size < 0) {
  return null;
}
break;
}
case INT_SIZED:
{
int size=getInt(buffer,position,mask);
if (packetId == 0x50) {
System.out.println("String_Node_Str" + size);
System.err.println("String_Node_Str" + size);
}
position=(position + 4);
if (size > maxPacketSize) {
if (position - start <= dataLength) {
  System.err.println("String_Node_Str");
  System.out.println("String_Node_Str");
}
return null;
}
position=(position + size);
if (size < 0) {
return null;
}
break;
}
case INT_SIZED_TRIPLE:
{
int size=getInt(buffer,position,mask) * 3;
position=(position + 4);
if (size > maxPacketSize) {
if (position - start <= dataLength) {
System.err.println("String_Node_Str");
System.out.println("String_Node_Str");
}
return null;
}
position=(position + size);
if (size < 0) {
return null;
}
break;
}
case META_DATA:
{
byte b;
do {
int select;
select=(((b=getByte(buffer,position,mask)) & 0xFF) >> 5);
position=(position + 1);
if (b != 127) {
switch (select) {
case 0:
{
  position=(position + 1);
  break;
}
case 1:
{
position=(position + 2);
break;
}
case 2:
case 3:
{
position=(position + 4);
break;
}
case 4:
{
short size=(short)(getShort(buffer,position,mask) << 1);
position=(position + 2);
if (size > maxPacketSize) {
if (position - start <= dataLength) {
System.err.println("String_Node_Str");
System.out.println("String_Node_Str");
}
return null;
}
position=(position + size);
if (size < 0) {
return null;
}
break;
}
default :
{
if (position - start <= dataLength) {
System.err.println("String_Node_Str" + select);
System.out.println("String_Node_Str" + select);
}
return null;
}
}
}
}
 while (b != 127 && position - start <= dataLength);
break;
}
case OPTIONAL_MOTION:
{
int optional=getInt(buffer,position,mask);
position=(position + 4);
if (optional > 0) {
position=position + 6;
}
}
case ITEM:
{
short type=getShort(buffer,position,mask);
position=(position + 2);
if (type != -1) {
position=(position + 3);
}
break;
}
case ITEM_ARRAY:
{
short count=getShort(buffer,position,mask);
position=(position + 2);
if (count > (maxPacketSize >> 3)) {
if (position - start <= dataLength) {
System.err.println("String_Node_Str");
System.out.println("String_Node_Str");
}
return null;
}
for (int c=0; c < count && position - start <= dataLength; c++) {
short type=getShort(buffer,position,mask);
position=(position + 2);
if (type != -1) {
position=(position + 3);
}
}
break;
}
default :
{
if (position - start <= dataLength) {
System.err.println("String_Node_Str" + ops[cnt]);
System.out.println("String_Node_Str" + ops[cnt]);
}
return null;
}
}
}
if (position - start > maxPacketSize) {
return null;
}
if (position - start > dataLength) {
return null;
}
packet.start=start;
packet.end=position;
packet.buffer=buffer;
packet.mask=mask;
return packet;
}

Fixed version (ground truth):
static final Packet packetScan(byte[] buffer,int start,int dataLength,int mask,Packet packet){
  if (dataLength == 0) {
    return null;
  }
  if (packet == null) {
    packet=new Packet();
  }
  packet.start=start;
  packet.end=start;
  packet.buffer=buffer;
  packet.mask=mask;
  if (mask == 0) {
    return null;
  }
  if (mask + 1 != buffer.length) {
    System.out.println("String_Node_Str");
    System.err.println("String_Node_Str");
    return null;
  }
  int position=start;
  int packetId=buffer[position & mask] & 0xff;
  ProtocolUnitArray.Op[] ops=ProtocolUnitArray.ops[packetId];
  int[] params=ProtocolUnitArray.params[packetId];
  if (ops == null) {
    if (dataLength > 0) {
      System.out.println(packet + "String_Node_Str" + Integer.toHexString(packetId));
      System.err.println(packet + "String_Node_Str" + Integer.toHexString(packetId));
      StringBuilder sb=new StringBuilder();
      for (int cnt=-40; cnt < 40 && cnt < dataLength; cnt++) {
        String value=Integer.toHexString(buffer[(start + cnt) & mask] & 0xFF);
        if (cnt != 0) {
          sb.append(value + "String_Node_Str");
        }
 else {
          sb.append("String_Node_Str" + value + "String_Node_Str");
        }
      }
      System.err.println(packet + sb.toString());
      throw new IllegalStateException("String_Node_Str" + Integer.toHexString(packetId));
    }
    return null;
  }
  int opsLength=ops.length;
  for (int cnt=0; cnt < opsLength; cnt++) {
switch (ops[cnt]) {
case JUMP_FIXED:
{
        position=(position + params[cnt]);
        break;
      }
case BYTE_SIZED:
{
      byte size=getByte(buffer,position,mask);
      position=(position + 1);
      if (size > maxPacketSize) {
        if (position - start <= dataLength) {
          System.err.println("String_Node_Str");
          System.out.println("String_Node_Str");
        }
        return null;
      }
      position=(position + size);
      if (size < 0) {
        return null;
      }
      break;
    }
case SHORT_SIZED:
{
    short size=getShort(buffer,position,mask);
    position=(position + 2);
    if (size > maxPacketSize) {
      if (position - start <= dataLength) {
        System.err.println("String_Node_Str");
        System.out.println("String_Node_Str");
      }
      return null;
    }
    position=(position + size);
    if (size < 0) {
      return null;
    }
    break;
  }
case SHORT_SIZED_DOUBLED:
{
  short size=(short)(getShort(buffer,position,mask) << 1);
  position=(position + 2);
  if (size > maxPacketSize) {
    if (position - start <= dataLength) {
      System.err.println("String_Node_Str");
      System.out.println("String_Node_Str");
    }
    return null;
  }
  position=(position + size);
  if (size < 0) {
    return null;
  }
  break;
}
case SHORT_SIZED_QUAD:
{
short size=(short)(getShort(buffer,position,mask) << 2);
position=(position + 2);
if (size > maxPacketSize) {
  if (position - start <= dataLength) {
    System.err.println("String_Node_Str");
    System.out.println("String_Node_Str");
  }
  return null;
}
position=(position + size);
if (size < 0) {
  return null;
}
break;
}
case INT_SIZED:
{
int size=getInt(buffer,position,mask);
if (packetId == 0x50) {
System.out.println("String_Node_Str" + size);
System.err.println("String_Node_Str" + size);
}
position=(position + 4);
if (size > maxPacketSize) {
if (position - start <= dataLength) {
  System.err.println("String_Node_Str");
  System.out.println("String_Node_Str");
}
return null;
}
position=(position + size);
if (size < 0) {
return null;
}
break;
}
case INT_SIZED_TRIPLE:
{
int size=getInt(buffer,position,mask) * 3;
position=(position + 4);
if (size > maxPacketSize) {
if (position - start <= dataLength) {
System.err.println("String_Node_Str");
System.out.println("String_Node_Str");
}
return null;
}
position=(position + size);
if (size < 0) {
return null;
}
break;
}
case META_DATA:
{
byte b;
do {
int select;
select=(((b=getByte(buffer,position,mask)) & 0xFF) >> 5);
position=(position + 1);
if (b != 127) {
switch (select) {
case 0:
{
  position=(position + 1);
  break;
}
case 1:
{
position=(position + 2);
break;
}
case 2:
case 3:
{
position=(position + 4);
break;
}
case 4:
{
short size=(short)(getShort(buffer,position,mask) << 1);
position=(position + 2);
if (size > maxPacketSize) {
if (position - start <= dataLength) {
System.err.println("String_Node_Str");
System.out.println("String_Node_Str");
}
return null;
}
position=(position + size);
if (size < 0) {
return null;
}
break;
}
default :
{
if (position - start <= dataLength) {
System.err.println("String_Node_Str" + select);
System.out.println("String_Node_Str" + select);
}
return null;
}
}
}
}
 while (b != 127 && position - start <= dataLength);
break;
}
case OPTIONAL_MOTION:
{
int optional=getInt(buffer,position,mask);
position=(position + 4);
if (optional > 0) {
position=position + 6;
}
break;
}
case ITEM:
{
short type=getShort(buffer,position,mask);
position=(position + 2);
if (type != -1) {
position=(position + 3);
}
break;
}
case ITEM_ARRAY:
{
short count=getShort(buffer,position,mask);
position=(position + 2);
if (count > (maxPacketSize >> 3)) {
if (position - start <= dataLength) {
System.err.println("String_Node_Str");
System.out.println("String_Node_Str");
}
return null;
}
for (int c=0; c < count && position - start <= dataLength; c++) {
short type=getShort(buffer,position,mask);
position=(position + 2);
if (type != -1) {
position=(position + 3);
}
}
break;
}
default :
{
if (position - start <= dataLength) {
System.err.println("String_Node_Str" + ops[cnt]);
System.out.println("String_Node_Str" + ops[cnt]);
}
return null;
}
}
}
if (position - start > maxPacketSize) {
return null;
}
if (position - start > dataLength) {
return null;
}
packet.start=start;
packet.end=position;
packet.buffer=buffer;
packet.mask=mask;
return packet;
}