jetty / jetty.project

Eclipse Jetty® - Web Container & Clients - supports HTTP/2, HTTP/1.1, HTTP/1.0, websocket, servlets, and more
https://eclipse.dev/jetty
Other
3.83k stars 1.91k forks source link

StringIndexOutOfBoundsException in QuotedQualityCSV #1577

Closed gjdev closed 7 years ago

gjdev commented 7 years ago

Since upgrading to jetty 9.4.5 (from 9.3.12) we see this error logged in our server logs several times a day:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.AbstractStringBuilder.setLength(AbstractStringBuilder.java:207)
    at java.lang.StringBuffer.setLength(StringBuffer.java:192)
    at org.eclipse.jetty.http.QuotedQualityCSV.parsedParam(QuotedQualityCSV.java:138)
    at org.eclipse.jetty.http.QuotedCSV.addValue(QuotedCSV.java:156)
    at org.eclipse.jetty.http.QuotedQualityCSV.addValue(QuotedQualityCSV.java:102)
    at org.eclipse.jetty.http.HttpFields.getQualityCSV(HttpFields.java:441)
    at org.eclipse.jetty.server.handler.ErrorHandler.getAcceptableWriter(ErrorHandler.java:199)
    at org.eclipse.jetty.server.handler.ErrorHandler.generateAcceptableResponse(ErrorHandler.java:246)
    at org.eclipse.jetty.server.handler.ErrorHandler.generateAcceptableResponse(ErrorHandler.java:170)
    at org.eclipse.jetty.server.handler.ErrorHandler.doError(ErrorHandler.java:142)
    at org.eclipse.jetty.server.handler.ErrorHandler.handle(ErrorHandler.java:78)
    at org.eclipse.jetty.server.Response.sendError(Response.java:655)
    at org.eclipse.jetty.server.Response.sendError(Response.java:590)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:418)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
    at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
    at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:199)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)
    at java.lang.Thread.run(Thread.java:745)
    Suppressed: java.lang.IllegalStateException: s=COMPLETING i=false a=NOT_ASYNC
        at org.eclipse.jetty.server.HttpChannelState.onError(HttpChannelState.java:769)
        at org.eclipse.jetty.server.HttpChannel.handleException(HttpChannel.java:522)
        at org.eclipse.jetty.server.HttpChannelOverHttp.handleException(HttpChannelOverHttp.java:463)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:458)
        ... 11 common frames omitted
gregw commented 7 years ago

Hi,

I've opened https://github.com/eclipse/jetty.project/issues/1579 If you could capture the headers that cause that NPE, that would be a big help.

cheers

On 29 May 2017 at 15:55, gjdev notifications@github.com wrote:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.AbstractStringBuilder.setLength(AbstractStringBuilder.java: 207) at java.lang.StringBuffer.setLength(StringBuffer.java:192) at org.eclipse.jetty.http.QuotedQualityCSV.parsedParam( QuotedQualityCSV.java:138) at org.eclipse.jetty.http.QuotedCSV.addValue(QuotedCSV.java:156) at org.eclipse.jetty.http.QuotedQualityCSV.addValue( QuotedQualityCSV.java:102) at org.eclipse.jetty.http.HttpFields.getQualityCSV(HttpFields.java:441) at org.eclipse.jetty.server.handler.ErrorHandler.getAcceptableWriter( ErrorHandler.java:199) at org.eclipse.jetty.server.handler.ErrorHandler. generateAcceptableResponse(ErrorHandler.java:246) at org.eclipse.jetty.server.handler.ErrorHandler. generateAcceptableResponse(ErrorHandler.java:170) at org.eclipse.jetty.server.handler.ErrorHandler.doError( ErrorHandler.java:142) at org.eclipse.jetty.server.handler.ErrorHandler.handle( ErrorHandler.java:78) at org.eclipse.jetty.server.Response.sendError(Response.java:655) at org.eclipse.jetty.server.Response.sendError(Response.java:590) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:418) at org.eclipse.jetty.server.HttpConnection.onFillable( HttpConnection.java:251) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded( AbstractConnection.java:279) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) at org.eclipse.jetty.util.thread.Invocable.invokePreferred( Invocable.java:128) at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor. invoke(Invocable.java:222) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill. doProduce(EatWhatYouKill.java:294) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run( EatWhatYouKill.java:199) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob( QueuedThreadPool.java:672) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run( QueuedThreadPool.java:590) at java.lang.Thread.run(Thread.java:745) Suppressed: java.lang.IllegalStateException: s=COMPLETING i=false a=NOT_ASYNC at org.eclipse.jetty.server.HttpChannelState.onError( HttpChannelState.java:769) at org.eclipse.jetty.server.HttpChannel.handleException( HttpChannel.java:522) at org.eclipse.jetty.server.HttpChannelOverHttp.handleException( HttpChannelOverHttp.java:463) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:458) ... 11 common frames omitted

