Program: 111555
Project: 111555
Buggy source:
public void readRect(Rect r,CMsgHandler handler){
  InStream is=reader.getInStream();
  boolean cutZeros=false;
  clientpf=handler.getPreferredPF();
  serverpf=handler.cp.pf();
  int bpp=serverpf.bpp;
  cutZeros=false;
  if (bpp == 32) {
    if (serverpf.is888()) {
      cutZeros=true;
    }
  }
  int comp_ctl=is.readU8();
  boolean bigEndian=handler.cp.pf().bigEndian;
  for (int i=0; i < 4; i++) {
    if ((comp_ctl & 1) != 0) {
      zis[i].reset();
    }
    comp_ctl>>=1;
  }
  if (comp_ctl == rfbTightFill) {
    int[] pix=new int[1];
    if (cutZeros) {
      byte[] bytebuf=new byte[3];
      is.readBytes(bytebuf,0,3);
      serverpf.bufferFromRGB(pix,0,bytebuf,0,1);
    }
 else {
      pix[0]=is.readPixel(serverpf.bpp / 8,serverpf.bigEndian);
    }
    handler.fillRect(r,pix[0]);
    return;
  }
  if (comp_ctl == rfbTightJpeg) {
    DECOMPRESS_JPEG_RECT(r,is,handler);
    return;
  }
  if (comp_ctl > rfbTightMaxSubencoding) {
    throw new Exception("String_Node_Str");
  }
  int palSize=0;
  int[] palette=new int[256];
  boolean useGradient=false;
  if ((comp_ctl & rfbTightExplicitFilter) != 0) {
    int filterId=is.readU8();
switch (filterId) {
case rfbTightFilterPalette:
      palSize=is.readU8() + 1;
    byte[] tightPalette;
  if (cutZeros) {
    tightPalette=new byte[256 * 3];
    is.readBytes(tightPalette,0,palSize * 3);
    serverpf.bufferFromRGB(palette,0,tightPalette,0,palSize);
  }
 else {
    is.readPixels(palette,palSize,serverpf.bpp / 8,serverpf.bigEndian);
  }
break;
case rfbTightFilterGradient:
useGradient=true;
break;
case rfbTightFilterCopy:
break;
default :
throw new Exception("String_Node_Str");
}
}
int bppp=bpp;
if (palSize != 0) {
bppp=(palSize <= 2) ? 1 : 8;
}
 else if (cutZeros) {
bppp=24;
}
int rowSize=(r.width() * bppp + 7) / 8;
int dataSize=r.height() * rowSize;
int streamId=-1;
InStream input;
if (dataSize < rfbTightMinToCompress) {
input=is;
}
 else {
int length=is.readCompactLength();
streamId=comp_ctl & 0x03;
zis[streamId].setUnderlying(is,length);
input=(ZlibInStream)zis[streamId];
}
byte[] netbuf=new byte[dataSize];
input.readBytes(netbuf,0,dataSize);
int stride=r.width();
int[] buf=reader.getImageBuf(r.area());
if (palSize == 0) {
if (useGradient) {
if (bpp == 32 && cutZeros) {
FilterGradient24(netbuf,buf,stride,r);
}
 else {
FilterGradient(netbuf,buf,stride,r);
}
}
 else {
int h=r.height();
int w=r.width();
if (cutZeros) {
serverpf.bufferFromRGB(buf,0,netbuf,0,w * h);
}
 else {
for (int i=0; i < dataSize; i++) buf[i]=netbuf[i] & 0xff;
}
}
}
 else {
int x, h=r.height(), w=r.width(), b, pad=stride - w;
int ptr=0;
int srcPtr=0, bits;
if (palSize <= 2) {
while (h > 0) {
for (x=0; x < w / 8; x++) {
bits=netbuf[srcPtr++];
for (b=7; b >= 0; b--) {
buf[ptr++]=palette[bits >> b & 1];
}
}
if (w % 8 != 0) {
bits=netbuf[srcPtr++];
for (b=7; b >= 8 - w % 8; b--) {
buf[ptr++]=palette[bits >> b & 1];
}
}
ptr+=pad;
h--;
}
}
 else {
while (h > 0) {
int endOfRow=ptr + w;
while (ptr < endOfRow) {
buf[ptr++]=palette[netbuf[srcPtr++] & 0xff];
}
ptr+=pad;
h--;
}
}
}
handler.imageRect(r,buf);
if (streamId != -1) {
zis[streamId].reset();
}
}

