adrian-thurston / ragel

Ragel State Machine Compiler
MIT License
532 stars 46 forks source link

Ragel 7 crashes on assertion on state machine that compiles fine on Ragel 6 #58

Closed leandrosansilva closed 3 years ago

leandrosansilva commented 3 years ago

Hi, I've just found out that some code I have compiling fine on ragel 6.10 fails on version 7.

Version: 7.0.0.12, from Fedora 32 amd64 (dnf install ragel)

I am using it to build go code (using ragel -Z on version 6.10 and ragel-go on 7).

I have two input files in the same directory (qmgr.rl includes common.rl).

common.rl:

%%{
machine common;
queueId = xdigit+;
anythingExceptComma = [^,]+;
bracketedEmailLocalPart = [^'@']+;
bracketedEmailDomainPart = [^'>']+;
action setTokBeg { tokBeg = p }
}%%

qmgr.rl:

// +build !codeanalysis

package rawparser

%% machine qmgrReturnedToSender;
%% write data;

func parseQmgrReturnedToSender(data []byte) (QmgrReturnedToSender, bool) {
        cs, p, pe, eof := 0, 0, len(data), len(data)
        tokBeg := 0

        _ = eof

        r := QmgrReturnedToSender{}

%%{
        include common "common.rl";

        qMgrQueueId = queueId >setTokBeg %{
                r.Queue = data[tokBeg:p]
        };

        senderLocalPart = bracketedEmailLocalPart >setTokBeg %{
                r.SenderLocalPart = normalizeMailLocalPart(data[tokBeg:p])
        };

        senderDomainPart = bracketedEmailDomainPart >setTokBeg %{
                r.SenderDomainPart = data[tokBeg:p]
        };

        main := qMgrQueueId ': from=<' senderLocalPart '@' senderDomainPart '>, status=expired, returned to sender'  @{
                return r, true
        };

        write init;
        write exec;
}%%

        return r, false
}

This is the error I get:

> ragel-go qmgr.rl -o qmgr.gen.go
ragel-go: input.c:517: input_undo_prepend_tree: Assertion `si->queue.head != 0 && ( si->queue.head->type == SB_TOKEN || si->queue.head->type == SB_IGNORE )' failed.
ragel: frontend stopped by signal: 6
failed to parse output: <input>:1:1: parse error%s:%ld:

On ragel 6.10 (tested on alpine and manjaro linux), no errors, all compiles fine:

> ragel -Z qmgr.rl -o qmgr.gen.go
adrian-thurston commented 3 years ago

Hi @leandrosansilva thank you for reporting this. Bug is actually in colm. I have a fix and will be releasing a new version of ragel that uses the fixed version of colm.

evanmiller commented 3 years ago

I had the same problem and can confirm that the latest Colm fixes it. (I had to modify EXPECTED_COLM_VER in my Ragel's configure.ac to get it to compile.)