-- Greg Wilkins gregw@webtide.com CTO http://webtide.com

gregw commented 7 years ago

Found problem and fixed. They are from badly formed quality lists. In particular I think your error is caused by somebody sending a header like

Accept-Charset: q=1

Which is a bit wrong, so they probably deserve the 500 that they are getting. However the fix will ignore such bad quality CSVs and they will get the default charset.

cheers

On 30 May 2017 at 08:38, Greg Wilkins gregw@webtide.com wrote:

Hi,

I've opened https://github.com/eclipse/jetty.project/issues/1579 If you could capture the headers that cause that NPE, that would be a big help.

cheers

On 29 May 2017 at 15:55, gjdev notifications@github.com wrote:

java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.AbstractStringBuilder.setLength(AbstractStringBuil der.java:207) at java.lang.StringBuffer.setLength(StringBuffer.java:192) at org.eclipse.jetty.http.QuotedQualityCSV.parsedParam(QuotedQu alityCSV.java:138) at org.eclipse.jetty.http.QuotedCSV.addValue(QuotedCSV.java:156) at org.eclipse.jetty.http.QuotedQualityCSV.addValue(QuotedQuali tyCSV.java:102) at org.eclipse.jetty.http.HttpFields.getQualityCSV(HttpFields.java:441) at org.eclipse.jetty.server.handler.ErrorHandler.getAcceptableW riter(ErrorHandler.java:199) at org.eclipse.jetty.server.handler.ErrorHandler.generateAccept ableResponse(ErrorHandler.java:246) at org.eclipse.jetty.server.handler.ErrorHandler.generateAccept ableResponse(ErrorHandler.java:170) at org.eclipse.jetty.server.handler.ErrorHandler.doError(ErrorH andler.java:142) at org.eclipse.jetty.server.handler.ErrorHandler.handle(ErrorHa ndler.java:78) at org.eclipse.jetty.server.Response.sendError(Response.java:655) at org.eclipse.jetty.server.Response.sendError(Response.java:590) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:418) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConne ction.java:251) at org.eclipse.jetty.io.AbstractConnection$ReadCallback. succeeded(AbstractConnection.java:279) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124) at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invo cable.java:128) at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.in voke(Invocable.java:222) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProd uce(EatWhatYouKill.java:294) at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(Ea tWhatYouKill.java:199) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(Queued ThreadPool.java:672) at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedT hreadPool.java:590) at java.lang.Thread.run(Thread.java:745) Suppressed: java.lang.IllegalStateException: s=COMPLETING i=false a=NOT_ASYNC at org.eclipse.jetty.server.HttpChannelState.onError(HttpChanne lState.java:769) at org.eclipse.jetty.server.HttpChannel.handleException(HttpCha nnel.java:522) at org.eclipse.jetty.server.HttpChannelOverHttp.handleException (HttpChannelOverHttp.java:463) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:458) ... 11 common frames omitted

-- Greg Wilkins gregw@webtide.com CTO http://webtide.com

-- Greg Wilkins gregw@webtide.com CTO http://webtide.com

joakime commented 7 years ago

@gregw do you want to leave this issue #1577 open for anything else?

gregw commented 7 years ago

nope :)

gjdev commented 7 years ago

Thanks!