kbandla / dpkt

fast, simple packet creation / parsing, with definitions for the basic TCP/IP protocols
Other
1.09k stars 270 forks source link

Issue with SCTP DATA chunk padding #499

Closed lendern closed 3 years ago

lendern commented 3 years ago

Hello, while using dpkt, I identified an issue in SCTP DATA chunk management. An SCTP DATA chunk must be padded with 0, in order to align 4-bytes boundary. Fix may be located in class Chunk:

class Chunk(dpkt.Packet):
    __hdr__ = (
        ('type', 'B', INIT),
        ('flags', 'B', 0),
        ('len', 'H', 0)
    )

    def unpack(self, buf):
        dpkt.Packet.unpack(self, buf)
        # FIX: SCTP DATA Chunked is padded, 4-bytes aligned
        length = self.len
        if length % 4 > 0:
            length = length + 4 - (length % 4)
        self.data = self.data[:length - self.__hdr_len__]

I assume your fix would be smarter than my proposal