Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-3384

Attempt to parse an invalid MediaType leads to StringIndexOutOfBoundsException

XMLWordPrintable

      Processing an HTTP Request with a malformed accept header fails with a HTTP Status 500 (Internal Server Error) instead of 400 (Bad request).

      Reason is that the MediaType parsing in org.jboss.resteasy.plugins.delegates.MediaTypeHeaderDelegate#internalParse throws an StringIndexOutOfBoundException which bubbles up the stack instead of wrapping it in an IllegalArgumentException.

      The following test triggers the wrong exception:

      package org.jboss.resteasy.plugins.delegates;
      
      import org.junit.Test;
      
      public class MediaTypeHeaderDelegateTest {
      
          @Test
          public void parseBrokenMediaTypeShouldThrowIllegalArgumentException_minimized() {
              MediaTypeHeaderDelegate.parse("x; /x");
          }
      
          @Test
          public void parseBrokenMediaTypeShouldThrowIllegalArgumentException_actual() {
              MediaTypeHeaderDelegate.parse("() { ::}; echo \"NS:\" $(/bin/sh -c \"expr 123456 - 123456\")");
          }
      }
      

              jperkins-rhn James Perkins
              thomas.darimont@googlemail.com Thomas Darimont (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: