[jira] [Commented] (SOLR-13181) NullPointerException in org.apache.solr.request.macro.MacroExpander

2019-02-01 Thread Cesar Rodriguez (JIRA)


[ 
https://issues.apache.org/jira/browse/SOLR-13181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16758597#comment-16758597
 ] 

Cesar Rodriguez commented on SOLR-13181:


Thanks [~cpoerschke], and sorry for the patch naming, I've renamed the file now.

I will try to write a test, but note that I found this bug using an automatic 
tool and I'm not sure I follow the code very well!

> NullPointerException in org.apache.solr.request.macro.MacroExpander
> ---
>
> Key: SOLR-13181
> URL: https://issues.apache.org/jira/browse/SOLR-13181
> Project: Solr
>  Issue Type: Bug
>  Security Level: Public(Default Security Level. Issues are Public) 
>Affects Versions: master (9.0)
> Environment: h1. Steps to reproduce
> * Use a Linux machine.
> *  Build commit {{ea2c8ba}} of Solr as described in the section below.
> * Build the films collection as described below.
> * Start the server using the command {{./bin/solr start -f -p 8983 -s 
> /tmp/home}}
> * Request the URL given in the bug description.
> h1. Compiling the server
> {noformat}
> git clone https://github.com/apache/lucene-solr
> cd lucene-solr
> git checkout ea2c8ba
> ant compile
> cd solr
> ant server
> {noformat}
> h1. Building the collection
> We followed [Exercise 
> 2|http://lucene.apache.org/solr/guide/7_5/solr-tutorial.html#exercise-2] from 
> the [Solr 
> Tutorial|http://lucene.apache.org/solr/guide/7_5/solr-tutorial.html]. The 
> attached file ({{home.zip}}) gives the contents of folder {{/tmp/home}} that 
> you will obtain by following the steps below:
> {noformat}
> mkdir -p /tmp/home
> echo '' > 
> /tmp/home/solr.xml
> {noformat}
> In one terminal start a Solr instance in foreground:
> {noformat}
> ./bin/solr start -f -p 8983 -s /tmp/home
> {noformat}
> In another terminal, create a collection of movies, with no shards and no 
> replication, and initialize it:
> {noformat}
> bin/solr create -c films
> curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field": 
> {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' 
> http://localhost:8983/solr/films/schema
> curl -X POST -H 'Content-type:application/json' --data-binary 
> '{"add-copy-field" : {"source":"*","dest":"_text_"}}' 
> http://localhost:8983/solr/films/schema
> ./bin/post -c films example/films/films.json
> {noformat}
>Reporter: Cesar Rodriguez
>Priority: Minor
>  Labels: diffblue, newdev
> Attachments: SOLR-13181.patch, home.zip
>
>
> Requesting the following URL causes Solr to return an HTTP 500 error response:
> {noformat}
> http://localhost:8983/solr/films/select?a=${${b}}
> {noformat}
> The error response seems to be caused by the following uncaught exception:
> {noformat}
> java.lang.StringIndexOutOfBoundsException: String index out of range: -4
>   at java.lang.String.substring(String.java:1967)
>   at 
> org.apache.solr.request.macro.MacroExpander._expand(MacroExpander.java:150)
>   at 
> org.apache.solr.request.macro.MacroExpander.expand(MacroExpander.java:101)
>   at 
> org.apache.solr.request.macro.MacroExpander.expand(MacroExpander.java:65)
>   at 
> org.apache.solr.request.macro.MacroExpander.expand(MacroExpander.java:51)
>   at 
> org.apache.solr.request.json.RequestUtil.processParams(RequestUtil.java:159)
>   at 
> org.apache.solr.util.SolrPluginUtils.setDefaults(SolrPluginUtils.java:167)
>   at 
> org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:196)
> [...]
> {noformat}
> Parameter [macro 
> expansion|http://yonik.com/solr-query-parameter-substitution/] seems to take 
> place in {{org.apache.solr.request.macro.MacroExpander._expand(String val)}}. 
> From reading the code of the function it seems that macros are not expanded 
> inside curly brackets {{${...}}}, and so the {{${b}}} inside
> {noformat}
> ${${b}}
> {noformat}
> should not be expanded. But the function seems to fail to detect this 
> specific case and graciously refuse to expand it.
> A possible fix could be updating the {{idx}} variable when the {{StrParser}} 
> detects that no valid identifier can be found inside the brackets. See 
> attached file 
> {{0001-Macro-expander-fail-gracefully-on-unsupported-syntax.patch}}.
> We found this bug using [Diffblue Microservices 
> Testing|https://www.diffblue.com/labs/]. Find more information on this [fuzz 
> testing 
> campaign|https://www.diffblue.com/blog/2018/12/19/diffblue-microservice-testing-a-sneak-peek-at-our-early-product-and-results].



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



[jira] [Commented] (SOLR-13181) NullPointerException in org.apache.solr.request.macro.MacroExpander

2019-01-30 Thread Christine Poerschke (JIRA)


[ 
https://issues.apache.org/jira/browse/SOLR-13181?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16756549#comment-16756549
 ] 

Christine Poerschke commented on SOLR-13181:


Interesting edge case for the macro expander! And thanks [~cesar.rodriguez] for 
attaching the initial 
{{0001-Macro-expander-fail-gracefully-on-unsupported-syntax.patch}} patch.

I wonder if a test case could be added (say) in the 
[https://github.com/apache/lucene-solr/blob/master/solr/core/src/test/org/apache/solr/request/macro/TestMacroExpander.java]
 tests?

([https://wiki.apache.org/solr/HowToContribute#Contributing_your_work] has a 
lot of info but maybe the most actionable suggestion here in this context would 
be that if the next patch file was named (say) SOLR-13181.patch then the 
automatic validation of JIRA patches could be used with that. Hope that helps?)

> NullPointerException in org.apache.solr.request.macro.MacroExpander
> ---
>
> Key: SOLR-13181
> URL: https://issues.apache.org/jira/browse/SOLR-13181
> Project: Solr
>  Issue Type: Bug
>  Security Level: Public(Default Security Level. Issues are Public) 
>Affects Versions: master (9.0)
> Environment: h1. Steps to reproduce
> * Use a Linux machine.
> *  Build commit {{ea2c8ba}} of Solr as described in the section below.
> * Build the films collection as described below.
> * Start the server using the command {{./bin/solr start -f -p 8983 -s 
> /tmp/home}}
> * Request the URL given in the bug description.
> h1. Compiling the server
> {noformat}
> git clone https://github.com/apache/lucene-solr
> cd lucene-solr
> git checkout ea2c8ba
> ant compile
> cd solr
> ant server
> {noformat}
> h1. Building the collection
> We followed [Exercise 
> 2|http://lucene.apache.org/solr/guide/7_5/solr-tutorial.html#exercise-2] from 
> the [Solr 
> Tutorial|http://lucene.apache.org/solr/guide/7_5/solr-tutorial.html]. The 
> attached file ({{home.zip}}) gives the contents of folder {{/tmp/home}} that 
> you will obtain by following the steps below:
> {noformat}
> mkdir -p /tmp/home
> echo '' > 
> /tmp/home/solr.xml
> {noformat}
> In one terminal start a Solr instance in foreground:
> {noformat}
> ./bin/solr start -f -p 8983 -s /tmp/home
> {noformat}
> In another terminal, create a collection of movies, with no shards and no 
> replication, and initialize it:
> {noformat}
> bin/solr create -c films
> curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field": 
> {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' 
> http://localhost:8983/solr/films/schema
> curl -X POST -H 'Content-type:application/json' --data-binary 
> '{"add-copy-field" : {"source":"*","dest":"_text_"}}' 
> http://localhost:8983/solr/films/schema
> ./bin/post -c films example/films/films.json
> {noformat}
>Reporter: Cesar Rodriguez
>Priority: Minor
> Attachments: 
> 0001-Macro-expander-fail-gracefully-on-unsupported-syntax.patch, home.zip
>
>
> Requesting the following URL causes Solr to return an HTTP 500 error response:
> {noformat}
> http://localhost:8983/solr/films/select?a=${${b}}
> {noformat}
> The error response seems to be caused by the following uncaught exception:
> {noformat}
> java.lang.StringIndexOutOfBoundsException: String index out of range: -4
>   at java.lang.String.substring(String.java:1967)
>   at 
> org.apache.solr.request.macro.MacroExpander._expand(MacroExpander.java:150)
>   at 
> org.apache.solr.request.macro.MacroExpander.expand(MacroExpander.java:101)
>   at 
> org.apache.solr.request.macro.MacroExpander.expand(MacroExpander.java:65)
>   at 
> org.apache.solr.request.macro.MacroExpander.expand(MacroExpander.java:51)
>   at 
> org.apache.solr.request.json.RequestUtil.processParams(RequestUtil.java:159)
>   at 
> org.apache.solr.util.SolrPluginUtils.setDefaults(SolrPluginUtils.java:167)
>   at 
> org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:196)
> [...]
> {noformat}
> Parameter [macro 
> expansion|http://yonik.com/solr-query-parameter-substitution/] seems to take 
> place in {{org.apache.solr.request.macro.MacroExpander._expand(String val)}}. 
> From reading the code of the function it seems that macros are not expanded 
> inside curly brackets {{${...}}}, and so the {{${b}}} inside
> {noformat}
> ${${b}}
> {noformat}
> should not be expanded. But the function seems to fail to detect this 
> specific case and graciously refuse to expand it.
> A possible fix could be updating the {{idx}} variable when the {{StrParser}} 
> detects that no valid identifier can be found inside the brackets. See 
> attached file 
> {{0001-Macro-expander-fail-gracefully-on-unsupported-syntax.patch}}.
> We found this bug using [Diffblue Microservices 
>