named-data-iot / ndn-lite

A lightweight NDN protocol stack with high-level application support including security bootstrapping, access control, trust management, etc.
https://ndn-lite.named-data.net
GNU Lesser General Public License v3.0
44 stars 16 forks source link

Cannot decode Data without MetaInfo #24

Closed yoursunny closed 5 years ago

yoursunny commented 5 years ago

As of 4ee21124638949b35ba5a80ebfd4efd7c0161891, 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.

tianyuan129 commented 5 years ago

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