Program: 111589
Project: 111589
Buggy source:
public void handleRect(int x,int y,int w,int h) throws Exception {
  if (dos != null) {
    dos.writeInt(TightDecoder.EncodingTight);
  }
  int comp_ctl=rfbis.readU8();
  if (rec.canWrite()) {
    if (rec.isRecordFromBeginning() || comp_ctl == (TightFill << 4) || comp_ctl == (TightJpeg << 4)) {
      rec.writeByte(comp_ctl);
    }
 else {
      rec.writeByte(comp_ctl | 0x0F);
    }
  }
  for (int stream_id=0; stream_id < 4; stream_id++) {
    if ((comp_ctl & 1) != 0 && tightInflaters[stream_id] != null) {
      tightInflaters[stream_id]=null;
    }
    comp_ctl>>=1;
  }
  if (comp_ctl > TightDecoder.TightMaxSubencoding) {
    throw new Exception("String_Node_Str" + comp_ctl);
  }
  if (comp_ctl == TightDecoder.TightFill) {
    if (bytesPerPixel == 1) {
      int idx=rfbis.readU8();
      graphics.setColor(getColor256()[idx]);
      if (rec.canWrite()) {
        rec.writeByte(idx);
      }
    }
 else {
      byte[] buf=new byte[3];
      rfbis.readFully(buf);
      if (rec.canWrite()) {
        rec.write(buf);
      }
      Color bg=new Color(0xFF000000 | (buf[0] & 0xFF) << 16 | (buf[1] & 0xFF) << 8 | (buf[2] & 0xFF));
      graphics.setColor(bg);
    }
    graphics.fillRect(x,y,w,h);
    repainatableControl.scheduleRepaint(x,y,w,h);
    return;
  }
  if (comp_ctl == TightDecoder.TightJpeg) {
    statNumRectsTightJPEG++;
    byte[] jpegData=new byte[rfbis.readCompactLen()];
    rfbis.readFully(jpegData);
    if (rec.canWrite()) {
      if (!rec.isRecordFromBeginning()) {
        rec.recordCompactLen(jpegData.length);
      }
      rec.write(jpegData);
    }
    Image jpegImage=Toolkit.getDefaultToolkit().createImage(jpegData);
    jpegRect=new Rectangle(x,y,w,h);
synchronized (jpegRect) {
      Toolkit.getDefaultToolkit().prepareImage(jpegImage,-1,-1,this);
      try {
        jpegRect.wait(3000);
      }
 catch (      InterruptedException e) {
        throw new Exception("String_Node_Str");
      }
    }
    jpegRect=null;
    return;
  }
  int numColors=0, rowSize=w;
  byte[] palette8=new byte[2];
  int[] palette24=new int[256];
  boolean useGradient=false;
  if ((comp_ctl & TightDecoder.TightExplicitFilter) != 0) {
    int filter_id=rfbis.readU8();
    if (rec.canWrite()) {
      rec.writeByte(filter_id);
    }
    if (filter_id == TightDecoder.TightFilterPalette) {
      numColors=rfbis.readU8() + 1;
      if (rec.canWrite()) {
        rec.writeByte((numColors - 1));
      }
      if (bytesPerPixel == 1) {
        if (numColors != 2) {
          throw new Exception("String_Node_Str" + numColors);
        }
        rfbis.readFully(palette8);
        if (rec.canWrite()) {
          rec.write(palette8);
        }
      }
 else {
        byte[] buf=new byte[numColors * 3];
        rfbis.readFully(buf);
        if (rec.canWrite()) {
          rec.write(buf);
        }
        for (int i=0; i < numColors; i++) {
          palette24[i]=((buf[i * 3] & 0xFF) << 16 | (buf[i * 3 + 1] & 0xFF) << 8 | (buf[i * 3 + 2] & 0xFF));
        }
      }
      if (numColors == 2) {
        rowSize=(w + 7) / 8;
      }
    }
 else     if (filter_id == TightDecoder.TightFilterGradient) {
      useGradient=true;
    }
 else     if (filter_id != TightDecoder.TightFilterCopy) {
      throw new Exception("String_Node_Str" + filter_id);
    }
  }
  if (numColors == 0 && bytesPerPixel == 4)   rowSize*=3;
  int dataSize=h * rowSize;
  if (dataSize < TightDecoder.TightMinToCompress) {
    if (numColors != 0) {
      byte[] indexedData=new byte[dataSize];
      rfbis.readFully(indexedData);
      if (rec.canWrite()) {
        rec.write(indexedData);
      }
      if (numColors == 2) {
        if (bytesPerPixel == 1) {
          decodeMonoData(x,y,w,h,indexedData,palette8);
        }
 else {
          decodeMonoData(x,y,w,h,indexedData,palette24);
        }
      }
 else {
        int i=0;
        for (int dy=y; dy < y + h; dy++) {
          for (int dx=x; dx < x + w; dx++) {
            pixels24[dy * framebufferWidth + dx]=palette24[indexedData[i++] & 0xFF];
          }
        }
      }
    }
 else     if (useGradient) {
      byte[] buf=new byte[w * h * 3];
      rfbis.readFully(buf);
      if (rec.canWrite()) {
        rec.write(buf);
      }
      decodeGradientData(x,y,w,h,buf);
    }
 else {
      if (bytesPerPixel == 1) {
        for (int dy=y; dy < y + h; dy++) {
          rfbis.readFully(pixels8,dy * framebufferWidth + x,w);
          if (rec.canWrite()) {
            rec.write(pixels8,dy * framebufferWidth + x,w);
          }
        }
      }
 else {
        byte[] buf=new byte[w * 3];
        int i, offset;
        for (int dy=y; dy < y + h; dy++) {
          rfbis.readFully(buf);
          if (rec.canWrite()) {
            rec.write(buf);
          }
          offset=dy * framebufferWidth + x;
          for (i=0; i < w; i++) {
            pixels24[offset + i]=(buf[i * 3] & 0xFF) << 16 | (buf[i * 3 + 1] & 0xFF) << 8 | (buf[i * 3 + 2] & 0xFF);
          }
        }
      }
    }
  }
 else {
    int zlibDataLen=rfbis.readCompactLen();
    byte[] zlibData=new byte[zlibDataLen];
    rfbis.readFully(zlibData);
    if ((rec.canWrite()) && (rec.isRecordFromBeginning())) {
      rec.write(zlibData);
    }
    int stream_id=comp_ctl & 0x03;
    if (tightInflaters[stream_id] == null) {
      tightInflaters[stream_id]=new Inflater();
    }
    Inflater myInflater=tightInflaters[stream_id];
    myInflater.setInput(zlibData);
    byte[] buf=new byte[dataSize];
    myInflater.inflate(buf);
    if ((rec.canWrite()) && (!rec.isRecordFromBeginning())) {
      rec.recordCompressedData(buf);
    }
    if (numColors != 0) {
      if (numColors == 2) {
        if (bytesPerPixel == 1) {
          decodeMonoData(x,y,w,h,buf,palette8);
        }
 else {
          decodeMonoData(x,y,w,h,buf,palette24);
        }
      }
 else {
        int i=0;
        for (int dy=y; dy < y + h; dy++) {
          for (int dx=x; dx < x + w; dx++) {
            pixels24[dy * framebufferWidth + dx]=palette24[buf[i++] & 0xFF];
          }
        }
      }
    }
 else     if (useGradient) {
      decodeGradientData(x,y,w,h,buf);
    }
 else {
      if (bytesPerPixel == 1) {
        int destOffset=y * framebufferWidth + x;
        for (int dy=0; dy < h; dy++) {
          System.arraycopy(buf,dy * w,pixels8,destOffset,w);
          destOffset+=framebufferWidth;
        }
      }
 else {
        int srcOffset=0;
        int destOffset, i;
        for (int dy=0; dy < h; dy++) {
          myInflater.inflate(buf);
          destOffset=(y + dy) * framebufferWidth + x;
          for (i=0; i < w; i++) {
            RawDecoder.pixels24[destOffset + i]=(buf[srcOffset] & 0xFF) << 16 | (buf[srcOffset + 1] & 0xFF) << 8 | (buf[srcOffset + 2] & 0xFF);
            srcOffset+=3;
          }
        }
      }
    }
  }
  handleUpdatedPixels(x,y,w,h);
}

