You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2025/12/17 09:06:52 UTC
(httpcomponents-client) branch 5.6.x updated: Limit the length of content codec list that can be processed automatically (corrected)
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch 5.6.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
The following commit(s) were added to refs/heads/5.6.x by this push:
new 2ddb0c1fb Limit the length of content codec list that can be processed automatically (corrected)
2ddb0c1fb is described below
commit 2ddb0c1fbd5d4f18ef000545669e6c2713bbd6d7
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Dec 17 10:06:20 2025 +0100
Limit the length of content codec list that can be processed automatically (corrected)
---
.../impl/async/ContentCompressionAsyncExec.java | 1 +
.../async/TestContentCompressionAsyncExec.java | 29 ++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
index 04d5ed796..d685b39cd 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/ContentCompressionAsyncExec.java
@@ -149,6 +149,7 @@ public AsyncDataConsumer handleResponse(final HttpResponse rsp,
}
final List<String> codecs = ContentCodingSupport.parseContentCodecs(details);
+ ContentCodingSupport.validate(codecs, maxCodecListLen);
if (!codecs.isEmpty()) {
AsyncDataConsumer downstream = cb.handleResponse(rsp, wrapEntityDetails(details));
for (int i = codecs.size() - 1; i >= 0; i--) {
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/async/TestContentCompressionAsyncExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/async/TestContentCompressionAsyncExec.java
index 8cf3a181d..09b2abfef 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/async/TestContentCompressionAsyncExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/async/TestContentCompressionAsyncExec.java
@@ -57,6 +57,7 @@
import org.apache.hc.core5.http.HttpRequest;
import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.Method;
+import org.apache.hc.core5.http.ProtocolException;
import org.apache.hc.core5.http.message.BasicHttpRequest;
import org.apache.hc.core5.http.message.BasicHttpResponse;
import org.apache.hc.core5.http.nio.AsyncDataConsumer;
@@ -185,4 +186,32 @@ void testCompressionDisabledViaRequestConfig() throws Exception {
assertFalse(request.containsHeader(HttpHeaders.ACCEPT_ENCODING));
}
+
+ @Test
+ void testContentEncodingExceedsCodecListLenMax() throws Exception {
+ final HttpRequest request = new BasicHttpRequest(Method.GET, "/");
+ final AsyncExecCallback cb = executeAndCapture(request);
+
+ final HttpResponse rsp1 = new BasicHttpResponse(200, "OK");
+ final EntityDetails details1 = mock(EntityDetails.class);
+ when(details1.getContentEncoding()).thenReturn("gzip,gzip,gzip,gzip,gzip");
+
+ final AsyncDataConsumer downstream1 = new StringAsyncEntityConsumer();
+ when(originalCb.handleResponse(same(rsp1), same(details1))).thenReturn(downstream1);
+
+ final AsyncDataConsumer wrapped = cb.handleResponse(rsp1, details1);
+
+ assertNotNull(wrapped);
+
+ final HttpResponse rsp2 = new BasicHttpResponse(200, "OK");
+ final EntityDetails details2 = mock(EntityDetails.class);
+ when(details2.getContentEncoding()).thenReturn("gzip,gzip,gzip,gzip,gzip,gzip");
+
+ final AsyncDataConsumer downstream2 = new StringAsyncEntityConsumer();
+ when(originalCb.handleResponse(same(rsp2), same(details2))).thenReturn(downstream2);
+
+ final ProtocolException exception = assertThrows(ProtocolException.class, () -> cb.handleResponse(rsp2, details2));
+ assertEquals("Codec list exceeds maximum of 5 elements", exception.getMessage());
+ }
+
}
\ No newline at end of file