[liblouis-liblouisxml] Re: Another crash in Python hyphenation

  • From: Milan Zamazal <pdm@xxxxxxxxxxxx>
  • To: Christian Egli <christian.egli@xxxxxx>
  • Date: Fri, 23 Nov 2012 20:44:56 +0100

Thanks for the hint.  The attached patch prevents the crash.  But it may
still be just a workaround.  The problem is here in
lou_translateString.c:

    stateFound:
      currentState = &statesArray[stateNum];
      if (currentState->hyphenPattern)
        {
          hyphenPattern =
            (char *) &table->ruleArea[currentState->hyphenPattern];
          patternOffset = i + 1 - strlen (hyphenPattern);
          for (k = 0; patternOffset + k < wordSize && hyphenPattern[k]; k++)
            if (hyphens[patternOffset + k] < hyphenPattern[k])
              hyphens[patternOffset + k] = hyphenPattern[k];
        }

At the start of the for cycle:

  i = 16
  j = 17
  wordSize = 15
  patternOffset = 14
  hyphenPattern = "200"

I've got no idea how the algorithm works so someone knowledgeable should
look at it.  But the attached patch should probably be applied anyway.

Index: liblouis/lou_translateString.c
===================================================================
--- liblouis/lou_translateString.c      (revision 836)
+++ liblouis/lou_translateString.c      (working copy)
@@ -377,7 +377,7 @@
          hyphenPattern =
            (char *) &table->ruleArea[currentState->hyphenPattern];
          patternOffset = i + 1 - strlen (hyphenPattern);
-         for (k = 0; hyphenPattern[k]; k++)
+         for (k = 0; patternOffset + k < wordSize && hyphenPattern[k]; k++)
            if (hyphens[patternOffset + k] < hyphenPattern[k])
              hyphens[patternOffset + k] = hyphenPattern[k];
        }

Other related posts: