[ 
https://issues.apache.org/jira/browse/CAMEL-6561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13715993#comment-13715993
 ] 

Zemian Deng commented on CAMEL-6561:
------------------------------------

Sure Claus,

But before I add new option you suggested, I've discovered couple things that I 
would like to discuss first:

1) It looks like the latest code in master has a change in 
DefaultSqlPrepareStatementStrategy.java line  129 that prevented my test case 
to generate StackOverflowError. With this, it went and parsed the input into 
array and obviously give error because the size is mismatch to SQL binding 
parameters count. Which is expected.

However I see that DefaultSqlPrepareStatementStrategy did not check for this 
String input type when query has namedParameters (starting line 68) though. Is 
this intended?

2) As I hinted in previous comment, the StackOverflowError is really comes from 
ObjectHelper class. This is more concern to me. You can duplicate this bug by 
the following simple test case:
{code}

    @Test
    public void testCreateIteratorWithJsonThatBreakDelimiter() throws Exception 
{
        String input = readFromClasspath("sample1.json");
        Iterator<Object> result = ObjectHelper.createIterator(input);
        Assert.assertEquals(input, result.next());
    }
{code}

That means whoever calls any of these creatIterator() with bad input could 
potential get into StackOverflowError. The root cause is from ObjectHelper.java 
line 601. It parses input with some fancy regexp. Since its part of Camel Core, 
this is too risky and a bad error to expose to users by simply having bad 
inputs. I would recommend NOT to use that regexp but keep it minimal, fixed 
delimiter String to avoid this. What's your thought on this?

Zemian
                
> Inserting JSON like data with sql component cause a 
> java.lang.StackOverflowError
> --------------------------------------------------------------------------------
>
>                 Key: CAMEL-6561
>                 URL: https://issues.apache.org/jira/browse/CAMEL-6561
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-sql
>    Affects Versions: 2.11.0
>            Reporter: Zemian Deng
>         Attachments: sample1.json
>
>
> I have a simple route use case like this:
> {code}
> <camel:camelContext id="camel-server" 
> xmlns="http://camel.apache.org/schema/spring";>
>               <template id="producerTemplate"/>
>         <route>
>                       <from uri="direct:SEND_MEMQ"/>
>                       <to uri="sql:INSERT INTO CAMEL_TEST(MSG) 
> VALUES(#)?dataSource=testdbDataSource"/>
>                       <to 
> uri="log:camel.demos.throughputtest.tcp.Stat?level=INFO&amp;groupSize=100"/>
>         </route>
>     </camel:camelContext>
> {code}
> The DB table is simple one like this:
> {code}
> /* H2Database */
> DROP TABLE CAMEL_TEST;
> CREATE TABLE CAMEL_TEST ( 
>   ID BIGINT PRIMARY KEY AUTO_INCREMENT,
>   MSG VARCHAR(10240),
>   CREATE_TS TIMESTAMP DEFAULT NOW()
> );
> {code}
> And then I use the producerTemplate to send a sample JSON content like data 
> message (see attachment) into the "direct:SEND_MEMQ" (I read the full file 
> and send it as String), and it produced the following severe error:
> {code}
> 2013-07-18 08:34:00,593 ERROR pool-1-thread-1 
> [org.apache.camel.processor.DefaultErrorHandler] - Failed delivery for 
> (MessageId: ID-L328BDS002012US-56371-1374150839469-0-1 on ExchangeId: 
> ID-L328BDS002012US-56371-1374150839469-0-2). Exhausted after delivery 
> attempt: 1 caught: org.apache.camel.CamelExecutionException: Exception 
> occurred during execution on the exchange: Exchange[Message: {"web-app": {
> ... 
> ... [Body clipped after 1000 chars, total length is 3467]]
>         at 
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1354)
>         at 
> org.apache.camel.impl.DefaultExchange.setException(DefaultExchange.java:272)
>         at 
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:64)
>         at 
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
>         at 
> org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:122)
>         at 
> org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:298)
>         at 
> org.apache.camel.processor.SendProcessor.process(SendProcessor.java:117)
>         at 
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
>         at 
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
>         at 
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
>         at 
> org.apache.camel.processor.interceptor.BacklogTracerInterceptor.process(BacklogTracerInterceptor.java:84)
>         at 
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
>         at 
> org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
>         at 
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
>         at 
> org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:390)
>         at 
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:273)
>         at 
> org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
>         at 
> org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:335)
>         at 
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
>         at 
> org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
>         at 
> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:122)
>         at 
> org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
>         at 
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
>         at 
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
>         at 
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
>         at 
> org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:60)
>         at 
> org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)
>         at 
> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)
>         at 
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)
>         at 
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)
>         at 
> org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:63)
>         at 
> org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:366)
>         at 
> org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:337)
>         at 
> org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:233)
>         at 
> org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:337)
>         at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:175)
>         at 
> org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:111)
>         at 
> org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:124)
>         at 
> org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:131)
>         at throughputtest.FileSampleProducer$1.run(FileSampleProducer.java:64)
>         at 
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
>         at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
>         at java.lang.Thread.run(Thread.java:662)
> Caused by: java.lang.StackOverflowError
>         at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
>         at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
>         at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
>         at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
>         at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
>         at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
>         at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
>         at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
>         at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
>         at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078)
>         at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345)
>         at java.util.regex.Pattern$Branch.match(Pattern.java:4114)
>         at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168)
>         at java.util.regex.Pattern$Loop.match(Pattern.java:4295)
>         at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227)
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to