Fixed version (ground truth):
public void readRect(Rect r,CMsgHandler handler){
  InStream is=reader.getInStream();
  boolean cutZeros=false;
  clientpf=handler.getPreferredPF();
  serverpf=handler.cp.pf();
  int bpp=serverpf.bpp;
  cutZeros=false;
  if (bpp == 32) {
    if (serverpf.is888()) {
      cutZeros=true;
    }
  }
  int comp_ctl=is.readU8();
  boolean bigEndian=handler.cp.pf().bigEndian;
  for (int i=0; i < 4; i++) {
    if ((comp_ctl & 1) != 0) {
      zis[i].reset();
    }
    comp_ctl>>=1;
  }
  if (comp_ctl == rfbTightFill) {
    int[] pix=new int[1];
    if (cutZeros) {
      byte[] bytebuf=new byte[3];
      is.readBytes(bytebuf,0,3);
      serverpf.bufferFromRGB(pix,0,bytebuf,0,1);
    }
 else {
      pix[0]=is.readPixel(serverpf.bpp / 8,serverpf.bigEndian);
    }
    handler.fillRect(r,pix[0]);
    return;
  }
  if (comp_ctl == rfbTightJpeg) {
    DECOMPRESS_JPEG_RECT(r,is,handler);
    return;
  }
  if (comp_ctl > rfbTightMaxSubencoding) {
    throw new Exception("String_Node_Str");
  }
  int palSize=0;
  int[] palette=new int[256];
  boolean useGradient=false;
  if ((comp_ctl & rfbTightExplicitFilter) != 0) {
    int filterId=is.readU8();
switch (filterId) {
case rfbTightFilterPalette:
      palSize=is.readU8() + 1;
    byte[] tightPalette;
  if (cutZeros) {
    tightPalette=new byte[256 * 3];
    is.readBytes(tightPalette,0,palSize * 3);
    serverpf.bufferFromRGB(palette,0,tightPalette,0,palSize);
  }
 else {
    is.readPixels(palette,palSize,serverpf.bpp / 8,serverpf.bigEndian);
  }
break;
case rfbTightFilterGradient:
useGradient=true;
break;
case rfbTightFilterCopy:
break;
default :
throw new Exception("String_Node_Str");
}
}
int bppp=bpp;
if (palSize != 0) {
bppp=(palSize <= 2) ? 1 : 8;
}
 else if (cutZeros) {
bppp=24;
}
int rowSize=(r.width() * bppp + 7) / 8;
int dataSize=r.height() * rowSize;
int streamId=-1;
InStream input;
if (dataSize < rfbTightMinToCompress) {
input=is;
}
 else {
int length=is.readCompactLength();
streamId=comp_ctl & 0x03;
zis[streamId].setUnderlying(is,length);
input=(ZlibInStream)zis[streamId];
}
byte[] netbuf=new byte[dataSize];
input.readBytes(netbuf,0,dataSize);
int stride=r.width();
int[] buf=reader.getImageBuf(r.area());
if (palSize == 0) {
if (useGradient) {
if (bpp == 32 && cutZeros) {
FilterGradient24(netbuf,buf,stride,r);
}
 else {
FilterGradient(netbuf,buf,stride,r);
}
}
 else {
int h=r.height();
int ptr=0;
int srcPtr=0;
int w=r.width();
if (cutZeros) {
serverpf.bufferFromRGB(buf,ptr,netbuf,srcPtr,w * h);
}
 else {
int pixelSize=(bpp >= 24) ? 3 : bpp / 8;
while (h > 0) {
for (int i=0; i < w; i++) {
if (bpp == 8) {
buf[ptr + i]=netbuf[srcPtr + i] & 0xff;
}
 else {
for (int j=pixelSize - 1; j >= 0; j--) buf[ptr + i]|=((netbuf[srcPtr + i + j] & 0xff) << j * 8);
}
}
ptr+=stride;
srcPtr+=w * pixelSize;
h--;
}
}
}
}
 else {
int x, h=r.height(), w=r.width(), b, pad=stride - w;
int ptr=0;
int srcPtr=0, bits;
if (palSize <= 2) {
while (h > 0) {
for (x=0; x < w / 8; x++) {
bits=netbuf[srcPtr++];
for (b=7; b >= 0; b--) {
buf[ptr++]=palette[bits >> b & 1];
}
}
if (w % 8 != 0) {
bits=netbuf[srcPtr++];
for (b=7; b >= 8 - w % 8; b--) {
buf[ptr++]=palette[bits >> b & 1];
}
}
ptr+=pad;
h--;
}
}
 else {
while (h > 0) {
int endOfRow=ptr + w;
while (ptr < endOfRow) {
buf[ptr++]=palette[netbuf[srcPtr++] & 0xff];
}
ptr+=pad;
h--;
}
}
}
handler.imageRect(r,buf);
if (streamId != -1) {
zis[streamId].reset();
}
}