Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 540970

Summary: ArrayIndexOutOfboundsException in ProxyServlet
Product: [Eclipse Project] Equinox Reporter: Tim Roberts <troberts>
Component: CompendiumAssignee: equinox.components-inbox <equinox.components-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: raymond.auge, tjwatson
Version: unspecified   
Target Milestone: 4.11 M1   
Hardware: PC   
OS: Windows 10   
See Also: https://git.eclipse.org/r/133892
https://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=06745b4298f5ad9dce5d680095cb8fea435587cd
Whiteboard:

Description Tim Roberts CLA 2018-11-09 08:53:40 EST
I have a servlet that is receiving a callback from a piece of hardware (NEEO Brain) and am getting the following AIOOB. Pretty sure the encoded slashes are what's giving it issues...

2018-11-08 15:27:48.264:WARN:oejs.HttpChannel:qtp1596038409-1290: /neeo/NEEO-a5056097%2Fdevice%2Fapt-neeo_io%3Avirtual%3A6jzOoAtL%2FTemperature_GF_Living%2Fnone%2F1%2Fdirectory%2Factor/default
java.lang.ArrayIndexOutOfBoundsException: -6
	at org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet.getNotDecodedAlias(ProxyServlet.java:76)
	at org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet.service(ProxyServlet.java:90)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1317)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
	at org.eclipse.jetty.server.Server.handle(Server.java:531)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
	at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)
	at java.lang.Thread.run(Thread.java:748)
Comment 1 Tim Roberts CLA 2018-11-09 08:54:34 EST
Might be related to changes from https://bugs.eclipse.org/497510
Comment 2 Thomas Watson CLA 2018-11-09 15:24:51 EST
Ray, org.eclipse.equinox.http.servlet.internal.servlet.ProxyServlet.getNotDecodedAlias(HttpServletRequest) keeps getting more tricks thrown at it.  What now?  We have to first decode the slashes before doing this?
Comment 3 Tim Roberts CLA 2018-11-14 08:04:17 EST
Just pinging as this is a show stopper for us...
Comment 4 Tim Roberts CLA 2018-12-08 10:06:31 EST
Just pinging again as there has been no replies.  If someone wants me to tackle this myself, I can - but I have no idea what the original issue that caused this code change was and wouldn't feel real comfortable doing a change based on that.
Comment 5 Thomas Watson CLA 2018-12-10 09:19:39 EST
I want Ray to weigh in on this one.  I'm a bit concerned about what is being used as the path in this case:

/neeo/NEEO-a5056097%2Fdevice%2Fapt-neeo_io%3Avirtual%3A6jzOoAtL%2FTemperature_GF_Living%2Fnone%2F1%2Fdirectory%2Factor/default

Because we have a mix between encoded '/' and non-encoded '/'.  I'm not sure if the spec allows such a thing.  Ray do you have some time you could spend looking at this?
Comment 6 Tim Roberts CLA 2018-12-10 11:14:30 EST
I agree - unfortunately this is a hardware device formatting/sending this URL and I have no control over it and it was working fine prior to this change.

I can give you insight into the the confusion (not saying whether the hardware designers are correct or not in their approach - just stating the approach).  The non-encoded slashes denote the actual path:
First segment: the source device
Second segment: the source component
Third segment: the source value

So if we look at the URL:
I know the source device is "NEEO", the source component on the device is "NEEO-a5...actor" and the source value for the component is "default"

The problem is that the device name will include slashes itself and those should be considered part of the segment - not as a segment delimiter.

So you get non-encoded slashes to denote the segments and then encoded slashes to denote the data within the segment.
Comment 7 Tim Roberts CLA 2018-12-10 11:31:38 EST
I will add that after saying all that - if you want to treat the encoded slashes as a segment delimiter, I'd have no problems with that either.  We just really need to fix the AIOOB exception from occurring..
Comment 8 Raymond Auge CLA 2018-12-11 14:14:31 EST
I'm investigating...
Comment 9 Raymond Auge CLA 2018-12-11 14:37:43 EST
The first thing I can add is that, given this request:

/NEEO-a5056097%2Fdevice%2Fapt-neeo_io%3Avirtual%3A6jzOoAtL%2FTemperature_GF_Living%2Fnone%2F1%2Fdirectory%2Factor/default

Jetty's own request.getPathInfo() method returns this:

/NEEO-a5056097/device/apt-neeo_io:virtual:6jzOoAtL/Temperature_GF_Living/none/1/directory/actor/default

following that, the existing logic to get a compute the non-decoded pathinfo is pretty borked (i.e. is pretty broken).
Comment 10 Eclipse Genie CLA 2018-12-11 16:02:40 EST
New Gerrit change created: https://git.eclipse.org/r/133892
Comment 11 Raymond Auge CLA 2018-12-11 16:05:05 EST
@Tim would you be able to check the fix in the gerrit? I've added a test based on the path you provided and everything works. I hope this is the end of the silly path encoding issues.
Comment 13 Raymond Auge CLA 2018-12-11 19:00:24 EST
@Tim if would be please try with the subsequent i-build?
Comment 14 Thomas Watson CLA 2018-12-12 08:56:03 EST
(In reply to Raymond Auge from comment #13)
> @Tim if would be please try with the subsequent i-build?

This made it into the latest eclipse/equinox I20181212-0230 builds:

https://download.eclipse.org/equinox/drops/I20181212-0230/
https://download.eclipse.org/eclipse/downloads/drops4/I20181212-0230/
Comment 15 Tim Roberts CLA 2018-12-12 10:47:54 EST
Thanks - this was actually a bug from ESH/openHAB and I'll need to get them to pickup on the fix to be able to test it properly.  I'll let you know...