Project

General

Profile

Actions

Bug #4180

closed

Block::fromStream consumes extra octet when TLV-LENGTH equals zero

Added by Junxiao Shi over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Base
Target version:
Start date:
07/10/2017
Due date:
% Done:

100%

Estimated time:
1.50 h

Description

Snippet to reproduce:

// g++ -std=c++11 -o x x.cpp $(pkg-config --cflags --libs libndn-cxx)

#include <ndn-cxx/encoding/block.hpp>
#include <sstream>
#include <iostream>

int
main()
{
  std::istringstream is(std::string("\x01\x00\x03\x02\xee\xff", 6));

  ndn::Block b1 = ndn::Block::fromStream(is);
  std::cout << b1.type() << ' ' << b1.size() << std::endl;

  ndn::Block b2 = ndn::Block::fromStream(is);
  std::cout << b2.type() << ' ' << b2.size() << std::endl;
}

The input is:

TLV-TYPE=1 TLV-LENGTH=0 TLV-VALUE={}
TLV-TYPE=3 TLV-LENGTH=2 TLV-VALUE={0xee, 0xff}

Expected:

1 2
3 4

Actual:

1 2
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<ndn::tlv::Error> >'
  what():  Not enough data in the buffer to fully parse TLV
Aborted (core dumped)

When decoding the first TLV element, one extra octet has been consumed from the input stream, causing decoding error at the second TLV element.


Related issues 1 (0 open1 closed)

Related to ndn-cxx - Bug #2729: Block::fromStream decode error when TLV-LENGTH equals zeroClosedJunxiao Shi04/04/2015

Actions
Actions

Also available in: Atom PDF