Skip to content

jsoup bodyStream() silently truncates responses at Integer.MAX_VALUE despite maxBodySize(0) #2593

Closed

Description

@EdwinKM

When using Connection.maxBodySize(0) together with Response.bodyStream() to download a large binary response, the response appears to be silently truncated at exactly Integer.MAX_VALUE (2,147,483,647) bytes.

I understand that jsoup is primarily an HTML parser rather than a dedicated large-file download tool. However, the documentation for maxBodySize(0) explicitly describes 0 as:

an infinite amount (bounded only by your patience and the memory available on your machine)

This makes the observed behaviour somewhat unexpected. More importantly, the truncation is silent: the InputStream reaches EOF normally, so the calling application has no indication that the response was incomplete.

Steps to reproduce
We use the Blender example.
Compare with command line wget

wget "https://download.blender.org/demo/movies/Blender_reel_2013.mov"
--2026-09-06 15:44:16--  https://download.blender.org/demo/movies/Blender_reel_2013.mov
Resolving download.blender.org (download.blender.org)... 104.20.41.146, 172.66.172.236, 2606:4700:10::6814:2992, ...
Connecting to download.blender.org (download.blender.org)|104.20.41.146|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2516125285 (2,3G) [video/quicktime]

Expected file size is: 2516125285

				String url = "https://download.blender.org/demo/movies/Blender_reel_2013.mov";
				Connection con = Jsoup.connect(url.toString())
						.timeout(10800000) // 3 hours
			    		.method(Method.GET)
			    		.ignoreContentType(true)
			    		.maxBodySize(0)
			    		.followRedirects(false)
			    		.ignoreHttpErrors(true);
				
				Response res = con.execute();

				LOG.info("Content-Length: " + res.header("Content-Length"));
				LOG.info("Content-Type: " + res.contentType());
				
		        try (InputStream in = res.bodyStream();
	        	     OutputStream out = new FileOutputStream("/home/test/file.mov")) {
	
	        	    byte[] buffer = new byte[1024 * 1024]; // 1 MB
	        	    int bytesRead;
	
	        	    while ((bytesRead = in.read(buffer)) != -1) {
	        	        out.write(buffer, 0, bytesRead);
	        	    }
	        	}

Validate the resulting file on disk -> 2,0 GiB (2.147.483.647)

Activity

  1. jhy commented on Sep 7, 2026

    @jhy
    Owner

    I think this probably regressed in bd92bca / #2448 when I refactored these buffers. The max caps were handled differently with an explicit boolean vs a sentinel.

  2. added
    bugA confirmed bug, that we should fix
    fixedAn {bug|improvement} that has been {fixed|implemented}
    on Sep 8, 2026
  3. added this to the 1.24.1 milestone on Sep 8, 2026
  4. added a commit that references this issue on Sep 8, 2026
    8ca4902
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA confirmed bug, that we should fixfixedAn {bug|improvement} that has been {fixed|implemented}

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions