Restrict memory allocation in ContentCachingRequestWrapper
Prior to this commit, the `ContentCachingRequestWrapper` could allocate a `FastByteArrayOutputStream` block that was larger than the content cache limit given as a consturctor argument. This was due to an optimization applied in gh-31834 for allocating the right content cache size when the request size is known. Fixes gh-32987
This commit is contained in:
@@ -89,7 +89,12 @@ public class ContentCachingRequestWrapper extends HttpServletRequestWrapper {
|
||||
public ContentCachingRequestWrapper(HttpServletRequest request, int contentCacheLimit) {
|
||||
super(request);
|
||||
int contentLength = request.getContentLength();
|
||||
this.cachedContent = (contentLength > 0) ? new FastByteArrayOutputStream(contentLength) : new FastByteArrayOutputStream();
|
||||
if (contentLength > 0) {
|
||||
this.cachedContent = new FastByteArrayOutputStream(Math.min(contentLength, contentCacheLimit));
|
||||
}
|
||||
else {
|
||||
this.cachedContent = new FastByteArrayOutputStream();
|
||||
}
|
||||
this.contentCacheLimit = contentCacheLimit;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user