Re: Endless looping

DM Smith <[email protected]> Mon, 16 Jun 2025 17:07:03 -0400
Newsgroups gmane.comp.literature.sword.devel
Message-ID <[email protected]>
Pinoaffe, Michael,

Attached is a patch that will fix the endless looping bug.

The problem was in a verse in a chapter that was not in the chosen versification. Nitty gritty, incrementing a bad verse should have set an error. The fix for that was in src/keys/versekey.cpp in checkBounds.

That uncovered another problem in osis2mod that such verses were not properly placed at the end of the book in the last chapter.

Hope you can build this locally before we can check in this patch. I want Troy to review it, especially for unintended side effects.

In Him,
	DM



> On Apr 3, 2025, at 3:39 AM, pinoaffe <[email protected]> wrote:
> 
> DM Smith <[email protected]> writes:
> 
>> Can you supply a mock osis xml that reliably goes into an infinite loop? I’ve heard reports of this
>> but cannot reproduce.
> I've attached a file test.xml that goes into an infinite loop when I run
> something like `osis2mod /tmp test.xml` on osis2mod version $Rev: 3769 $
> (SWORD: 1.9.0)
> 
> I don't know for sure whether this is the issue that was reported, but
> I've encountered this before: osis2mod seems to go into an infinite loop
> when it encounters a chapter that is not in the versification.  This (or
> similar infinite-looping issues with osis2mod) has been reported by
> several others on this mailing list.
>

> 
> Kind regards,
> pinoaffe
> _______________________________________________
> sword-devel mailing list: [email protected]
> http://crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page

_______________________________________________
sword-devel mailing list: [email protected]
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page
osis2mod-infinite-loop.patch (application/octet-stream, 1.3 KB)
Index: src/keys/versekey.cpp
===================================================================
--- src/keys/versekey.cpp	(revision 3900)
+++ src/keys/versekey.cpp	(working copy)
@@ -1747,6 +1747,12 @@
 
 	long i = getIndex();
 
+	// assert we're sane
+	if (i < 0) {
+		error = KEYERR_OUTOFBOUNDS;
+		return;
+	}
+
 	initBounds();
 	if (i > upperBound) {
 		setIndex(upperBound);
Index: utilities/osis2mod.cpp
===================================================================
--- utilities/osis2mod.cpp	(revision 3900)
+++ utilities/osis2mod.cpp	(working copy)
@@ -440,7 +440,8 @@
 	// Since isValidRef returned false constrain the key to the nearest prior reference.
 	// If we are past the last chapter set the reference to the last chapter
 	int chapterMax = key.getChapterMax();
-	if (key.getChapter() > chapterMax) {
+	bool beyondChapter = key.getChapter() > chapterMax;
+	if (beyondChapter) {
 		key.setChapter(chapterMax);
 	}
 
@@ -471,7 +472,7 @@
 	//    In this case we should re-versify Matt.7.30 as Matt.7.29.
 	//    However, since this and 2) are ambiguous, we'll re-reversify to the last entry in the module.
 	
-	while (!key.popError() && !module->hasEntry(&key)) {
+	while (!beyondChapter && !key.popError() && !module->hasEntry(&key)) {
 		key.decrement(1);
 	}
test.xml (application/xml, 7.6 KB)
<?xml version="1.0"?>
<osis xmlns="http://www.bibletechnologies.net/2003/OSIS/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.2.1.1.xsd">
  <osisText osisIDWork="WV75" osisRefWork="defaultReferenceScheme" xml:lang="nl">
    <header>
      <work osisWork="WV75">
        <title>Willibrordvertaling</title>
        <identifier type="OSIS">Bible.WV75</identifier>
        <scope>Gen-Rev</scope>
        <language type="IETF" use="base">nl</language>
        <refSystem>Bible.Catholic</refSystem>
      </work>
      <work osisWork="defaultReferenceScheme">
        <refSystem>Bible.Catholic</refSystem>
      </work>
    </header>
    <div type="book" osisID="Gen">
      <title level="2">Genesis</title>
      <div type="chapter" osisID="Gen.1" n="1">
        <verse osisID="Gen.1.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.2" n="1">
        <verse osisID="Gen.2.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.3" n="1">
        <verse osisID="Gen.3.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.4" n="1">
        <verse osisID="Gen.4.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.5" n="1">
        <verse osisID="Gen.5.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.6" n="1">
        <verse osisID="Gen.6.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.7" n="1">
        <verse osisID="Gen.7.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.8" n="1">
        <verse osisID="Gen.8.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.9" n="1">
        <verse osisID="Gen.9.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" o10isID="Gen.10" n="1">
        <verse osisID="Gen.1.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.11" n="1">
        <verse osisID="Gen.11.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.12" n="1">
        <verse osisID="Gen.12.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.13" n="1">
        <verse osisID="Gen.13.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.14" n="1">
        <verse osisID="Gen.14.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.15" n="1">
        <verse osisID="Gen.15.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.16" n="1">
        <verse osisID="Gen.16.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.17" n="1">
        <verse osisID="Gen.17.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.18" n="1">
        <verse osisID="Gen.18.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.19" n="1">
        <verse osisID="Gen.19.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.20" n="1">
        <verse osisID="Gen.20.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.21" n="1">
        <verse osisID="Gen.21.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.22" n="1">
        <verse osisID="Gen.22.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.23" n="1">
        <verse osisID="Gen.23.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.24" n="1">
        <verse osisID="Gen.24.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" o25isID="Gen.25" n="1">
        <verse osisID="Gen.1.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.26" n="1">
        <verse osisID="Gen.26.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.27" n="1">
        <verse osisID="Gen.27.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.28" n="1">
        <verse osisID="Gen.28.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.29" n="1">
        <verse osisID="Gen.29.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.30" n="1">
        <verse osisID="Gen.30.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.31" n="1">
        <verse osisID="Gen.31.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.32" n="1">
        <verse osisID="Gen.32.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.33" n="1">
        <verse osisID="Gen.33.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.34" n="1">
        <verse osisID="Gen.34.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.35" n="1">
        <verse osisID="Gen.35.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.36" n="1">
        <verse osisID="Gen.36.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.37" n="1">
        <verse osisID="Gen.37.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.38" n="1">
        <verse osisID="Gen.38.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.39" n="1">
        <verse osisID="Gen.39.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" o40isID="Gen.40" n="1">
        <verse osisID="Gen.1.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.41" n="1">
        <verse osisID="Gen.41.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.42" n="1">
        <verse osisID="Gen.42.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.43" n="1">
        <verse osisID="Gen.43.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.44" n="1">
        <verse osisID="Gen.44.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.45" n="1">
        <verse osisID="Gen.45.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.46" n="1">
        <verse osisID="Gen.46.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.47" n="1">
        <verse osisID="Gen.47.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.48" n="1">
        <verse osisID="Gen.48.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.49" n="1">
        <verse osisID="Gen.49.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.50" n="1">
        <verse osisID="Gen.50.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.51" n="1">
        <verse osisID="Gen.51.1"><p>This is a test file</p></verse>
      </div>
      <div type="chapter" osisID="Gen.52" n="1">
        <verse osisID="Gen.52.1"><p>This is a test file</p></verse>
      </div>
    </div>
  </osisText>
</osis>