Program: 156219
Project: 156219
Buggy source:
@Override protected Object decode(ChannelHandlerContext ctx,Channel channel,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.skipBytes(2);
  int length=buf.readByte();
  int dataLength=length - 5;
  int type=buf.readUnsignedByte();
  if (type == MSG_LOGIN) {
    String imei=readImei(buf);
    try {
      deviceId=getDataManager().getDeviceByImei(imei).getId();
      buf.skipBytes(dataLength - 8);
      sendResponse(channel,type,buf.readUnsignedShort());
    }
 catch (    Exception error) {
      Log.warning("String_Node_Str" + imei);
    }
  }
 else   if (type == MSG_GPS || type == MSG_GPS_LBS || type == MSG_GPS_LBS_STATUS || type == MSG_GPS_PHONE) {
    Position position=new Position();
    position.setDeviceId(deviceId);
    ExtendedInfoFormatter extendedInfo=new ExtendedInfoFormatter("String_Node_Str");
    Calendar time=Calendar.getInstance(TimeZone.getTimeZone("String_Node_Str"));
    time.clear();
    time.set(Calendar.YEAR,2000 + buf.readUnsignedByte());
    time.set(Calendar.MONTH,buf.readUnsignedByte() - 1);
    time.set(Calendar.DAY_OF_MONTH,buf.readUnsignedByte());
    time.set(Calendar.HOUR,buf.readUnsignedByte());
    time.set(Calendar.MINUTE,buf.readUnsignedByte());
    time.set(Calendar.SECOND,buf.readUnsignedByte());
    position.setTime(time.getTime());
    int gpsLength=buf.readUnsignedByte();
    extendedInfo.set("String_Node_Str",gpsLength & 0xf);
    gpsLength>>=4;
    double latitude=buf.readUnsignedInt() / (60.0 * 30000.0);
    double longitude=buf.readUnsignedInt() / (60.0 * 30000.0);
    position.setSpeed(buf.readUnsignedByte() * 0.539957);
    int union=buf.readUnsignedShort();
    position.setCourse((double)(union & 0x03FF));
    position.setValid((union & 0x1000) != 0);
    if ((union & 0x0400) == 0)     latitude=-latitude;
    if ((union & 0x0800) != 0)     longitude=-longitude;
    position.setLatitude(latitude);
    position.setLongitude(longitude);
    position.setAltitude(0.0);
    buf.skipBytes(gpsLength - 12);
    if (type == MSG_GPS_LBS || type == MSG_GPS_LBS_STATUS) {
      int lbsLength=0;
      if (type == MSG_GPS_LBS_STATUS) {
        lbsLength=buf.readUnsignedByte();
      }
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort());
      extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort());
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort() << 8 + buf.readUnsignedByte());
      buf.skipBytes(lbsLength - 9);
      if (type == MSG_GPS_LBS_STATUS) {
        extendedInfo.set("String_Node_Str",true);
        int flags=buf.readUnsignedByte();
        extendedInfo.set("String_Node_Str",(flags & 0x2) != 0);
        extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
        extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
      }
    }
    if (buf.readableBytes() > 6) {
      buf.skipBytes(buf.readableBytes() - 6);
    }
    int index=buf.readUnsignedShort();
    extendedInfo.set("String_Node_Str",index);
    sendResponse(channel,type,index);
    position.setExtendedInfo(extendedInfo.toString());
    return position;
  }
 else {
    buf.skipBytes(dataLength);
    sendResponse(channel,type,buf.readUnsignedShort());
  }
  return null;
}

Fixed version (ground truth):
@Override protected Object decode(ChannelHandlerContext ctx,Channel channel,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.skipBytes(2);
  int length=buf.readByte();
  int dataLength=length - 5;
  int type=buf.readUnsignedByte();
  if (type == MSG_LOGIN) {
    String imei=readImei(buf);
    buf.readUnsignedShort();
    if (dataLength > 10) {
      int extensionBits=buf.readUnsignedShort();
      int offset=(extensionBits >> 4) * 36000;
      if ((extensionBits & 0x8) != 0) {
        offset=-offset;
      }
      timeZone.setRawOffset(offset);
    }
    try {
      deviceId=getDataManager().getDeviceByImei(imei).getId();
      buf.skipBytes(dataLength - 8);
      sendResponse(channel,type,buf.readUnsignedShort());
    }
 catch (    Exception error) {
      Log.warning("String_Node_Str" + imei);
    }
  }
 else   if (type == MSG_GPS || type == MSG_GPS_LBS || type == MSG_GPS_LBS_STATUS || type == MSG_GPS_PHONE) {
    Position position=new Position();
    position.setDeviceId(deviceId);
    ExtendedInfoFormatter extendedInfo=new ExtendedInfoFormatter("String_Node_Str");
    Calendar time=Calendar.getInstance(timeZone);
    time.clear();
    time.set(Calendar.YEAR,2000 + buf.readUnsignedByte());
    time.set(Calendar.MONTH,buf.readUnsignedByte() - 1);
    time.set(Calendar.DAY_OF_MONTH,buf.readUnsignedByte());
    time.set(Calendar.HOUR,buf.readUnsignedByte());
    time.set(Calendar.MINUTE,buf.readUnsignedByte());
    time.set(Calendar.SECOND,buf.readUnsignedByte());
    position.setTime(time.getTime());
    int gpsLength=buf.readUnsignedByte();
    extendedInfo.set("String_Node_Str",gpsLength & 0xf);
    gpsLength>>=4;
    double latitude=buf.readUnsignedInt() / (60.0 * 30000.0);
    double longitude=buf.readUnsignedInt() / (60.0 * 30000.0);
    position.setSpeed(buf.readUnsignedByte() * 0.539957);
    int union=buf.readUnsignedShort();
    position.setCourse((double)(union & 0x03FF));
    position.setValid((union & 0x1000) != 0);
    if ((union & 0x0400) == 0)     latitude=-latitude;
    if ((union & 0x0800) != 0)     longitude=-longitude;
    position.setLatitude(latitude);
    position.setLongitude(longitude);
    position.setAltitude(0.0);
    buf.skipBytes(gpsLength - 12);
    if (type == MSG_GPS_LBS || type == MSG_GPS_LBS_STATUS) {
      int lbsLength=0;
      if (type == MSG_GPS_LBS_STATUS) {
        lbsLength=buf.readUnsignedByte();
      }
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort());
      extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort());
      extendedInfo.set("String_Node_Str",buf.readUnsignedShort() << 8 + buf.readUnsignedByte());
      buf.skipBytes(lbsLength - 9);
      if (type == MSG_GPS_LBS_STATUS) {
        extendedInfo.set("String_Node_Str",true);
        int flags=buf.readUnsignedByte();
        extendedInfo.set("String_Node_Str",(flags & 0x2) != 0);
        extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
        extendedInfo.set("String_Node_Str",buf.readUnsignedByte());
      }
    }
    if (buf.readableBytes() > 6) {
      buf.skipBytes(buf.readableBytes() - 6);
    }
    int index=buf.readUnsignedShort();
    extendedInfo.set("String_Node_Str",index);
    sendResponse(channel,type,index);
    position.setExtendedInfo(extendedInfo.toString());
    return position;
  }
 else {
    buf.skipBytes(dataLength);
    sendResponse(channel,type,buf.readUnsignedShort());
  }
  return null;
}