-
Notifications
You must be signed in to change notification settings - Fork 405
Do not execute the default_value expr until we need it in TLV deser #1588
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
Do not execute the default_value expr until we need it in TLV deser #1588
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1588 +/- ##
==========================================
- Coverage 91.07% 91.02% -0.05%
==========================================
Files 80 80
Lines 44128 44125 -3
Branches 44128 44125 -3
==========================================
- Hits 40190 40166 -24
- Misses 3938 3959 +21
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be squashed now.
This fixes an insta-panic in `ChannelMonitor` deserialization where we always `unwrap` a previous value to determine the default value of a later field. However, because we always ran the `unwrap` before the previous field is read, we'd always panic. The fix is rather simple - use a `OptionDeserWrapper` for `default_value` fields and only fill in the default value if no value was read while walking the TLV stream. The only complexity comes from our desire to support `read_tlv_field` calls that use an explicit field rather than an `Option` of some sort, which requires some statement which can assign both an `OptionDeserWrapper<T>` variable and a `T` variable. We settle on `x = t.into()` and implement `From<T> for OptionDeserWrapper<T>` which works, though it requires users to specify types explicitly due to Rust determining expression types prior to macro execution, completely guessing with no knowlege for integer expressions (see rust-lang/rust#91369).
0ee7b7f
to
f1b9bd3
Compare
Squashed. |
This fixes an insta-panic in
ChannelMonitor
deserialization wherewe always
unwrap
a previous value to determine the default valueof a later field. However, because we always ran the
unwrap
before the previous field is read, we'd always panic.
The fix is rather simple - use a
OptionDeserWrapper
fordefault_value
fields and only fill in the default value if novalue was read while walking the TLV stream.
The only complexity comes from our desire to support
read_tlv_field
calls that use an explicit field rather than anOption
of some sort, which requires some statement which canassign both an
OptionDeserWrapper<T>
variable and aT
variable.We settle on
x = t.into()
and implementFrom<T> for OptionDeserWrapper<T>
which works, though it requires users tospecify types explicitly due to Rust determining expression types
prior to macro execution, completely guessing with no knowlege for
integer expressions (see
rust-lang/rust#91369).
In lieu of an explicit and overly-restrictive test, we opt instead for a new fuzzer, which should exercise this code much better.