I've prepared patches against release-1.0, release-1.9, and
trunk.  The patch just raises a ValueError exception with
the next 'Expected a string'.

I've attached the patches, FWIW.

-matthew

Matthew O'Connor [EMAIL PROTECTED] said:

> This error happens in p2j() in PyLucene.i.  We have the
> following code:
> 
>     char *ps = PyString_AsString(object);
>     jstring js = JvNewStringUTF(ps);
> 
> But PyString_AsString() returns NULL for non-string objects.
> I guess the right thing is to either call __str__ on the
> object or just raise an exception.
> 
> -matthew
> 
> Matthew O'Connor [EMAIL PROTECTED] said:
> 
> > I got the OS X precompiled binaries for PyLucene 1.0.1
> > working on my laptop.  I see a similar error:
> > 
> >     [EMAIL PROTECTED](10:04)$ python bug.py
> >     Test 1:  [<PyLucene.Field; proxy of C++ 
> > org::apache::lucene::document::Field instance at <PyCObject object at 
> > 0xd7a0>>]
> >     Test 2:  None
> >     Bus error (core dumped)
> > 
> > -matthew
> > 
> > Matthew O'Connor [EMAIL PROTECTED] said:
> > 
> > > I had a bug in some code last night where I accidentally
> > > passed in the integer 1 into getFields() and this caused
> > > Python to abort and exit out.  Is this behavior expected?  I
> > > don't have access to any machines that can run the
> > > precompiled binaries so hopefully there's nothing weird w/
> > > the compiler tools I used.
> > > 
> > > Here's a minimal amount of code that reproduces the issue.
> > > I can get the following to crash using both PyLucene 1.9 and
> > > PyLucene 1.0.1 (both compiled from source):
> > > 
> > >     import PyLucene
> > >     d = PyLucene.Document()
> > >     f = PyLucene.Field('breed', 'bulldog', True, True, True)
> > >     d.add(f)
> > >     print 'Test 1: ', d.getFields('breed')   # Works
> > >     print 'Test 2: ', d.getFields('1')       # Works
> > >     print 'Test 3: ', d.getFields(1)         # Crashes
> > >     print 'ALL DONE'
> > > 
> > > The output is as follows:
> > > 
> > >     $ python2.4 bug.py
> > >     Test 1:  [<PyLucene.Field; proxy of C++ 
> > > org::apache::lucene::document::Field instance at <PyCObject object at 
> > > 0xb7a38068>>]
> > >     Test 2:  None
> > >     Test 3: Aborted
> > >     $
> > > 
> > > Here's the system / tools I used:
> > > 
> > >     OS: Debian GNU/Linux Stable (Sarge)
> > >     Kernel: 2.6.11.9
> > >     CPU: Pentium 4 / 2.8 GHz
> > >     Memory: 250MB
> > >     Python 2.4.1
> > >     gcj 3.4.4
> > >     SWIG 1.3.24
> > >     PyLucene 1.9 and 1.0.1 (tested seperately)
> > > 
> > > Python, GCJ, and SWIG are provided by standard Debian
> > > packages.  
> > > 
> > > -matthew
> > > _______________________________________________
> > > pylucene-dev mailing list
> > > [email protected]
> > > http://lists.osafoundation.org/mailman/listinfo/pylucene-dev
> > > 
> > _______________________________________________
> > pylucene-dev mailing list
> > [email protected]
> > http://lists.osafoundation.org/mailman/listinfo/pylucene-dev
> > 
> _______________________________________________
> pylucene-dev mailing list
> [email protected]
> http://lists.osafoundation.org/mailman/listinfo/pylucene-dev
> 
Index: PyLucene.i
===================================================================
--- PyLucene.i  (revision 242)
+++ PyLucene.i  (working copy)
@@ -510,8 +510,12 @@
     else
     {
         char *ps = PyString_AsString(object);
+        if (!ps) {
+            PyErr_SetString(PyExc_ValueError, "Expected a string");
+            return NULL;
+        }
+
         jstring js = JvNewStringUTF(ps);
-
         if (!js)
             PyErr_Format(PyExc_ValueError,
                          "python str is not unicode or utf-8 encoded: %s", ps);
Index: PyLucene.i
===================================================================
--- PyLucene.i  (revision 242)
+++ PyLucene.i  (working copy)
@@ -505,8 +505,12 @@
     else
     {
         char *ps = PyString_AsString(object);
+        if (!ps) {
+            PyErr_SetString(PyExc_ValueError, "Expected a string");
+            return NULL;
+        }
+
         jstring js = JvNewStringUTF(ps);
-
         if (!js)
             PyErr_Format(PyExc_ValueError,
                          "python str is not unicode or utf-8 encoded: %s", ps);
Index: PyLucene.i
===================================================================
--- PyLucene.i  (revision 242)
+++ PyLucene.i  (working copy)
@@ -469,8 +469,12 @@
     else
     {
         char *ps = PyString_AsString(object);
+        if (!ps) {
+            PyErr_SetString(PyExc_ValueError, "Expected a string");
+            return NULL;
+        }
+
         jstring js = JvNewStringUTF(ps);
-
         if (!js)
         {
             char msg[strlen(ps) + 64];
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to