Program: 63814
Project: 63814
Buggy source:
public int write(ByteBuffer inBuf) throws IOException {
  int length=inBuf.remaining();
  ByteBuffer out=this.inner.getWriteBuffer();
  ByteBuffer slowBuffer=ByteBuffer.allocate(20);
  int inPtr=inBuf.position();
  int inEnd=inPtr + length;
  while (inPtr < inEnd) {
    if (out.remaining() < 10) {
      if (out == slowBuffer) {
        int oldLimit=out.limit();
        out.limit(out.position());
        out.rewind();
        this.inner.write(out);
        out.limit(oldLimit);
      }
      out=slowBuffer;
      out.rewind();
    }
    int tagPos=out.position();
    out.position(tagPos + 1);
    byte curByte;
    curByte=inBuf.get(inPtr);
    byte bit0=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit0 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit1=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit1 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit2=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit2 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit3=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit3 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit4=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit4 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit5=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit5 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit6=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit6 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit7=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit7 - 1);
    inPtr+=1;
    byte tag=(byte)((bit0 << 0) | (bit1 << 1) | (bit2 << 2)| (bit3 << 3)| (bit4 << 4)| (bit5 << 5)| (bit6 << 6)| (bit7 << 7));
    out.put(tagPos,tag);
    if (tag == 0) {
      inBuf.position(inPtr);
      long inWord=inBuf.getLong();
      int limit=inEnd;
      if (limit - inPtr > 255 * 8) {
        limit=inPtr + 255 * 8;
      }
      while (inBuf.position() < limit && inWord == 0) {
        inWord=inBuf.getLong();
      }
      out.put((byte)((inBuf.position() - inPtr) / 8 - 1));
      inPtr=inBuf.position() - 8;
    }
 else     if (tag == (byte)0xff) {
      int runStart=inPtr;
      int limit=inEnd;
      if (limit - inPtr > 255 * 8) {
        limit=inPtr + 255 * 8;
      }
      while (inPtr < limit) {
        byte c=0;
        for (int ii=0; ii < 8; ++ii) {
          c+=(inBuf.get(inPtr) == 0 ? 1 : 0);
          inPtr+=1;
        }
        if (c >= 2) {
          inPtr-=8;
          break;
        }
      }
      int count=inPtr - runStart;
      out.put((byte)(count / 8));
      if (count <= out.remaining()) {
        inBuf.position(runStart);
        ByteBuffer slice=inBuf.slice();
        slice.limit(count);
        out.put(slice);
      }
 else {
        if (out == slowBuffer) {
          int oldLimit=out.limit();
          out.limit(out.position());
          out.rewind();
          this.inner.write(out);
          out.limit(oldLimit);
        }
        inBuf.position(runStart);
        ByteBuffer slice=inBuf.slice();
        slice.limit(count);
        while (slice.hasRemaining()) {
          this.inner.write(slice);
        }
        out=this.inner.getWriteBuffer();
      }
    }
  }
  if (out == slowBuffer) {
    out.limit(out.position());
    out.rewind();
    this.inner.write(out);
  }
  return length;
}

Fixed version (ground truth):
public int write(ByteBuffer inBuf) throws IOException {
  int length=inBuf.remaining();
  ByteBuffer out=this.inner.getWriteBuffer();
  ByteBuffer slowBuffer=ByteBuffer.allocate(20);
  int inPtr=inBuf.position();
  int inEnd=inPtr + length;
  while (inPtr < inEnd) {
    if (out.remaining() < 10) {
      if (out == slowBuffer) {
        int oldLimit=out.limit();
        out.limit(out.position());
        out.rewind();
        this.inner.write(out);
        out.limit(oldLimit);
      }
      out=slowBuffer;
      out.rewind();
    }
    int tagPos=out.position();
    out.position(tagPos + 1);
    byte curByte;
    curByte=inBuf.get(inPtr);
    byte bit0=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit0 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit1=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit1 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit2=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit2 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit3=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit3 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit4=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit4 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit5=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit5 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit6=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit6 - 1);
    inPtr+=1;
    curByte=inBuf.get(inPtr);
    byte bit7=(curByte != 0) ? (byte)1 : (byte)0;
    out.put(curByte);
    out.position(out.position() + bit7 - 1);
    inPtr+=1;
    byte tag=(byte)((bit0 << 0) | (bit1 << 1) | (bit2 << 2)| (bit3 << 3)| (bit4 << 4)| (bit5 << 5)| (bit6 << 6)| (bit7 << 7));
    out.put(tagPos,tag);
    if (tag == 0) {
      int runStart=inPtr;
      int limit=inEnd;
      if (limit - inPtr > 255 * 8) {
        limit=inPtr + 255 * 8;
      }
      while (inPtr < limit && inBuf.getLong(inPtr) == 0) {
        inPtr+=8;
      }
      out.put((byte)((inPtr - runStart) / 8));
    }
 else     if (tag == (byte)0xff) {
      int runStart=inPtr;
      int limit=inEnd;
      if (limit - inPtr > 255 * 8) {
        limit=inPtr + 255 * 8;
      }
      while (inPtr < limit) {
        byte c=0;
        for (int ii=0; ii < 8; ++ii) {
          c+=(inBuf.get(inPtr) == 0 ? 1 : 0);
          inPtr+=1;
        }
        if (c >= 2) {
          inPtr-=8;
          break;
        }
      }
      int count=inPtr - runStart;
      out.put((byte)(count / 8));
      if (count <= out.remaining()) {
        inBuf.position(runStart);
        ByteBuffer slice=inBuf.slice();
        slice.limit(count);
        out.put(slice);
      }
 else {
        if (out == slowBuffer) {
          int oldLimit=out.limit();
          out.limit(out.position());
          out.rewind();
          this.inner.write(out);
          out.limit(oldLimit);
        }
        inBuf.position(runStart);
        ByteBuffer slice=inBuf.slice();
        slice.limit(count);
        while (slice.hasRemaining()) {
          this.inner.write(slice);
        }
        out=this.inner.getWriteBuffer();
      }
    }
  }
  if (out == slowBuffer) {
    out.limit(out.position());
    out.rewind();
    this.inner.write(out);
  }
  inBuf.position(inPtr);
  return length;
}