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

Do not execute the default_value expr until we need it in TLV deser #1588

Merged
merged 4 commits into from Jul 5, 2022

Commits on Jul 1, 2022

  1. Copy the full SHA
    cee1feb View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    c9a52d6 View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    d246e61 View commit details
    Browse the repository at this point in the history

Commits on Jul 5, 2022

  1. Do not execute the default_value expr until we need it in TLV deser

    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).
    TheBlueMatt committed Jul 5, 2022
    Copy the full SHA
    f1b9bd3 View commit details
    Browse the repository at this point in the history