Binpac wrong boundary check

Description

I'm trying to create a parser for a simple protocol, described by the following type:

The code generated by BinPAC, when you compile the attached .pac file is wrong.
In fact the code generated for the parsing of the message is something like:

As you can see at first buffer's length is set to 8, than it will throw an ExceptionOutOfBound because 12>8.
I've looked into the issue and i think that the problem is in the method:

bool RecordField::AttemptBoundaryCheck(Output* out_cc, Env* env)
(pac_record.cc)

In this method the boundary check for the field "msg_length" leads to the boundary check of the field "msg_type", because
quoting the comment on the method: "If my next field can check its boundary, then I don't have to check mine, and it will save me a boundary-check."

As a temporary fix i commented out the "optimization" to check the next field in the AttemptBoundaryCheck method.
How to fix this issue properly?

Environment

None

Assignee

Unassigned

Reporter

lorenzo simionato

Labels

None

External issue ID

250

Components

Affects versions

Priority

Normal
Configure