Skip to content

Commit 2dbbd7d

Browse files
committed
Ensure http content copied for safe buffers (#112767)
Currently, unless a rest handler specifies that it handles "unsafe" buffers, we must copy the http buffers in releaseAndCopy. Unfortuantely, the original content was slipping through in the initial stream PR. This less to memory corruption on index and update requests which depend on buffers being copied.
1 parent 0d55dc6 commit 2dbbd7d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ public HttpRequest releaseAndCopy() {
128128
}
129129
try {
130130
final ByteBuf copiedContent = Unpooled.copiedBuffer(request.content());
131+
HttpBody newContent;
132+
if (content.isStream()) {
133+
newContent = content;
134+
} else {
135+
newContent = Netty4Utils.fullHttpBodyFrom(copiedContent);
136+
}
131137
return new Netty4HttpRequest(
132138
sequence,
133139
new DefaultFullHttpRequest(
@@ -140,7 +146,7 @@ public HttpRequest releaseAndCopy() {
140146
),
141147
new AtomicBoolean(false),
142148
false,
143-
content
149+
newContent
144150
);
145151
} finally {
146152
release();

0 commit comments

Comments
 (0)