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

TransmitCall and TransmitReturn #215

Merged
merged 19 commits into from
Oct 11, 2023
Merged

TransmitCall and TransmitReturn #215

merged 19 commits into from
Oct 11, 2023

Conversation

ibeckermayer
Copy link
Contributor

@ibeckermayer ibeckermayer commented Oct 11, 2023

Corresponds with gravitational/teleport#33282

@ibeckermayer ibeckermayer requested a review from CBenoit October 11, 2023 04:06
@github-actions
Copy link

github-actions bot commented Oct 11, 2023

Coverage Report 🤖 ⚙️

Past:
Total lines: 24246
Covered lines: 15656 (64.57%)

New:
Total lines: 24359
Covered lines: 15651 (64.25%)

Diff: -0.32%

[this comment will be updated automatically]

Comment on lines 946 to 949
let preferred_protocols = CardProtocol::from_bits_truncate(src.read_u32());
let preferred_protocols = CardProtocol::from_bits(src.read_u32())
.ok_or_else(|| invalid_message_err!("decode_ptr", "ConnectCommon", "invalid CardProtocol"))?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: why from_bits_truncate wasn’t doing the job? I wonder if from_bits_retain wouldn’t be a better alternative (keeping the original payload as-is)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was doing the job, I just noticed that from_bits was more precise so decided to switch to using that. I tried it here as well

let current_state = CardStateFlags::from_bits_truncate(src.read_u32());
let event_state = CardStateFlags::from_bits_truncate(src.read_u32());

but it turns out that we actually do sometimes get junk bits in those fields 🤷‍♂️.

Copy link
Member

@CBenoit CBenoit Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-thinking about this, I really think we should use from_bits_retain everywhere now. My understanding is that it wasn’t used up until now because this method didn’t exist yet in older versions of the bitflags crate.

As much as possible I want parsing to be lossless and to uphold the "round-trip" property (m = encode(decode(m)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand how from_bits_retain works. What if there are undefined bits?

Copy link
Member

@CBenoit CBenoit Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those bits are ignored, but not unset (unlike from_bits_truncate), i.e.: the underlying u32 is set exactly to the value received from the network

Actually, let me correct myself: we should either use from_bits or from_bits_retain, but never from_bits_truncate, and I would tend to reach for from_bits_retain over from_bits

Rationale:

  • We want the round-tripping property to hold, and for this property to hold, parsing must be non destructive (lossless), but from_bits_truncate is destructive (undefined bits are discarded)
  • We generally want lenient parsing, ignoring unknown values as long as we don’t need them and/or as long as ignoring them is causing no harm, but from_bits is not lenient

However, it’s okay to use from_bits if strictness is required at some place, but I would like such places to be documented with a comment explaining why we have to refuse unknown flags

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, yes, from_bits_retain is much better than truncation via from_bits_truncate, which may prevent a hard-to-catch bug for us in the future! We may want to make refactoring on the whole codebase, I created an issue to do refactoring in future #217

@ibeckermayer ibeckermayer requested a review from CBenoit October 11, 2023 20:07
Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

crates/ironrdp-rdpdr/src/pdu/esc.rs Outdated Show resolved Hide resolved
crates/ironrdp-rdpdr/src/pdu/esc.rs Outdated Show resolved Hide resolved
@ibeckermayer ibeckermayer requested a review from CBenoit October 11, 2023 20:56
Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@CBenoit CBenoit merged commit 3c59397 into master Oct 11, 2023
@CBenoit CBenoit deleted the feat/Transmit branch October 11, 2023 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants