Skip to content

Fix possible unsafe sharing of internal NIO buffer in CompositeByteBuf#9169

Merged
normanmaurer merged 1 commit intonetty:4.1from
njhill:cbb-internalnio
May 22, 2019
Merged

Fix possible unsafe sharing of internal NIO buffer in CompositeByteBuf#9169
normanmaurer merged 1 commit intonetty:4.1from
njhill:cbb-internalnio

Conversation

@njhill
Copy link
Copy Markdown
Member

@njhill njhill commented May 21, 2019

Motivation

A small thread-safety bug was introduced during the internal optimizations of ComponentByteBuf made a while back in #8437. When there is a single component which was added as a slice,
internalNioBuffer(int,int) will currently return the unwrapped slice's un-duplicated internal NIO buffer. This is not safe since it could be modified concurrently with other usage of that parent buffer.

Modifications

Delegate internalNioBuffer to nioBuffer in this case, which returns a duplicate. This matches what's done in derived buffers in general (for the same reason). Add unit test.

Result

Fixed possible thread-safety bug

Motivation

A small thread-safety bug was introduced during the internal
optimizations of ComponentByteBuf made a while back in netty#8437. When there
is a single component which was added as a slice,
internalNioBuffer(int,int) will currently return the unwrapped slice's
un-duplicated internal NIO buffer. This is not safe since it could be
modified concurrently with other usage of that parent buffer.

Modifications

Delegate internalNioBuffer to nioBuffer in this case, which returns a
duplicate. This matches what's done in derived buffers in general
(for the same reason). Add unit test.

Result

Fixed possible thread-safety bug
@netty-bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@normanmaurer normanmaurer added this to the 4.1.37.Final milestone May 22, 2019
@normanmaurer normanmaurer merged commit 507e0a0 into netty:4.1 May 22, 2019
@normanmaurer
Copy link
Copy Markdown
Member

@njhill good catch... Thanks!

normanmaurer pushed a commit that referenced this pull request May 22, 2019
#9169)

Motivation

A small thread-safety bug was introduced during the internal
optimizations of ComponentByteBuf made a while back in #8437. When there
is a single component which was added as a slice,
internalNioBuffer(int,int) will currently return the unwrapped slice's
un-duplicated internal NIO buffer. This is not safe since it could be
modified concurrently with other usage of that parent buffer.

Modifications

Delegate internalNioBuffer to nioBuffer in this case, which returns a
duplicate. This matches what's done in derived buffers in general
(for the same reason). Add unit test.

Result

Fixed possible thread-safety bug
@njhill njhill deleted the cbb-internalnio branch May 22, 2019 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants