named-data-iot/ndn-lite

Cannot decode Data without MetaInfo

Closed this issue · 1 comments

As of 4ee2112, ndn_data_tlv_decode_no_verify invokes:

// meta info
ndn_metainfo_tlv_decode(&decoder, &data->metainfo);

// content
decoder_get_type(&decoder, &probe);
decoder_get_length(&decoder, &probe);

Within ndn_metainfo_tlv_decode:

uint32_t probe = 0;
decoder_get_type(decoder, &probe);

if (probe != TLV_MetaInfo) {
  if (probe == TLV_Content || probe == TLV_SignatureInfo) {
    ndn_metainfo_init(meta);
    return 0;
  }
  else
    return NDN_WRONG_TLV_TYPE;
}

As soon as decoder_get_type is invoked, it consumes the TLV-TYPE from input. When ndn_metainfo_tlv_decode determines the TLV-TYPE belongs to the next element in Data, it did not unshift the input back to the decoder. Therefore, the next decoder_get_type in ndn_data_tlv_decode_no_verify is reading subsequent input that is not a TLV-TYPE.

Commit 752c6b5 will address this problem. Thank you for pointing this out.