[sword-devel] osis2mod bug

DM Smith dmsmith at crosswire.org
Mon Jan 4 09:52:45 MST 2010

I took a quick look at the problem. Seems that osis2mod chokes on 
chapter numbers that are not in the book.
(It works just fine if the chapter is valid but the verse number is not. 
And I still cannot reproduce the bug where it chokes on a book not in 
the versification.)

Here is the smallest valid OSIS input that reproduces the problem:
<?xml version="1.0" encoding="UTF-8"?><osis 
<osisText osisIDWork="KJV" osisRefWork="defaultReferenceScheme" 
<work osisWork="KJV">
<title>King James Version (1769)</title>
<identifier type="OSIS">Bible.KJV</identifier>
<work osisWork="defaultReferenceScheme">
<div type="book" osisID="Matt" canonical="true">
<chapter osisID="Matt.29">
<verse osisID="Matt.29.1">Matt.29.1 is not in the KJV versification</verse>

Since osis2mod does not care about the header, the following will do the 
<verse osisID="Matt.29.1">Matt.29.1 is not in the KJV versification</verse>

A quick look shows the problem in this osis2mod code (lines 773-800):

// Get osisID for verse or annotateRef for commentary
SWBuf keyVal = token.getAttribute(tokenName == "verse" ? "osisID" : 

// Massage the key into a form that ParseVerseList can accept

// The osisID or annotateRef can be more than a single verse
// The first or only one is the currentVerse
// Use the last verse seen (i.e. the currentVerse) as the basis for 
recovering from bad parsing.
// This should never happen if the references are valid OSIS references
ListKey verseKeys = currentVerse.ParseVerseList(keyVal, currentVerse, true);
int memberKeyCount = verseKeys.Count();
if (memberKeyCount) {
     currentVerse = verseKeys.getElement(0);
     // See if this osisID or annotateRef refers to more than one verse.
     // If it does, save it until all verses have been seen.
     // At that point we will output links.
     // This can be done by incrementing, which will produce an error
     // if there is only one verse.
     if (!verseKeys.Error()) {
else {
     cout << "ERROR(REF): Invalid osisID/annotateRef: " << 
token.getAttribute((tokenName == "verse") ? "osisID" :

In looking at the stack trace it gets into an infinite loop when calling:

This calls Index(pos) with a value of 0, and recursively calls it with a 
value of -1. Once it does that, it spins until a segfault calling malloc.

Some help would be appreciated since I have very little extra time this 

In Him,

More information about the sword-devel mailing list