Project

Profile

Help

Bug #5343

closed

Error found when converting array of XdmValue to XdmArray

Added by O'Neil Delpratt 6 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Category:
Python
Start date:
2022-02-21
Due date:
% Done:

100%

Estimated time:
Found in version:
11.2
Fixed in version:
11.3
Platforms:

Description

Reported by user here: https://saxonica.plan.io/boards/4/topics/8573

The simple python script which creates a PyXdmArray object:

from saxonc import *

with PySaxonProcessor(license=False) as proc:
    print("Test SaxonC on Python")
    print(proc.version)
    
    xdm_value = PyXdmValue()
    for i in range(1, 6):
        xdm_value.add_xdm_item(proc.make_array([proc.make_integer_value(n) for n in range(1, i)]))

    print(isinstance(xdm_value, PyXdmValue))
    
    print(xdm_value)
    
    for item in xdm_value:
        print(isinstance(item, PyXdmItem))
        print(isinstance(item, PyXdmArray))
        print(item)

Prints the following error message before SaxonC crashes:

Error found when converting array of XdmValue to XdmArray
Actions #1

Updated by O'Neil Delpratt 5 months ago

  • Description updated (diff)
Actions #2

Updated by O'Neil Delpratt 5 months ago

I ran gdb tool in the following sequence:

gdb python3
(gdb) handle SIG35 noprint nostop
(gdb) run example_loop_XdmArray.py 

See output:

Test SaxonC on Python
SaxonC-HE 11.1 from Saxonica
Error found when converting array of XdmValue to XdmArray
Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
0x00007ffff6c1d076 in XdmValue::addXdmItem (this=0x1131780, val=<optimised out>) at ../XdmValue.cpp:186
186	        val->incrementRefCount();

Also with the bt command:

(gdb) bt
#0  0x00007ffff6c1d076 in XdmValue::addXdmItem (this=0x1131780, val=<optimised out>) at ../XdmValue.cpp:186
#1  0x00007ffff6bc6465 in __pyx_pf_6saxonc_10PyXdmValue_4add_xdm_item (__pyx_v_self=0x7ffff6ce9bd0, __pyx_v_value=0x90ba10 <_Py_NoneStruct>) at saxonc.cpp:38249
#2  __pyx_pw_6saxonc_10PyXdmValue_5add_xdm_item (__pyx_v_self=0x7ffff6ce9bd0, __pyx_v_value=0x90ba10 <_Py_NoneStruct>) at saxonc.cpp:38226
#3  0x00000000005042e6 in ?? ()
#4  0x000000000056b5e0 in _PyEval_EvalFrameDefault ()
#5  0x00000000005696da in _PyEval_EvalCodeWithName ()
#6  0x000000000068db17 in PyEval_EvalCode ()
#7  0x000000000067eeb1 in ?? ()
#8  0x000000000067ef2f in ?? ()
#9  0x000000000067efd1 in ?? ()
#10 0x000000000067f377 in PyRun_SimpleFileExFlags ()
#11 0x00000000006b7902 in Py_RunMain ()
#12 0x00000000006b7c8d in Py_BytesMain ()
#13 0x00007ffff7deb0b3 in __libc_start_main (main=0x4eed30 <main>, argc=2, argv=0x7fffffffe1f8, init=<optimised out>, fini=<optimised out>, rtld_fini=<optimised out>, stack_end=0x7fffffffe1e8)
    at ../csu/libc-start.c:308
#14 0x00000000005fb12e in _start ()

It is is clear we are trying to add an XdmItem to the XdmValue which is a nullptr. We should safeguard this happening but also investigate why.

Actions #3

Updated by O'Neil Delpratt 5 months ago

  • Status changed from New to In Progress

Bug fixed for when we try to create an array with zero items. Fix applied in the proc.make_array method. I have also added some conditional code in add_xdm_item to avoid the Segmentation error.

Actions #4

Updated by O'Neil Delpratt 5 months ago

  • Status changed from In Progress to Resolved
  • % Done changed from 0 to 100

After further investigation the SaxonProcessor.makeArray method in the C++ API is not correctly handling the empty array. This has now been fixed. For the example in comment 0 we are now getting as output the sequence:

[]
[1]
[1,2]
[1,2,3]
[1,2,3,4]
Actions #5

Updated by O'Neil Delpratt 4 months ago

  • Status changed from Resolved to Closed
  • Fixed in version set to 11.3

Bug fix applied in the SaxonC 11.3 maintenance release.

Please register to edit this issue

Also available in: Atom PDF