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

Demarshaling messages with zero-length arrays fails #14

Open
albel727 opened this issue Nov 8, 2018 · 0 comments
Open

Demarshaling messages with zero-length arrays fails #14

albel727 opened this issue Nov 8, 2018 · 0 comments

Comments

@albel727
Copy link

albel727 commented Nov 8, 2018

When a message signature contains an array, but the message body actually contains no elements, parsing incorrectly fails with DemarshalError::MismatchedParens, due to invalid handling in

let mut sig_copy = "".to_owned();
while *offset < start_offset+(array_len as usize) {
// We want to pass the same signature to each call of demarshal
sig_copy = sig.to_owned();
vec.push(try!(demarshal(buf, offset, &mut sig_copy)));
}
// Now that we're done with our elements we can forget the elements consumed by demarshal
let mut mysig = sig.clone();
mysig.truncate(sig.len() - sig_copy.len());
mysig.insert(0, 'a');
*sig = sig_copy;

Note that if the while loop doesn't execute even once, sig_copy will remain empty, and the currently parsed sig will be unconditionally emptied, instead of being set to fields remaining to be parsed.

Maybe I'll fix the bug myself later and publish a PR, but meanwhile here's an example failing test case with an array in the middle of a simple struct. Both nonempty and empty array tests are added for contrast.

albel727@460d6c1

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

No branches or pull requests

1 participant