You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/02/25 03:37:02 UTC

[lucy-commits] svn commit: r1074381 - in /incubator/lucy/trunk/core/Lucy: Search/IndexSearcher.c Search/Searcher.c Util/PriorityQueue.c

Author: marvin
Date: Fri Feb 25 02:37:02 2011
New Revision: 1074381

URL: http://svn.apache.org/viewvc?rev=1074381&view=rev
Log:
Guard against excessive search result size requests.

Modified:
    incubator/lucy/trunk/core/Lucy/Search/IndexSearcher.c
    incubator/lucy/trunk/core/Lucy/Search/Searcher.c
    incubator/lucy/trunk/core/Lucy/Util/PriorityQueue.c

Modified: incubator/lucy/trunk/core/Lucy/Search/IndexSearcher.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Search/IndexSearcher.c?rev=1074381&r1=1074380&r2=1074381&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Search/IndexSearcher.c (original)
+++ incubator/lucy/trunk/core/Lucy/Search/IndexSearcher.c Fri Feb 25 02:37:02 2011
@@ -116,7 +116,9 @@ IxSearcher_top_docs(IndexSearcher *self,
                     SortSpec *sort_spec)
 {
     Schema        *schema    = IxSearcher_Get_Schema(self);
-    SortCollector *collector = SortColl_new(schema, sort_spec, num_wanted);
+    uint32_t       doc_max   = IxSearcher_Doc_Max(self);
+    uint32_t       wanted    = num_wanted > doc_max ? doc_max : num_wanted;
+    SortCollector *collector = SortColl_new(schema, sort_spec, wanted);
     IxSearcher_Collect(self, query, (Collector*)collector);
     {
         VArray  *match_docs = SortColl_Pop_Match_Docs(collector);

Modified: incubator/lucy/trunk/core/Lucy/Search/Searcher.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Search/Searcher.c?rev=1074381&r1=1074380&r2=1074381&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Search/Searcher.c (original)
+++ incubator/lucy/trunk/core/Lucy/Search/Searcher.c Fri Feb 25 02:37:02 2011
@@ -52,8 +52,12 @@ Searcher_hits(Searcher *self, Obj *query
               SortSpec *sort_spec)
 {
     Query   *real_query = Searcher_Glean_Query(self, query);
-    TopDocs *top_docs   = Searcher_Top_Docs(self, real_query, 
-                                offset + num_wanted, sort_spec);
+    uint32_t doc_max    = Searcher_Doc_Max(self);
+    uint32_t wanted     = offset + num_wanted > doc_max 
+                        ? doc_max 
+                        : offset + num_wanted;
+    TopDocs *top_docs   = Searcher_Top_Docs(self, real_query, wanted, 
+                                            sort_spec);
     Hits    *hits       = Hits_new(self, top_docs, offset);
     DECREF(top_docs);
     DECREF(real_query);

Modified: incubator/lucy/trunk/core/Lucy/Util/PriorityQueue.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Util/PriorityQueue.c?rev=1074381&r1=1074380&r2=1074381&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Util/PriorityQueue.c (original)
+++ incubator/lucy/trunk/core/Lucy/Util/PriorityQueue.c Fri Feb 25 02:37:02 2011
@@ -41,6 +41,9 @@ S_down_heap(PriorityQueue *self);
 PriorityQueue*
 PriQ_init(PriorityQueue *self, uint32_t max_size)
 {
+    if (max_size == U32_MAX) {
+        THROW(ERR, "max_size too large: %u32", max_size);
+    }
     uint32_t heap_size = max_size + 1;
 
     // Init.