Program: 34674
Project: 34674
Buggy source:
public int processNextBuffer(@Sensitive WsByteBuffer buf) throws ProtocolException, FrameSizeException {
  if (tc.isDebugEnabled()) {
    Tr.debug(tc,"String_Node_Str" + frameState);
  }
  if (frameState == FrameState.PAYLOAD_COMPLETE) {
    return Constants.BP_FRAME_ALREADY_COMPLETE;
  }
  if (countOfBuffers >= frameBuffers.length) {
    int originalSize=frameBuffers.length;
    WsByteBuffer[] temp=new WsByteBuffer[originalSize + BUFFER_ARRAY_GROWTH_SIZE];
    System.arraycopy(frameBuffers,0,temp,0,originalSize);
    frameBuffers=temp;
  }
  if (tc.isDebugEnabled()) {
    Tr.debug(tc,"String_Node_Str" + countOfBuffers);
  }
  frameBuffers[countOfBuffers]=buf;
  countOfBuffers++;
  if (muxLink != null && muxLink.connection_preface_string_rcvd == false) {
    long bytesToProcess=bytesRemaining();
    if (bytesToProcess < 24) {
      return Constants.BP_FRAME_IS_NOT_COMPLETE;
    }
    currentBufferArrayIndex=0;
    try {
      if (checkConnectionPreface()) {
        frameState=FrameState.INIT;
        muxLink.processConnectionPrefaceMagic();
      }
 else {
        throw new ProtocolException("String_Node_Str");
      }
    }
 catch (    FrameSizeException e1) {
      throw new ProtocolException("String_Node_Str");
    }
  }
  if (frameState == FrameState.INIT) {
    byte frameSixthByte;
    long bytesToProcess=bytesRemaining();
    if (bytesToProcess < Frame.SIZE_FRAME_BEFORE_PAYLOAD) {
      return Constants.BP_FRAME_IS_NOT_COMPLETE;
    }
    currentBufferArrayIndex=0;
    int payloadLength=grabNext24BitInt();
    byteFrameType=grabNextByte();
    byte flags=grabNextByte();
    frameSixthByte=grabNextByte();
    int frameReserveBit=(byte)(frameSixthByte & Constants.MASK_80);
    if (frameReserveBit != 0) {
      frameReserveBit=1;
    }
    frameSixthByte=(byte)(frameSixthByte & Constants.MASK_7F);
    int streamId=new Integer(grabNext24BitInt(frameSixthByte));
    this.currentFrame=FrameFactory.getFrame(byteFrameType,streamId,payloadLength,flags,frameReserveBit == 1,Frame.FrameDirection.READ);
    if (this.currentFrame.getFrameType() == FrameTypes.UNKNOWN) {
      if (tc.isDebugEnabled()) {
        Tr.debug(tc,"String_Node_Str");
      }
    }
    frameState=FrameState.FIND_PAYLOAD;
  }
  if (currentFrame != null && frameState == FrameState.FIND_PAYLOAD) {
    int returnValue=Constants.BP_FRAME_IS_NOT_COMPLETE;
    long count=0;
    int remaining=0;
    for (int i=0; i < countOfBuffers; i++) {
      remaining=frameBuffers[i].remaining();
      if (count + remaining <= currentFrame.getPayloadLength()) {
        count+=remaining;
        if (count == currentFrame.getPayloadLength()) {
          frameState=FrameState.PAYLOAD_COMPLETE;
          returnValue=Constants.BP_FRAME_EXACTLY_COMPLETED;
        }
      }
 else {
        int nextPosition=frameBuffers[i].position() + ((int)(currentFrame.getPayloadLength() - count));
        frameState=FrameState.PAYLOAD_COMPLETE;
        returnValue=nextPosition;
      }
    }
    return returnValue;
  }
  ProtocolException e=new ProtocolException("String_Node_Str");
  throw e;
}

Fixed version (ground truth):
public int processNextBuffer(@Sensitive WsByteBuffer buf) throws ProtocolException, FrameSizeException {
  if (tc.isDebugEnabled()) {
    Tr.debug(tc,"String_Node_Str" + frameState);
  }
  if (frameState == FrameState.PAYLOAD_COMPLETE) {
    return Constants.BP_FRAME_ALREADY_COMPLETE;
  }
  if (countOfBuffers >= frameBuffers.length) {
    int originalSize=frameBuffers.length;
    WsByteBuffer[] temp=new WsByteBuffer[originalSize + BUFFER_ARRAY_GROWTH_SIZE];
    System.arraycopy(frameBuffers,0,temp,0,originalSize);
    frameBuffers=temp;
  }
  if (tc.isDebugEnabled()) {
    Tr.debug(tc,"String_Node_Str" + countOfBuffers);
  }
  frameBuffers[countOfBuffers]=buf;
  countOfBuffers++;
  if (muxLink != null && muxLink.connection_preface_string_rcvd == false) {
    long bytesToProcess=bytesRemaining();
    if (bytesToProcess < 24) {
      return Constants.BP_FRAME_IS_NOT_COMPLETE;
    }
    currentBufferArrayIndex=0;
    try {
      if (checkConnectionPreface()) {
        frameState=FrameState.INIT;
        muxLink.processConnectionPrefaceMagic();
      }
 else {
        throw new ProtocolException("String_Node_Str");
      }
    }
 catch (    Http2Exception e) {
      throw new ProtocolException("String_Node_Str");
    }
  }
  if (frameState == FrameState.INIT) {
    byte frameSixthByte;
    long bytesToProcess=bytesRemaining();
    if (bytesToProcess < Frame.SIZE_FRAME_BEFORE_PAYLOAD) {
      return Constants.BP_FRAME_IS_NOT_COMPLETE;
    }
    currentBufferArrayIndex=0;
    int payloadLength=grabNext24BitInt();
    byteFrameType=grabNextByte();
    byte flags=grabNextByte();
    frameSixthByte=grabNextByte();
    int frameReserveBit=(byte)(frameSixthByte & Constants.MASK_80);
    if (frameReserveBit != 0) {
      frameReserveBit=1;
    }
    frameSixthByte=(byte)(frameSixthByte & Constants.MASK_7F);
    int streamId=new Integer(grabNext24BitInt(frameSixthByte));
    this.currentFrame=FrameFactory.getFrame(byteFrameType,streamId,payloadLength,flags,frameReserveBit == 1,Frame.FrameDirection.READ);
    if (this.currentFrame.getFrameType() == FrameTypes.UNKNOWN) {
      if (tc.isDebugEnabled()) {
        Tr.debug(tc,"String_Node_Str");
      }
    }
    frameState=FrameState.FIND_PAYLOAD;
  }
  if (currentFrame != null && frameState == FrameState.FIND_PAYLOAD) {
    int returnValue=Constants.BP_FRAME_IS_NOT_COMPLETE;
    long count=0;
    int remaining=0;
    for (int i=0; i < countOfBuffers; i++) {
      remaining=frameBuffers[i].remaining();
      if (count + remaining <= currentFrame.getPayloadLength()) {
        count+=remaining;
        if (count == currentFrame.getPayloadLength()) {
          frameState=FrameState.PAYLOAD_COMPLETE;
          returnValue=Constants.BP_FRAME_EXACTLY_COMPLETED;
        }
      }
 else {
        int nextPosition=frameBuffers[i].position() + ((int)(currentFrame.getPayloadLength() - count));
        frameState=FrameState.PAYLOAD_COMPLETE;
        returnValue=nextPosition;
      }
    }
    return returnValue;
  }
  ProtocolException e=new ProtocolException("String_Node_Str");
  throw e;
}