Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SolrException: Invalid Number when searching on d:int property with value exceeding Integer.MAX_VALUE #334

Open
kerkhofsd opened this issue Jun 23, 2020 · 4 comments

Comments

@kerkhofsd
Copy link

Steps to reproduce

  • perform a search on a property of type d:int, with query value exceeding the Integer.MAX_VALUE value.
  • same for properties of type d:long when searching with value exceeding Long.MAX_VALUE

Context
To fix MNT-19252, following code has been introduced in the Solr4QueryParser to check if the queryText is a valid numeric:

            isNumeric = (schemaField.getType().getNumericType() != null);
            if (isNumeric)
            {
                //Check to see if queryText is numeric or else it will fail.
                try
                {
                    Double.valueOf(queryText);
                }
                catch (NumberFormatException e)
                {
                    return new TermQuery(new Term("_dummy_", "_miss_"));
                }
            }

However in the edge case where queryText is a number, but exceeds e.g. Integer.MAX_VALUE, Double.valueOf(queryText); will not throw a NumberFormatException and later a SolrException: Invalid Number exception will be thrown.

Stacktrace
Reproducable by searching for sys:node\-dbid: 123456789123456789123456789 in the Alfresco admin panel.
This results in following stacktrace in SearchServices:

2020-06-23 15:11:33.435 ERROR (qtp440938038-20) [   x:alfresco] o.a.s.h.RequestHandlerBase org.apache.solr.common.SolrException: Invalid Number: 123456789123456789123456789
	at org.apache.solr.schema.TrieField.readableToIndexed(TrieField.java:455)
	at org.apache.solr.schema.TrieField.readableToIndexed(TrieField.java:427)
	at org.apache.solr.schema.TrieField.toInternal(TrieField.java:462)
	at org.apache.solr.schema.FieldType$DefaultAnalyzer$1.incrementToken(FieldType.java:508)
	at org.alfresco.solr.query.Solr4QueryParser.getFieldQueryImpl(Solr4QueryParser.java:1621)
	at org.alfresco.solr.query.Solr4QueryParser.getFieldQueryImplWithIOExceptionWrapped(Solr4QueryParser.java:1129)
	at org.alfresco.solr.query.Solr4QueryParser.getSuperFieldQuery(Solr4QueryParser.java:3830)
	at org.alfresco.solr.query.Solr4QueryParser$FieldQuery.getQuery(Solr4QueryParser.java:3936)
	at org.alfresco.solr.query.Solr4QueryParser.attributeQueryBuilder(Solr4QueryParser.java:4392)
	at org.alfresco.solr.query.Solr4QueryParser.getFieldQuery(Solr4QueryParser.java:631)
	at org.alfresco.solr.query.Lucene4QueryParserAdaptor.getFieldQuery(Lucene4QueryParserAdaptor.java:67)
	at org.alfresco.solr.query.Lucene4QueryParserAdaptor.getFieldQuery(Lucene4QueryParserAdaptor.java:48)
	at org.alfresco.repo.search.impl.querymodel.impl.lucene.functions.LuceneFTSTerm.addComponent(LuceneFTSTerm.java:75)
	at org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneFunctionalConstraint.addComponent(LuceneFunctionalConstraint.java:63)
	at org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQuery.buildQuery(LuceneQuery.java:110)
	at org.alfresco.solr.AlfrescoSolrDataModel.getFTSQuery(AlfrescoSolrDataModel.java:1475)
	at org.alfresco.solr.query.AlfrescoFTSQParserPlugin$AlfrescoFTSQParser.parse(AlfrescoFTSQParserPlugin.java:105)
	at org.apache.solr.search.QParser.getQuery(QParser.java:168)
	at org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:161)
	at org.apache.solr.handler.component.AlfrescoSearchHandler.handleRequestBody(AlfrescoSearchHandler.java:323)
	at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:173)
	at org.apache.solr.core.SolrCore.execute(SolrCore.java:2477)
	at org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:723)
	at org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:529)
	at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:361)
	at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:305)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1691)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
	at org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:335)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)
	at org.eclipse.jetty.server.Server.handle(Server.java:534)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
	at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:202)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
	at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)
	at java.base/java.lang.Thread.run(Thread.java:834)

@kerkhofsd kerkhofsd changed the title SolrException: 'Invalid Number' when searching on d:int property with value exceeding Integer.MAX_VALUE SolrException: Invalid Number when searching on d:int property with value exceeding Integer.MAX_VALUE Jun 23, 2020
@kerkhofsd
Copy link
Author

I tried to pinpoint the issue by adding failing tests to QParserPluginIT on:
https://github.com/kerkhofsd/SearchServices/commit/e97efc71990a9653815c41b47d8bd34dce29a58c

@aborroy
Copy link
Contributor

aborroy commented Jun 24, 2020

Not sure this is a valid issue, as 123456789123456789123456789 is effectively an invalid Number.

@tgeens
Copy link

tgeens commented Jun 24, 2020

Real world use case: alfresco is configured with a custom search-query-template, that includes some custom properties.

Example: %(cm:name company:contractNumber company:someNumber)
The user wants to put in a search term and those 3 properties should be searched:

  • cm:name
  • company:contractNumber (type d:text)
  • company:someNumber (type d:int)

User searches for company:someNumber - "12345" - works fine!
User searches for a 10-digit contract number "9876543210" - implicitly expecting it to match the company:contractNumber. But this query will fail in solr, for the reasons above: "9876543210" does not fit into a 32-bit integer, solr will return an HTTP 400.

This is reproducible in a vanilla set up by simulating this with a query template like %(cm:name exif:pixelXDimension)

@aborroy
Copy link
Contributor

aborroy commented Jul 1, 2020

We've created https://issues.alfresco.com/jira/browse/SEARCH-2331 to proceed with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants