Re: BUG #5111: Segmentation fault, if to_tsvector returns empty row to ts_stat - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #5111: Segmentation fault, if to_tsvector returns empty row to ts_stat
Date
Msg-id 27480.1255443825@sss.pgh.pa.us
Whole thread Raw
In response to BUG #5111: Segmentation fault, if to_tsvector returns empty row to ts_stat  ("Fendris" <f.fendris@gmail.com>)
List pgsql-bugs
"Fendris" <f.fendris@gmail.com> writes:
> SELECT * from ts_stat('SELECT to_tsvector(''simple'','''')');
> [ dumps core ]

Thanks, looks like this code just missed the possibility of an empty
tree.  Attached patch fixes it.

            regards, tom lane

*** src/backend/utils/adt/tsvector_op.c.orig    Thu Jul 16 02:33:44 2009
--- src/backend/utils/adt/tsvector_op.c    Tue Oct 13 10:19:24 2009
***************
*** 959,975 ****

      node = stat->root;
      /* find leftmost value */
!     for (;;)
!     {
!         stat->stack[stat->stackpos] = node;
!         if (node->left)
          {
!             stat->stackpos++;
!             node = node->left;
          }
!         else
!             break;
!     }

      tupdesc = CreateTemplateTupleDesc(3, false);
      TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word",
--- 959,979 ----

      node = stat->root;
      /* find leftmost value */
!     if (node == NULL)
!         stat->stack[stat->stackpos] = NULL;
!     else
!         for (;;)
          {
!             stat->stack[stat->stackpos] = node;
!             if (node->left)
!             {
!                 stat->stackpos++;
!                 node = node->left;
!             }
!             else
!                 break;
          }
!     Assert(stat->stackpos <= stat->maxdepth);

      tupdesc = CreateTemplateTupleDesc(3, false);
      TupleDescInitEntry(tupdesc, (AttrNumber) 1, "word",
***************
*** 1015,1020 ****
--- 1019,1025 ----
              else
                  break;
          }
+         Assert(stat->stackpos <= stat->maxdepth);
      }
      else
      {

pgsql-bugs by date:

Previous
From: "Yury Don"
Date:
Subject: BUG #5112: Segmentation fault on ts_stat with empty words
Next
From: "Turner, Ian"
Date:
Subject: Re: Kerberos authentication, Active Directory, and PostgreSQL