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

GzipDecompressingEntity does not release InputStream when an IOException occurs while reading the Gzip header

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 4.2.2, 4.2.3
    • 4.2.3
    • HttpClient (classic)
    • None

    Description

      When calling method org.apache.http.client.entity.DecompressingEntity.getContent() for a GzipDecompressingEntity, the method tries to build a GZIPInputStream, then the GzipInputStream tries to read the Gzip header and fails throwing an IOException.
      At the end you get an Exception but the backend InputStream is never closed resulting in a connection leak.

      Here is a test to reproduce:
      @Test
      public void testGzipDecompressingEntityDoesNotCrashInConstructorAndLeaveInputStreamOpen()
      throws Exception {
      final AtomicBoolean inputStreamIsClosed = new AtomicBoolean(false);
      HttpEntity in = new InputStreamEntity(new InputStream() {
      @Override
      public int read() throws IOException

      { throw new IOException("An exception occurred"); }

      @Override
      public void close() throws IOException

      { inputStreamIsClosed.set(true); }

      }, 123);
      GzipDecompressingEntity gunzipe = new GzipDecompressingEntity(in);
      try

      { InputStream is = gunzipe.getContent(); }

      catch (IOException e)

      { // As I cannot get the content, GzipDecompressingEntity is supposed // to have released everything Assert.assertTrue(inputStreamIsClosed.get()); }

      }

      Attachments

        1. DecompressingEntity_patch.txt
          3 kB
          Francois-Xavier Bonnet

        Activity

          People

            Unassigned Unassigned
            fx.bonnet Francois-Xavier Bonnet
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: