cap Content-Length before narrowing to int in Http2Client#3431
Merged
Conversation
velo
approved these changes
Jun 20, 2026
velo
left a comment
Member
There was a problem hiding this comment.
This fixes a real edge case in the HTTP/2 adapter without changing the API surface. The range check in java11/src/main/java/feign/http2client/Http2Client.java matches the Response.Body contract, and Http2ClientContentLengthTest covers the oversized, negative, and normal-length paths. Checks are green, so this looks good to me.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Http2Client.toFeignResponsenarrows the responseContent-Lengthwith(int) length.getAsLong()and no range check.Content-Length: 2147483648(2^31) wraps to-2147483648, andContent-Length: -1is forwarded as-is.Response.Body.length()is documented to benullwhen the length is unknown or greater thanInteger.MAX_VALUE, andokhttp,httpclient,hc5andgooglehttpclientalready cap before narrowing. The wrapped negative length also slips past theresponse.body().length() <= MAX_RESPONSE_BUFFER_SIZEcheck inInvocationContextthat decides whether to buffer the whole response into memory. Capped so theintis returned only for0 <= length <= Integer.MAX_VALUE, otherwisenull.repro:Http2ClientContentLengthTestbuilds anHttpResponsewith a givenContent-Lengthand readsbody().length().Content-Length: 2147483648expectednull, before-2147483648.Content-Length: -1expectednull, before-1.Content-Length: 1024stays1024.