Skip to content

Commit

Permalink
Issue #4828 Buffer Corruption (#4864)
Browse files Browse the repository at this point in the history
+ improve synchronization around releaseBuffer
 + improve synchronization around acquireBuffer
 + made acquireBuffer private.

Signed-off-by: Greg Wilkins <[email protected]>
  • Loading branch information
gregw authored May 11, 2020
1 parent 933ab64 commit e869773
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,8 @@ public void completed()
synchronized (_channelState)
{
_state = State.CLOSED;
releaseBuffer();
}
releaseBuffer();
}

@Override
Expand Down Expand Up @@ -613,10 +613,13 @@ public void close() throws IOException

public ByteBuffer getBuffer()
{
return _aggregate;
synchronized (_channelState)
{
return acquireBuffer();
}
}

public ByteBuffer acquireBuffer()
private ByteBuffer acquireBuffer()
{
if (_aggregate == null)
_aggregate = _channel.getByteBufferPool().acquire(getBufferSize(), _interceptor.isOptimizedForDirectBuffers());
Expand Down Expand Up @@ -1410,10 +1413,13 @@ public void recycle()

public void resetBuffer()
{
_interceptor.resetBuffer();
if (BufferUtil.hasContent(_aggregate))
BufferUtil.clear(_aggregate);
_written = 0;
synchronized (_channelState)
{
_interceptor.resetBuffer();
if (BufferUtil.hasContent(_aggregate))
BufferUtil.clear(_aggregate);
_written = 0;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ protected void generateAcceptableResponse(Request baseRequest, HttpServletReques
// TODO error page may cause a BufferOverflow. In which case we try
// TODO again with stacks disabled. If it still overflows, it is
// TODO written without a body.
ByteBuffer buffer = baseRequest.getResponse().getHttpOutput().acquireBuffer();
ByteBuffer buffer = baseRequest.getResponse().getHttpOutput().getBuffer();
ByteBufferOutputStream out = new ByteBufferOutputStream(buffer);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, charset));

Expand Down

0 comments on commit e869773

Please sign in to comment.