Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1550

"deflate" encoding issue : java.util.zip.ZipException: invalid stored block lengths

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.3.5
    • Fix Version/s: 4.5.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Windows

      Description

      When trying to GET any nzb files from http://nzbindex.nl with a httpclient request, a ZipException is raised.

      JunitTestFailing.java
      	@Test
      	public void testDeflateIssueFailing() throws ClientProtocolException, IOException {
      		HttpGet httpget = new HttpGet("http://nzbindex.nl/download/72441827/BackTrack5R3.Gnome.iSO.32bit-LiNUX-0171-bt5r2gis32.par2.nzb");
      		HttpClient client = HttpClientBuilder.create().build();
      		HttpResponse response = client.execute(httpget);
      		HttpEntity entity = response.getEntity();
      		byte[] data = EntityUtils.toByteArray( entity );
      		Assert.assertEquals( data.length, 423548 );
      	}
      
      

      The complete stack trace I get is this:

      java.util.zip.ZipException: invalid stored block lengths
      	at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
      	at java.io.FilterInputStream.read(FilterInputStream.java:107)
      	at org.apache.http.client.entity.DeflateInputStream.read(DeflateInputStream.java:144)
      	at org.apache.http.client.entity.LazyDecompressingInputStream.read(LazyDecompressingInputStream.java:68)
      	at org.apache.http.util.EntityUtils.toByteArray(EntityUtils.java:136)
      	at hclient.HTTPClientTest.testDeflateIssueFailing(HTTPClientTest.java:39)
      

      A workaround I found is to set the Accept-Encoding header to only accept gzip, as follows:

      JunitTestWorking.java
      	
      	@Test
      	public void testDeflateIssueWorking() throws ClientProtocolException, IOException {
      		HttpGet httpget = new HttpGet("http://nzbindex.nl/download/72441827/BackTrack5R3.Gnome.iSO.32bit-LiNUX-0171-bt5r2gis32.par2.nzb");
      		httpget.setHeader("Accept-Encoding", "gzip");
      		HttpClient client = HttpClientBuilder.create().build();
      		HttpResponse response = client.execute(httpget);
      		HttpEntity entity = response.getEntity();
      		byte[] data = EntityUtils.toByteArray( entity );
      		Assert.assertEquals( data.length, 423548 );
      	}
      

      Thanks

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                mozvip Guillaume Serre
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: