-
Notifications
You must be signed in to change notification settings - Fork 524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C++] Possible bug in decodeLength() #1044
Comments
Actually there seems to be a 3rd problem: precedence checks should not allow call to this function in an unwrapped state. |
/cc @ZachBray |
Good spot. Regarding Problem 1, it looks like the incorrect block length has been used since the Regarding Problem 2, I believe the generator no longer passes @szymonwieloch, if you are happy to raise a PR with a fix, please go ahead. Otherwise, I'll pick this up when I get some time. |
@szymonwieloch, in case you'd like to raise a PR and get a fix soon, we're planning to release a minor version of SBE within the next week. If you do raise a PR, please add a test mimicking your reproduction steps. |
Fixed in #1045. |
I believe that you code generator has a bug in the
decodeLength()
method of messages. Inside this method a new temporal instance of the message class is created in order to iterate over elements and provide length of the message (actually part of it that is understood by the parser). It goes like this:As you can see, I am currently using precedence checks and it's possible that the bug is limited to this version.
The purpose of creating this temporal instance is to have a "fresh" instance that you can use to skip over variable length fields.
The problem is with two parts of this code:
sbeBlockLength()
instead of usingm_actingBlockLength
.m_codecState
Problem 1 is about passing a constant block length characteristic to the version of schema that was used by code generator. Instead the value from the received header should be used. This violates the forward compatibility paradigm as the received message may have a longer block length. To reproduce problem 1:
Problem 2 is about codec state. Whenever you completely reset the parser, you should also reset the codec state. Otherwise precedence checks will throw and exception in a completely correct scenario. To reproduce:
<data>
fields<data>
field. This will change the codec state.decodeLength()
method. Precedence checks will make it throw because the temporal instance is in an invalid state.Suggestion for fixing
Since creation of a "fresh" instance exists in few places (for example
operator <<
also creates a new temporal instance) I suggest wrapping this piece of code inside a new method to reduce duplication. You already have thesbeRewind()
method but the new one needs to return a new instance of the message class, without affecting the original instance:The text was updated successfully, but these errors were encountered: