Menu

#293 hfst-reweight crashes on TSV reweight file

future
closed
nobody
None
1
2015-04-24
2015-04-08
sjurum
No

To reproduce, store the following content in a file tags.reweight:

+Cmp    +2
+Der    +2

Then run the following command (the input fst can be any fst):

hfst-reweight -T tags.reweight -i generator-fstspeller-gt-norm.hfst > /dev/null 

Actual result:

hfst-reweight(1434,0x7fff753f2300) malloc: *** error for object 0x7fff5d47d390: pointer being realloc'd was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

Expected result: No crash, and a reweighted fst.

Discussion

  • sjurum

    sjurum - 2015-04-21

    I looked further into this bug, and located the bug in the function 'hfst_getline()' on line 673 in the file ''tools/src/hfst-commandline.cc''. I added a couple of debug statements, so that the function code looks like the following:

    ssize_t
    hfst_getline(char** lineptr, size_t* n, FILE* stream)
    {
      errno = 0;
      ssize_t rv = -1;
      verbose_printf("Debugging tsv - 1\n"); 
      rv = getline(lineptr, n, stream);
      verbose_printf("Debugging tsv - 2\n"); 
      if ((rv < 0) && errno)
        {
          error(EXIT_FAILURE, errno, "getline failed");
        }
      return rv;
    }
    

    When running hfst-reweight using this modified version of hfst-commandline.cc, I get the following:

    $ make analyser-fstspeller-gt-norm.hfst 
      CP       generator-fstspeller-gt-norm.tmp.hfst
      GEN      generator-fstspeller-gt-norm.tmp1.hfst
    Reading from <stdin>, writing to <stdout>
    Modifying weights 0.000000 < w < 340282346638528859811704183484516925440.000000 as 1.000000 * id(w) + 0.000000
    Reweighting minimize(determinize(push-weights-f(remove-epsilons(reweight(?stdin?)))))...
    Reading reweights from ../../../../../tools/spellcheckers/fstbased/weighting/tags.reweight
    Debugging tsv - 1
    hfst-reweight(91813,0x7fff774d7300) malloc: *** error for object 0x7fff57a54390: pointer being realloc'd was not allocated
    *** set a breakpoint in malloc_error_break to debug
    /bin/sh: line 1: 91813 Abort trap: 6           /usr/local/bin/hfst-reweight -v -T ../../../../../tools/spellcheckers/fstbased/weighting/tags.reweight < generator-fstspeller-gt-norm.tmp.hfst > generator-fstspeller-gt-norm.tmp1.hfst
    make: *** [generator-fstspeller-gt-norm.tmp1.hfst] Error 134
    

    Based on the above, it looks like the bug is on the line:

      rv = getline(lineptr, n, stream);
    
     
  • sjurum

    sjurum - 2015-04-21

    In the end, the error was in hfst-reweight.cc. A pointer was not initialised. The bug should be fixed in revision 4329.

    Please review, and close the bug report if the commit is ok.

     
  • Erik Axelson

    Erik Axelson - 2015-04-24
    • status: open --> closed