named-data-iot/ndn-lite

Incorrect decoding of InterestLifetime

Closed this issue · 2 comments

As of c03b560, ndn_interest_from_block invokes:

while (decoder.offset < block_size) {
  decoder_get_type(&decoder, &type);
  uint32_t length = 0;
  if (type == TLV_InterestLifetime) {
    decoder_get_length(&decoder, &length);
    decoder_get_uint16_value(&decoder, &interest->lifetime);
  }
}

It assumes InterestLifetime has TLV-LENGTH=2 without checking it.
NDN Packet Format v0.3 specifies that InterestLifetime element is NonNegativeInteger that could have 1, 2, 4, or 8 octets.
Consequently, given input:

050B
  0703080141
  0C0400012100

the decoding function would incorrectly read InterestLifetime to be 1, and erroneously interpret 2100 as CanBePrefix.

Commit a5a0b72 will address this problem. For some reasons NDN-Lite now decides to accept 4 octets InterestLifetime, rather than all four options. Can you @Zhiyi-Zhang explain a bit about that? 😃

Commit b180d15 fixed the issue.