Actions
Bug #2728
closedBlock::fromStream decode error when TLV-LENGTH equals whitespace
Start date:
04/04/2015
Due date:
% Done:
100%
Estimated time:
3.00 h
Description
Snippet to reproduce:
// g++ -std=c++0x x.cpp $(pkg-config --cflags --libs libndn-cxx)
#include <ndn-cxx/data.hpp>
using namespace ndn;
int
main()
{
uint8_t PACKET[] = {
0x06, 0x20, // Data
0x07, 0x11, // Name
0x08, 0x05, 0x68, 0x65, 0x6c, 0x6c, 0x6f, // NameComponent 'hello'
0x08, 0x01, 0x31, // NameComponent '1'
0x08, 0x05, 0x77, 0x6f, 0x72, 0x6c, 0x64, // NameComponent 'world'
0x14, 0x00, // MetaInfo empty
0x15, 0x00, // Content empty
0x16, 0x05, // SignatureInfo
0x1b, 0x01, 0x01, // SignatureType RSA
0x1c, 0x00, // KeyLocator empty
0x17, 0x00 // SignatureValue empty
};
std::stringstream stream;
stream.write(reinterpret_cast<const char*>(PACKET), sizeof(PACKET));
stream.seekg(0);
Block block = Block::fromStream(stream);
block.parse();
return 0;
}
Expected: no error
Actual:
terminate called after throwing an instance of 'ndn::tlv::Error'
what(): TLV length exceeds buffer length
Debug:
(gdb) bt
#0 0x00007ffff711a0d5 in __GI_raise (sig=<optimized out>) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1 0x00007ffff711d83b in __GI_abort () at abort.c:91
#2 0x00007ffff777069d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff776e846 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff776e873 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff776e96e in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6 0x0000000000406f89 in ndn::Block::parse (this=0x7fffffffe410) at ../src/encoding/block.cpp:313
#7 0x0000000000404ae8 in main ()
(gdb) up 6
#6 0x0000000000406f89 in ndn::Block::parse (this=0x7fffffffe410) at ../src/encoding/block.cpp:313
313 throw tlv::Error("TLV length exceeds buffer length");
(gdb) p type
$1 = 17
(gdb) p length
$2 = 8
(gdb) p *this
$3 = {m_buffer = {<std::__shared_ptr<ndn::Buffer const, (__gnu_cxx::_Lock_policy)2>> = {_M_ptr = 0x621240, _M_refcount = {
_M_pi = 0x621280}}, <No data fields>}, m_type = 6, m_begin = {_M_current = 0x621260 "\006\a\021\b\005hell"}, m_end = {
_M_current = 0x621269 ""}, m_size = 9, m_value_begin = {_M_current = 0x621262 "\021\b\005hell"}, m_value_end = {
_M_current = 0x621269 ""}, m_subBlocks = {<std::_Vector_base<ndn::Block, std::allocator<ndn::Block> >> = {
_M_impl = {<std::allocator<ndn::Block>> = {<__gnu_cxx::new_allocator<ndn::Block>> = {<No data fields>}, <No data fields>},
_M_start = 0x0, _M_finish = 0x0, _M_end_of_storage = 0x0}}, <No data fields>}}
(gdb) x/34x m_begin._M_current
0x621260: 0x06 0x07 0x11 0x08 0x05 0x68 0x65 0x6c
0x621268: 0x6c 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x621270: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x621278: 0x21 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x621280: 0x30 0xfc
It seems that top-level element's TLV-LENGTH octet (0x20) is lost.
Actions