Fixed version (ground truth):
public void handleRect(int x,int y,int w,int h) throws Exception {
  if (dos != null) {
    dos.writeInt(TightDecoder.EncodingTight);
  }
  int comp_ctl=rfbis.readU8();
  if (rec.canWrite()) {
    if (rec.isRecordFromBeginning() || comp_ctl == (TightFill << 4) || comp_ctl == (TightJpeg << 4)) {
      rec.writeByte(comp_ctl);
    }
 else {
      rec.writeByte(comp_ctl | 0x0F);
    }
  }
  for (int stream_id=0; stream_id < 4; stream_id++) {
    if ((comp_ctl & 1) != 0 && tightInflaters[stream_id] != null) {
      tightInflaters[stream_id]=null;
    }
    comp_ctl>>=1;
  }
  if (comp_ctl > TightDecoder.TightMaxSubencoding) {
    throw new Exception("String_Node_Str" + comp_ctl);
  }
  if (comp_ctl == TightDecoder.TightFill) {
    if (bytesPerPixel == 1) {
      int idx=rfbis.readU8();
      graphics.setColor(getColor256()[idx]);
      if (rec.canWrite()) {
        rec.writeByte(idx);
      }
    }
 else {
      byte[] buf=new byte[3];
      rfbis.readFully(buf);
      if (rec.canWrite()) {
        rec.write(buf);
      }
      Color bg=new Color(0xFF000000 | (buf[0] & 0xFF) << 16 | (buf[1] & 0xFF) << 8 | (buf[2] & 0xFF));
      graphics.setColor(bg);
    }
    graphics.fillRect(x,y,w,h);
    repainatableControl.scheduleRepaint(x,y,w,h);
    return;
  }
  if (comp_ctl == TightDecoder.TightJpeg) {
    statNumRectsTightJPEG++;
    byte[] jpegData=new byte[rfbis.readCompactLen()];
    rfbis.readFully(jpegData);
    if (rec.canWrite()) {
      if (!rec.isRecordFromBeginning()) {
        rec.recordCompactLen(jpegData.length);
      }
      rec.write(jpegData);
    }
    Image jpegImage=Toolkit.getDefaultToolkit().createImage(jpegData);
    jpegRect=new Rectangle(x,y,w,h);
synchronized (jpegRect) {
      Toolkit.getDefaultToolkit().prepareImage(jpegImage,-1,-1,this);
      try {
        jpegRect.wait(3000);
      }
 catch (      InterruptedException e) {
        throw new Exception("String_Node_Str");
      }
    }
    jpegRect=null;
    return;
  }
 else {
    statNumRectsTight++;
  }
  int numColors=0, rowSize=w;
  byte[] palette8=new byte[2];
  int[] palette24=new int[256];
  boolean useGradient=false;
  if ((comp_ctl & TightDecoder.TightExplicitFilter) != 0) {
    int filter_id=rfbis.readU8();
    if (rec.canWrite()) {
      rec.writeByte(filter_id);
    }
    if (filter_id == TightDecoder.TightFilterPalette) {
      numColors=rfbis.readU8() + 1;
      if (rec.canWrite()) {
        rec.writeByte((numColors - 1));
      }
      if (bytesPerPixel == 1) {
        if (numColors != 2) {
          throw new Exception("String_Node_Str" + numColors);
        }
        rfbis.readFully(palette8);
        if (rec.canWrite()) {
          rec.write(palette8);
        }
      }
 else {
        byte[] buf=new byte[numColors * 3];
        rfbis.readFully(buf);
        if (rec.canWrite()) {
          rec.write(buf);
        }
        for (int i=0; i < numColors; i++) {
          palette24[i]=((buf[i * 3] & 0xFF) << 16 | (buf[i * 3 + 1] & 0xFF) << 8 | (buf[i * 3 + 2] & 0xFF));
        }
      }
      if (numColors == 2) {
        rowSize=(w + 7) / 8;
      }
    }
 else     if (filter_id == TightDecoder.TightFilterGradient) {
      useGradient=true;
    }
 else     if (filter_id != TightDecoder.TightFilterCopy) {
      throw new Exception("String_Node_Str" + filter_id);
    }
  }
  if (numColors == 0 && bytesPerPixel == 4)   rowSize*=3;
  int dataSize=h * rowSize;
  if (dataSize < TightDecoder.TightMinToCompress) {
    if (numColors != 0) {
      byte[] indexedData=new byte[dataSize];
      rfbis.readFully(indexedData);
      if (rec.canWrite()) {
        rec.write(indexedData);
      }
      if (numColors == 2) {
        if (bytesPerPixel == 1) {
          decodeMonoData(x,y,w,h,indexedData,palette8);
        }
 else {
          decodeMonoData(x,y,w,h,indexedData,palette24);
        }
      }
 else {
        int i=0;
        for (int dy=y; dy < y + h; dy++) {
          for (int dx=x; dx < x + w; dx++) {
            pixels24[dy * framebufferWidth + dx]=palette24[indexedData[i++] & 0xFF];
          }
        }
      }
    }
 else     if (useGradient) {
      byte[] buf=new byte[w * h * 3];
      rfbis.readFully(buf);
      if (rec.canWrite()) {
        rec.write(buf);
      }
      decodeGradientData(x,y,w,h,buf);
    }
 else {
      if (bytesPerPixel == 1) {
        for (int dy=y; dy < y + h; dy++) {
          rfbis.readFully(pixels8,dy * framebufferWidth + x,w);
          if (rec.canWrite()) {
            rec.write(pixels8,dy * framebufferWidth + x,w);
          }
        }
      }
 else {
        byte[] buf=new byte[w * 3];
        int i, offset;
        for (int dy=y; dy < y + h; dy++) {
          rfbis.readFully(buf);
          if (rec.canWrite()) {
            rec.write(buf);
          }
          offset=dy * framebufferWidth + x;
          for (i=0; i < w; i++) {
            pixels24[offset + i]=(buf[i * 3] & 0xFF) << 16 | (buf[i * 3 + 1] & 0xFF) << 8 | (buf[i * 3 + 2] & 0xFF);
          }
        }
      }
    }
  }
 else {
    int zlibDataLen=rfbis.readCompactLen();
    byte[] zlibData=new byte[zlibDataLen];
    rfbis.readFully(zlibData);
    if ((rec.canWrite()) && (rec.isRecordFromBeginning())) {
      rec.write(zlibData);
    }
    int stream_id=comp_ctl & 0x03;
    if (tightInflaters[stream_id] == null) {
      tightInflaters[stream_id]=new Inflater();
    }
    Inflater myInflater=tightInflaters[stream_id];
    myInflater.setInput(zlibData);
    byte[] buf=new byte[dataSize];
    myInflater.inflate(buf);
    if ((rec.canWrite()) && (!rec.isRecordFromBeginning())) {
      rec.recordCompressedData(buf);
    }
    if (numColors != 0) {
      if (numColors == 2) {
        if (bytesPerPixel == 1) {
          decodeMonoData(x,y,w,h,buf,palette8);
        }
 else {
          decodeMonoData(x,y,w,h,buf,palette24);
        }
      }
 else {
        int i=0;
        for (int dy=y; dy < y + h; dy++) {
          for (int dx=x; dx < x + w; dx++) {
            pixels24[dy * framebufferWidth + dx]=palette24[buf[i++] & 0xFF];
          }
        }
      }
    }
 else     if (useGradient) {
      decodeGradientData(x,y,w,h,buf);
    }
 else {
      if (bytesPerPixel == 1) {
        int destOffset=y * framebufferWidth + x;
        for (int dy=0; dy < h; dy++) {
          System.arraycopy(buf,dy * w,pixels8,destOffset,w);
          destOffset+=framebufferWidth;
        }
      }
 else {
        int srcOffset=0;
        int destOffset, i;
        for (int dy=0; dy < h; dy++) {
          myInflater.inflate(buf);
          destOffset=(y + dy) * framebufferWidth + x;
          for (i=0; i < w; i++) {
            RawDecoder.pixels24[destOffset + i]=(buf[srcOffset] & 0xFF) << 16 | (buf[srcOffset + 1] & 0xFF) << 8 | (buf[srcOffset + 2] & 0xFF);
            srcOffset+=3;
          }
        }
      }
    }
  }
  handleUpdatedPixels(x,y,w,h);
}