question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StringIndexOutOfBoundsException thrown by HttpPostRequestDecoder.splitHeaderContentType() when Content-Type header starts with a semicolon

See original GitHub issue

Expected behavior

I’m not sure what the desired behavior should be for HttpPostRequestDecoder.splitHeaderContentType() when it finds a Content-Type header that starts with a semicolon, but I’m assuming StringIndexOutOfBoundsException is not intentional.

Actual behavior

HttpPostRequestDecoder.splitHeaderContentType() throws a StringIndexOutOfBoundsException when it parses a Content-Type header that starts with a semicolon ;. Specifically this line, because the aEnd variable is 0 when the Content-Type header starts with a semicolon: https://github.com/netty/netty/blob/00afb19d7a37de21b35ce4f6cb3fa7f74809f2ab/codec-http/src/main/java/io/netty/handler/codec/http/multipart/HttpPostRequestDecoder.java#L278.

Steps to reproduce

  1. Make a request to a Netty HTTP server and pass a Content-Type header that starts with a semicolon ;. I’m not sure if there are HTTP clients that would sanitize this for you and prevent the problem, but I was able to reproduce this with RestAssured and a Netty Bootstrap acting as a HTTP Client via HttpClientCodec, so there are at least a few clients you can use to reproduce.
  2. In the Netty server that receives the request, call HttpPostRequestDecoder.isMultipart(HttpRequest) or any other code path that ultimately causes HttpPostRequestDecoder.splitHeaderContentType(String) to be called with the request’s Content-Type header.
  3. You’ll see a StringIndexOutOfBoundsException get thrown.

Netty version

4.1.30.Final (probably others as well)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
amizurovcommented, Nov 22, 2018

No problem, do that

0reactions
nicmunroecommented, Oct 23, 2019

Sorry I was out all last week, but your solution looks good to me! Thank you @amizurov !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Comparing 38524ec3e2...37c03cce5e - netty5 - iGNUranza Git
Motivation: HttpPostRequestDecoder.splitHeaderContentType() throws a StringIndexOutOfBoundsException when it parses a Content-Type header that starts with a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found