Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-1608

IndexOutOfBounds in StoredResponseStreamSinkConduit

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.0.27.Final
    • None
    • None
    • None

      There is a bug in buf.position() actually indicates buffer size, so last buffer index is equal to buf.position() -1.

      With this error, when buffer array has more than one element (so when response is bigger than 16KB by default), exception is thrown and exchange will never be finalized properly (even though HTTP response is received by client and seems fine). Listeners won't be executed, graceful shutdown will fail etc.

      Below there is a simple code snippet for reproducing this error:

      public static void main(String[] args) {
      
          HttpHandler targetHandler = exchange -> {
              exchange.getResponseHeaders().add(Headers.CONTENT_TYPE, "text/plain");
              exchange.getResponseSender().send("A".repeat(20000));
          };
      
          StoredResponseHandler storedResponseHandler = new StoredResponseHandler(targetHandler);
      
          Undertow server = Undertow.builder()
                  .addHttpListener(5050, "0.0.0.0")
                  .setHandler(storedResponseHandler)
                  .build();
      
          server.start();
      }
      

              flaviarnn Flavia Rainone
              flaviarnn Flavia Rainone
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: