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 Content #25

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);
data->content_size = probe;

NDN Packet Format v0.3 specifies that Content element is optional in a Data packet. However, the above code does not properly consider this case. For example, given input:

0631
  0703080141
  1403150100
  16031B0100
  1720AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

the decoding function would incorrectly read the SignatureInfo element as Content.

tianyuan129 commented 5 years ago

Commit 4b4f5012636f5e0c58cce4ba72a96b34cbf7d027 will address this problem. Thank you for pointing this out.