Hi, all
I am reading ns3 code. But I am confused by these three functions: Buffer::Iterator::ReadNtohU16(), Buffer::Iterator::ReadNtohU32(), and Buffer::Iterator::ReadNtohU64()
Here's problem. To make it short and obvious, just consider these two cases.
1). When m_current > m_zeroEnd
ReadNtohU16() and ReadNtohU32() will read from m_data[m_current]. But ReadNtohU64() will invoke eight ReadU8() which in turn will invoke PeekU8(). But PeekU8() will read from m_data[m_current - (m_zeroEnd - m_zeroStart)]. Because the zero area bytes are usually used to represent the application payload, and the state invariant of m_start <= m_zeroStart <= m_zeroEnd <= m_end, they should be reading from different location.
2) When m_zeroStart < m_current < m_zeroEnd
ReadNtohU16() and ReadNtohU32() will increase m_current too much. Take ReadNtohU16() as a example. It invokes SlowReadNtohU16() and then increase m_current by 2. But SlowReadNtohU16() invokes ReadU8() twice, which in turn invokes PeekU8() and increases m_current by 1. Eventually, ReadNtohU16() will increase m_current by 4 instead of 2.
I searched this problem on google and in the bugzilla database, but failed to find related information.
This looks like a bug, but it doesn't hurt too much. Because there is few manipulation on application payload or footer during the packet processing.
Or perhaps there's something I just omitted? Any comment will be appreciated.