Skip to content
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

Fix encoding alignment logic. #18

Merged
merged 2 commits into from
Apr 20, 2015
Merged

Conversation

vincenospam
Copy link
Contributor

The newEncoder method is recursive, but alignment logic must be based on
"global" absolute position. This FIX allows recursive calls to set the
initial position.

Unit tests added to verify the problem and fix.

The problem was discovered for nested containers where the start of the
nested container can be on a 4-byte-aligned (but not 8-byte-aligned) boundary.

The newEncoder method is recursive, but alignment logic must be based on
"global" absolute position. This FIX allows recursive calls to set the
initial position.

Unit tests added to very the problem and fix.

The problem was discovered for nested containers where the start of the
nested container can be on a 4-byte-aligned (but not 8-byte-aligned) boundary.
@philips
Copy link
Contributor

philips commented Apr 17, 2015

lgtm from eyeballing both this and the dbus wire format: http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling

I would absolutely love @alexlarsson to review this one.

@philips
Copy link
Contributor

philips commented Apr 17, 2015

@vincenospam How did you run upon this one?

@vincenospam
Copy link
Contributor Author

@philips We're trying to send JSON-like data, which has, essentially, nested dicts and arrays. We noticed crashes (DBus connection getting closed) that were data dependent. A pattern emerged that the crash would occur when parts of the data would change lengths by increments of 4 bytes. E.g., would be fine 0-3 bytes, would crash 4-7 bytes, ok again for 8-11 bytes, etc.

I isolated the behavior down to the encoder, where the marshalled data could not be decoded by the decoder.

@alexlarsson
Copy link
Contributor

So, apart from the missing alignment for the length this looks ok to me.
However, we should probably have better testcases here. We could just dump a bunch of dbus traffic and ensure we can roundtrip it via the decoder/encoder and get the same binary data back.

@vincenospam
Copy link
Contributor Author

Alas, the dumping dbus traffic doesn't work, because the current library implementation cannot roundtrip from decode -> encode. That is, the library can decode what it encodes, but it may not be able to re-encode something it decodes from the bus.

The issue is that, when decoding, structs are decoded into []interface{}, but encode does not deal with interface{} well (nor does Signature).

@alexlarsson
Copy link
Contributor

This looks good to me.

alexlarsson added a commit that referenced this pull request Apr 20, 2015
Fix encoding alignment logic.
@alexlarsson alexlarsson merged commit 4160802 into godbus:master Apr 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants