NET-A-PORTER/scala-uri

StackOverflowError Caused by Long URI

Closed this issue · 5 comments

Passing in the following URI: http://www.counselingeducation.com/preroll/d/?id=44022&pid=2289033&subid=&size=300x250&e=xKS%2BPDcZDew%2BLDcx7z7hjoWHrPUQRWmjqoNs30jyvuRTh8XP3dCxgaPcjsF5DGAMVAaTJNGqdCoSU2PV6eax0GqflO%2BEDnrj44T6m72%2B%2F0Tv%2B4NCKEMbshFTAv27Dr%2FXp18roLvPT6rwfRcD46jr2qrGL8ru5C%2Ba3QQVpioQ92QPYaU39vFSwrVPU8GWWZcLMuN1s%2BKtqcOx7KXSFBiOGpNNxryydPRzMjI%2BhwmaT1z4ijVnpDjYnicAcX%2BuKtJRqM%2F%2BN9DscOxSZr2x4oSzpkptlTeHvJrj5kJVcrqTzC16tRsuYUulPd7uQblmMxcTsHRkQoGtcB2oOkqRHbW5I6NNWYKQtAnr69gYGAcEXf2a46wi9s7CH8%2FI6uMRvjwvuO0XLFxGVr3hF1V7qfNEIpNo0Lt94LOwefZqnp8fae14taQ1Rb7TGdA9BLIhsbQBmC1WWK2mIUd%2FjERFPhGdoyjcQqGfpGPetYE1yyAdukcubhPcDTNfvPM5DzLENqkefmBNb808irgpulr%2BkUYj2jm6iLRxcGim0EsntciBOPbxVTm7LxfU7D34Z5APCbiyopazfj05Ks5EiD%2FiwsEAJmMXJjKFQlHcpgNLTju3Ct8%2B3TcRstIzoThYphqY8HfuoAtZWCOy9HsSLwXFCqQyZVGO5im%2Fn1BPrF%2Fx%2BnCUfG7yH0laqdQdxaPnz32Ax9H3dscs5E2MfyRTOJVhe0cJLP7T%2B0JuFvhy3NU9Jk2Jx%2BPnWN8wn47O9XJDfnM%2FScIjXpNtiiXxu8b72l14HaM56P2GoIOvaLq2M1Gfullar0dmSkXFmPoI2NMViA7EHBk1zer7AAh7pBq7y10uEh%2BbaDBowavM5c7HF6%2BJW1NBrcFIKBpNr2SvotpFlfqh629ROGLkL54AhzkFHfJzJev3UrXXlpYPP9XdDzT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LNcI1zu6%2FHUC%2Fg11yVjIs5DOE4jN

Creates the following stack trace:

java.lang.StackOverflowError
at org.parboiled2.ValueStack.size_$eq(ValueStack.scala:33)
at org.parboiled2.Parser.__restoreState(Parser.scala:222)
at com.netaporter.uri.parsing.UriParser.rec$7(UriParser.scala:20)

Obviously this is a long URL (although a cursory glance suggests it is valid). I've fixed the problem by handling the exception, but obviously it isn't the expected behavior.

I can reproduce the stackoverflow locally, however the stackoverflow doesn't happen on travis (the URI is parsed and the test fails for another reason):

https://travis-ci.org/NET-A-PORTER/scala-uri/jobs/27286327#L316

I'll investigate further.

It looks like it passed on travis because it is using a large 6 MB stack size. Locally, increasing the stack size from 1024k to 1300k using the -Xss1300k JVM argument is enough of a workaround for the URI in question.

I'll look into a proper fix.

This should be fixed now as of c9168f9

Since this required a fairly large change to the parser, I would like to keep it at a SNAPSHOT version for a little while. Could you try out version 0.4.3-SNAPSHOT.

The parboiled2 guys have raised a bug against the Scala complier as a result of this, so thanks again for raising this issue.

See: sirthias/parboiled2#78

@NJordan72 Update: The workaround I committed as part of this ticket caused more problems than it solved. For 0.4.3+ I have reverted this change. Unfortunately, this does mean StackOverflowErrors for long URIs in Scala 2.10, however the good news is that SI-8657 has now been fixed in Scala 2.11.2+. So, if you need to deal with large URIs, you will currently need to use Scala 2.11.2+. There is a unit test to ensure this here