Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Servlet HEAD doesn't support content-length over Integer.MAX_VALUE #5214

Closed
ebremer opened this issue Aug 31, 2020 · 8 comments · Fixed by #5215
Closed

Servlet HEAD doesn't support content-length over Integer.MAX_VALUE #5214

ebremer opened this issue Aug 31, 2020 · 8 comments · Fixed by #5215
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@ebremer
Copy link

ebremer commented Aug 31, 2020

9.4.31.v20200723

(build 11.0.8+10-jvmci-20.2-b03

Windows 10

When doing a HEAD request to retrieve file size using Jetty, anything one byte or more over 2^31 returns Content-Length: 0.

@gregw
Copy link
Contributor

gregw commented Aug 31, 2020

Can your server serve that resource if it is a GET request? Does it return with a content-length or chunked or connection:close ?

@ebremer
Copy link
Author

ebremer commented Aug 31, 2020

It works when doing a GET with the Content-Length being correct.

GET REQUEST
Request Headers ============================
GET /image.svs HTTP/1.1
Host: localhost:8899
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://localhost:8899/
Cookie: JSESSIONID=node0d0en4zp25hsb6cfws341jgmx0.node0; _ga=GA1.1.2146752974.1598712787
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache

Response Headers ============================
HTTP/1.1 200 OK
Date: Mon, 31 Aug 2020 14:06:58 GMT
Last-Modified: Mon, 31 Aug 2020 13:30:15 GMT
Accept-Ranges: bytes
Content-Length: 4085552795
Server: Jetty(9.4.31.v20200723)

HEAD REQUEST
Request Headers ============================
HEAD /image.svs HTTP/1.1
Host: localhost:8899
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://localhost:8899/
Cookie: JSESSIONID=node0d0en4zp25hsb6cfws341jgmx0.node0; _ga=GA1.1.2146752974.1598712787
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache

Response Headers ============================
HTTP/1.1 200 OK
Date: Mon, 31 Aug 2020 14:11:00 GMT
Last-Modified: Mon, 31 Aug 2020 13:30:15 GMT
Accept-Ranges: bytes
Content-Length: 0
Server: Jetty(9.4.31.v20200723)

@joakime joakime added the Bug For general bugs on Jetty side label Aug 31, 2020
@joakime
Copy link
Contributor

joakime commented Aug 31, 2020

Just tested this on Linux.

It fails on Linux as well. for 4GB and 10GB files from DefaultServlet. (See commit 1168713)
Looking into it.

joakime added a commit that referenced this issue Aug 31, 2020
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@joakime
Copy link
Contributor

joakime commented Aug 31, 2020

This is a bug in the servlet-api layer.

When the HEAD request arrives to javax.servlet.http.HttpServlet.service(HttpServletRequest, HttpServletResponse) the servlet API will create a
javax.servlet.http.HttpServlet$NoResponseBody (HttpServletResponseWrapper) to handle this request.
But that implementation is limited to int values on Content-Length.

@gregw the branch jetty-9.4.x-5214-head-huge-static has the testcase that can repllicate.

Do we want to fork/fix the servlet-api?
Or handle HEAD requests entirely within the Jetty layer now?

joakime added a commit that referenced this issue Aug 31, 2020
+ In the case of HEAD, the servlet-api response is a wrapper
  of javax.servlet.http.HttpServlet$NoBodyResponse
  We know the content_length, use it.

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@joakime
Copy link
Contributor

joakime commented Aug 31, 2020

Opened PR #5215

joakime added a commit that referenced this issue Aug 31, 2020
+ Adding DefaultServlet.doHead() to avoid servlet wrapping
+ Making ResourceService HEAD aware

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@ebremer
Copy link
Author

ebremer commented Sep 1, 2020

tested with PR for jetty-9.4.x-5214-head-huge-static and it works!

@joakime
Copy link
Contributor

joakime commented Sep 1, 2020

@ebremer great news! thanks for the feedback.

joakime added a commit that referenced this issue Sep 2, 2020
Issue #5214 - Servlet HEAD doesn't support content-length over Integer.MAX_VALUE
@joakime
Copy link
Contributor

joakime commented Sep 2, 2020

PR #5215 merged.

@joakime joakime closed this as completed Sep 2, 2020
@joakime joakime changed the title Jetty HEAD request cannot handle file sizes over 2^31 Servlet HEAD doesn't support content-length over Integer.MAX_VALUE Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants